[PATCH net-next] net: remove redundant variable in vxlan_xmit_one

2020-08-20 Thread Jianlin Lv
dst/src is used multiple times in vxlan_xmit_one function as the variable
name, although its scope is different, but it reduces the readability and
it is unnecessary to use intermediate variables here;
This patch reduces unnecessary assignments and removes redundant variables

Signed-off-by: Jianlin Lv 
---
 drivers/net/vxlan.c | 40 +++-
 1 file changed, 15 insertions(+), 25 deletions(-)

diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index b9fefe27e3e8..679260e1d9f1 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -2597,7 +2597,6 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct 
net_device *dev,
struct ip_tunnel_info *info;
struct vxlan_dev *vxlan = netdev_priv(dev);
const struct iphdr *old_iph = ip_hdr(skb);
-   union vxlan_addr *dst;
union vxlan_addr remote_ip, local_ip;
struct vxlan_metadata _md;
struct vxlan_metadata *md = &_md;
@@ -2614,8 +2613,8 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct 
net_device *dev,
info = skb_tunnel_info(skb);
 
if (rdst) {
-   dst = >remote_ip;
-   if (vxlan_addr_any(dst)) {
+   remote_ip = rdst->remote_ip;
+   if (vxlan_addr_any(_ip)) {
if (did_rsc) {
/* short-circuited back to local bridge */
vxlan_encap_bypass(skb, vxlan, vxlan,
@@ -2635,7 +2634,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct 
net_device *dev,
ttl = ip_tunnel_get_ttl(old_iph, skb);
} else {
ttl = vxlan->cfg.ttl;
-   if (!ttl && vxlan_addr_multicast(dst))
+   if (!ttl && vxlan_addr_multicast(_ip))
ttl = 1;
}
 
@@ -2643,7 +2642,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct 
net_device *dev,
if (tos == 1)
tos = ip_tunnel_get_dsfield(old_iph, skb);
 
-   if (dst->sa.sa_family == AF_INET)
+   if (remote_ip.sa.sa_family == AF_INET)
udp_sum = !(flags & VXLAN_F_UDP_ZERO_CSUM_TX);
else
udp_sum = !(flags & VXLAN_F_UDP_ZERO_CSUM6_TX);
@@ -2662,7 +2661,6 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct 
net_device *dev,
remote_ip.sin6.sin6_addr = info->key.u.ipv6.dst;
local_ip.sin6.sin6_addr = info->key.u.ipv6.src;
}
-   dst = _ip;
dst_port = info->key.tp_dst ? : vxlan->cfg.dst_port;
vni = tunnel_id_to_key32(info->key.tun_id);
ifindex = 0;
@@ -2681,7 +2679,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct 
net_device *dev,
 vxlan->cfg.port_max, true);
 
rcu_read_lock();
-   if (dst->sa.sa_family == AF_INET) {
+   if (remote_ip.sa.sa_family == AF_INET) {
struct vxlan_sock *sock4 = rcu_dereference(vxlan->vn4_sock);
struct rtable *rt;
__be16 df = 0;
@@ -2690,7 +2688,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct 
net_device *dev,
ifindex = sock4->sock->sk->sk_bound_dev_if;
 
rt = vxlan_get_route(vxlan, dev, sock4, skb, ifindex, tos,
-dst->sin.sin_addr.s_addr,
+remote_ip.sin.sin_addr.s_addr,
 _ip.sin.sin_addr.s_addr,
 dst_port, src_port,
 dst_cache, info);
@@ -2701,7 +2699,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct 
net_device *dev,
 
if (!info) {
/* Bypass encapsulation if the destination is local */
-   err = encap_bypass_if_local(skb, dev, vxlan, dst,
+   err = encap_bypass_if_local(skb, dev, vxlan, _ip,
dst_port, ifindex, vni,
>dst, rt->rt_flags);
if (err)
@@ -2728,12 +2726,8 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct 
net_device *dev,
goto tx_error;
} else if (err) {
if (info) {
-   struct in_addr src, dst;
-
-   src = remote_ip.sin.sin_addr;
-   dst = local_ip.sin.sin_addr;
-   info->key.u.ipv4.src = src.s_addr;
-   info->key.u.ipv4.dst = dst.s_addr;
+   info->key.u.ipv4.src = 
remote_ip.sin.sin_addr.s_addr;
+   info->key.u.ipv4.dst = 
local_ip.sin.sin_addr.s_addr;
 

Re: [PATCH 3/5] i2c: aspeed: Mask IRQ status to relevant bits

2020-08-20 Thread Wolfram Sang

> + irq_received &= 0xf000;

Can we have a define for this? Like ASPEED_I2CD_INTR_MASTER_IRQS or
something?



signature.asc
Description: PGP signature


Re: [PATCH v5] phy: omap-usb2-phy: disable PHY charger detect

2020-08-20 Thread Jan Kiszka
On 20.08.20 15:39, Roger Quadros wrote:
> AM654x PG1.0 has a silicon bug that D+ is pulled high after POR, which
> could cause enumeration failure with some USB hubs.  Disabling the
> USB2_PHY Charger Detect function will put D+ into the normal state.
> 
> This addresses Silicon Errata:
> i2075 - "USB2PHY: USB2PHY Charger Detect is Enabled by Default Without VBUS
> Presence"
> 
> Signed-off-by: Roger Quadros 
> ---
> Changelog:
> v5
> - don't use dt property to enable workaround. Use soc_device_match() instead.
> 
> v4
> - fix example to fix dt_binding_check warnings
> - '#phy-cells' -> "#phy-cells"
> - Add 'oneOf' to compatible logic to allow just "ti,omap-usb2" as valid
> 
> v3
> - Removed quotes from compatibles
> - changed property to "ti,disable-charger-det"
> 
> v2
> - Address Rob's comments on YAML schema.
> 
>  drivers/phy/ti/phy-omap-usb2.c | 70 +-
>  1 file changed, 51 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/phy/ti/phy-omap-usb2.c b/drivers/phy/ti/phy-omap-usb2.c
> index cb2dd3230fa7..65d73142d4ec 100644
> --- a/drivers/phy/ti/phy-omap-usb2.c
> +++ b/drivers/phy/ti/phy-omap-usb2.c
> @@ -6,26 +6,31 @@
>   * Author: Kishon Vijay Abraham I 
>   */
>  
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
> -#include 
>  #include 
> -#include 
> -#include 
>  #include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
>  #include 
> +#include 
>  #include 
> -#include 
> +#include 
> +#include 
>  #include 
> -#include 
> +#include 
> +#include 
> +#include 
>  
>  #define USB2PHY_ANA_CONFIG1  0x4c
>  #define USB2PHY_DISCON_BYP_LATCH BIT(31)
>  
> +#define USB2PHY_CHRG_DET 0x14
> +#define USB2PHY_CHRG_DET_USE_CHG_DET_REG BIT(29)
> +#define USB2PHY_CHRG_DET_DIS_CHG_DET BIT(28)
> +
>  /* SoC Specific USB2_OTG register definitions */
>  #define AM654_USB2_OTG_PDBIT(8)
>  #define AM654_USB2_VBUS_DET_EN   BIT(5)
> @@ -43,6 +48,7 @@
>  #define OMAP_USB2_HAS_START_SRP  BIT(0)
>  #define OMAP_USB2_HAS_SET_VBUS   BIT(1)
>  #define OMAP_USB2_CALIBRATE_FALSE_DISCONNECT BIT(2)
> +#define OMAP_USB2_DISABLE_CHRG_DET   BIT(3)
>  
>  struct omap_usb {
>   struct usb_phy  phy;
> @@ -236,6 +242,13 @@ static int omap_usb_init(struct phy *x)
>   omap_usb_writel(phy->phy_base, USB2PHY_ANA_CONFIG1, val);
>   }
>  
> + if (phy->flags & OMAP_USB2_DISABLE_CHRG_DET) {
> + val = omap_usb_readl(phy->phy_base, USB2PHY_CHRG_DET);
> + val |= USB2PHY_CHRG_DET_USE_CHG_DET_REG |
> +USB2PHY_CHRG_DET_DIS_CHG_DET;
> + omap_usb_writel(phy->phy_base, USB2PHY_CHRG_DET, val);
> + }
> +
>   return 0;
>  }
>  
> @@ -329,6 +342,26 @@ static const struct of_device_id omap_usb2_id_table[] = {
>  };
>  MODULE_DEVICE_TABLE(of, omap_usb2_id_table);
>  
> +static void omap_usb2_init_errata(struct omap_usb *phy)
> +{
> + static const struct soc_device_attribute am65x_sr10_soc_devices[] = {
> + { .family = "AM65X", .revision = "SR1.0" },
> + { /* sentinel */ }
> + };
> +
> + /*
> +  * Errata i2075: USB2PHY: USB2PHY Charger Detect is Enabled by
> +  * Default Without VBUS Presence.
> +  *
> +  * AM654x SR1.0 has a silicon bug due to which D+ is pulled high after
> +  * POR, which could cause enumeration failure with some USB hubs.
> +  * Disabling the USB2_PHY Charger Detect function will put D+
> +  * into the normal state.
> +  */
> + if (soc_device_match(am65x_sr10_soc_devices))
> + phy->flags |= OMAP_USB2_DISABLE_CHRG_DET;
> +}
> +
>  static int omap_usb2_probe(struct platform_device *pdev)
>  {
>   struct omap_usb *phy;
> @@ -366,14 +399,14 @@ static int omap_usb2_probe(struct platform_device *pdev)
>   phy->mask   = phy_data->mask;
>   phy->power_on   = phy_data->power_on;
>   phy->power_off  = phy_data->power_off;
> + phy->flags  = phy_data->flags;
>  
> - if (phy_data->flags & OMAP_USB2_CALIBRATE_FALSE_DISCONNECT) {
> - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> - phy->phy_base = devm_ioremap_resource(>dev, res);
> - if (IS_ERR(phy->phy_base))
> - return PTR_ERR(phy->phy_base);
> - phy->flags |= OMAP_USB2_CALIBRATE_FALSE_DISCONNECT;
> - }
> + omap_usb2_init_errata(phy);
> +
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + phy->phy_base = devm_ioremap_resource(>dev, res);
> + if (IS_ERR(phy->phy_base))
> + return PTR_ERR(phy->phy_base);
>  
>   phy->syscon_phy_power = syscon_regmap_lookup_by_phandle(node,
>   "syscon-phy-power");
> @@ -405,7 +438,6 @@ static int omap_usb2_probe(struct platform_device *pdev)
>  

Re: [PATCH v3 3/3] selinux: add permission names to trace event

2020-08-20 Thread peter enderborg
On 8/21/20 4:22 AM, Paul Moore wrote:
> On Tue, Aug 18, 2020 at 8:14 AM Stephen Smalley
>  wrote:
>> On Tue, Aug 18, 2020 at 4:11 AM peter enderborg  
>> wrote:
> ...
>
>>> Is there any other things we need to fix? A part 1&2 now OK?
>> They looked ok to me, but Paul should review them.
> Patches 1 and 2 look fine to me with the small nits that Stephen
> pointed out corrected.  I'm glad to see the information in string form
> now, I think that will be a big help for people making use of this.
>
> Unfortunately, I'm a little concerned about patch 3 for the reason
> Stephen already mentioned.  While changes to the class mapping are
> infrequent, they do happen, and I'm not very excited about adding it
> to the userspace kAPI via a header.  Considering that the tracing
> tools are going to be running on the same system that is being
> inspected, perhaps the tracing tools could inspect
> /sys/fs/selinux/class at runtime to query the permission mappings?
> Stephen, is there a libselinux API which does this already?
>
One way to use this trace is to write directly to a memory buffer over a time
period. In the case for Android and I guess in many other embedded cases too
they are moved to be some other machine to be analysed so having them
locked to where it was running also have problems.

So what is the problem we see with the plugin, that we have perms names
that are "unknown" ?



[PATCH] media: atomisp: fix memleak in ia_css_stream_create

2020-08-20 Thread Dinghao Liu
When aspect_ratio_crop_init() fails, curr_stream needs
to be freed just like what we've done in the following
error paths. However, current code is returning directly
and ends up leaking memory.

Signed-off-by: Dinghao Liu 
---
 drivers/staging/media/atomisp/pci/sh_css.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/media/atomisp/pci/sh_css.c 
b/drivers/staging/media/atomisp/pci/sh_css.c
index 54434c2dbaf9..8473e1437074 100644
--- a/drivers/staging/media/atomisp/pci/sh_css.c
+++ b/drivers/staging/media/atomisp/pci/sh_css.c
@@ -9521,7 +9521,7 @@ ia_css_stream_create(const struct ia_css_stream_config 
*stream_config,
if (err)
{
IA_CSS_LEAVE_ERR(err);
-   return err;
+   goto ERR;
}
 #endif
for (i = 0; i < num_pipes; i++)
-- 
2.17.1



Re: [PATCH v5 6/8] mm: Move vmap_range from lib/ioremap.c to mm/vmalloc.c

2020-08-20 Thread Christophe Leroy




Le 21/08/2020 à 06:44, Nicholas Piggin a écrit :

This is a generic kernel virtual memory mapper, not specific to ioremap.

Signed-off-by: Nicholas Piggin 
---
  include/linux/vmalloc.h |   2 +
  mm/ioremap.c| 192 
  mm/vmalloc.c| 191 +++
  3 files changed, 193 insertions(+), 192 deletions(-)

diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index 787d77ad7536..e3590e93bfff 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -181,6 +181,8 @@ extern struct vm_struct *remove_vm_area(const void *addr);
  extern struct vm_struct *find_vm_area(const void *addr);
  
  #ifdef CONFIG_MMU

+extern int vmap_range(unsigned long addr, unsigned long end, phys_addr_t 
phys_addr, pgprot_t prot,
+   unsigned int max_page_shift);


extern keyword is useless on function prototypes and deprecated. Please 
don't add new function prototypes with that keyword.



  extern int map_kernel_range_noflush(unsigned long start, unsigned long size,
pgprot_t prot, struct page **pages);
  int map_kernel_range(unsigned long start, unsigned long size, pgprot_t prot,


Christophe


Re: [PATCH v5 0/8] huge vmalloc mappings

2020-08-20 Thread Christophe Leroy




Le 21/08/2020 à 06:44, Nicholas Piggin a écrit :

I made this powerpc-only for the time being. It shouldn't be too hard to
add support for other archs that define HUGE_VMAP. I have booted x86
with it enabled, just may not have audited everything.


I like this series, but if I understand correctly it enables huge 
vmalloc mappings only for hugepages sizes matching a page directory 
levels, ie on a PPC32 it would work only for 4M hugepages.


On the 8xx, we only have 8M and 512k hugepages. Any change that it can 
support these as well one day ?


Christophe



Hi Andrew, would you care to put this in your tree?

Thanks,
Nick

Since v4:
- Fixed an off-by-page-order bug in v4
- Several minor cleanups.
- Added page order to /proc/vmallocinfo
- Added hugepage to alloc_large_system_hage output.
- Made an architecture config option, powerpc only for now.

Since v3:
- Fixed an off-by-one bug in a loop
- Fix !CONFIG_HAVE_ARCH_HUGE_VMAP build fail
- Hopefully this time fix the arm64 vmap stack bug, thanks Jonathan
   Cameron for debugging the cause of this (hopefully).

Since v2:
- Rebased on vmalloc cleanups, split series into simpler pieces.
- Fixed several compile errors and warnings
- Keep the page array and accounting in small page units because
   struct vm_struct is an interface (this should fix x86 vmap stack debug
   assert). [Thanks Zefan]

Nicholas Piggin (8):
   mm/vmalloc: fix vmalloc_to_page for huge vmap mappings
   mm: apply_to_pte_range warn and fail if a large pte is encountered
   mm/vmalloc: rename vmap_*_range vmap_pages_*_range
   lib/ioremap: rename ioremap_*_range to vmap_*_range
   mm: HUGE_VMAP arch support cleanup
   mm: Move vmap_range from lib/ioremap.c to mm/vmalloc.c
   mm/vmalloc: add vmap_range_noflush variant
   mm/vmalloc: Hugepage vmalloc mappings

  .../admin-guide/kernel-parameters.txt |   2 +
  arch/Kconfig  |   4 +
  arch/arm64/mm/mmu.c   |  12 +-
  arch/powerpc/Kconfig  |   1 +
  arch/powerpc/mm/book3s64/radix_pgtable.c  |  10 +-
  arch/x86/mm/ioremap.c |  12 +-
  include/linux/io.h|   9 -
  include/linux/vmalloc.h   |  13 +
  init/main.c   |   1 -
  mm/ioremap.c  | 231 +
  mm/memory.c   |  60 ++-
  mm/page_alloc.c   |   4 +-
  mm/vmalloc.c  | 456 +++---
  13 files changed, 476 insertions(+), 339 deletions(-)



Re: [PATCH v5 6/8] mm: Move vmap_range from lib/ioremap.c to mm/vmalloc.c

2020-08-20 Thread Christoph Hellwig
On Fri, Aug 21, 2020 at 02:44:25PM +1000, Nicholas Piggin wrote:
> This is a generic kernel virtual memory mapper, not specific to ioremap.

lib/ioremap doesn't exist any more.

> 
> Signed-off-by: Nicholas Piggin 
> ---
>  include/linux/vmalloc.h |   2 +
>  mm/ioremap.c| 192 
>  mm/vmalloc.c| 191 +++
>  3 files changed, 193 insertions(+), 192 deletions(-)
> 
> diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
> index 787d77ad7536..e3590e93bfff 100644
> --- a/include/linux/vmalloc.h
> +++ b/include/linux/vmalloc.h
> @@ -181,6 +181,8 @@ extern struct vm_struct *remove_vm_area(const void *addr);
>  extern struct vm_struct *find_vm_area(const void *addr);
>  
>  #ifdef CONFIG_MMU
> +extern int vmap_range(unsigned long addr, unsigned long end, phys_addr_t 
> phys_addr, pgprot_t prot,
> + unsigned int max_page_shift);

Please avoid the pointlessly long line.  And don't add the pointless
extern.


Re: [PATCH v5 5/8] mm: HUGE_VMAP arch support cleanup

2020-08-20 Thread Christoph Hellwig
>  static int vmap_try_huge_pmd(pmd_t *pmd, unsigned long addr, unsigned long 
> end,
> - phys_addr_t phys_addr, pgprot_t prot)
> + phys_addr_t phys_addr, pgprot_t prot, unsigned int 
> max_page_shift)
>  {

... and here.


Re: [PATCH v5 3/8] mm/vmalloc: rename vmap_*_range vmap_pages_*_range

2020-08-20 Thread Christoph Hellwig
On Fri, Aug 21, 2020 at 02:44:22PM +1000, Nicholas Piggin wrote:
> The vmalloc mapper operates on a struct page * array rather than a
> linear physical address, re-name it to make this distinction clear.
> 
> Signed-off-by: Nicholas Piggin 
> ---
>  mm/vmalloc.c | 28 
>  1 file changed, 12 insertions(+), 16 deletions(-)
> 
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 49f225b0f855..3a1e45fd1626 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -190,9 +190,8 @@ void unmap_kernel_range_noflush(unsigned long start, 
> unsigned long size)
>   arch_sync_kernel_mappings(start, end);
>  }
>  
> -static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
> - unsigned long end, pgprot_t prot, struct page **pages, int *nr,
> - pgtbl_mod_mask *mask)
> +static int vmap_pages_pte_range(pmd_t *pmd, unsigned long addr, unsigned 
> long end,
> + pgprot_t prot, struct page **pages, int *nr, pgtbl_mod_mask 
> *mask)

Please don't add > 80 lines without any good reason.



Re: [PATCH v5 4/8] lib/ioremap: rename ioremap_*_range to vmap_*_range

2020-08-20 Thread Christoph Hellwig
On Fri, Aug 21, 2020 at 02:44:23PM +1000, Nicholas Piggin wrote:
> This will be moved to mm/ and used as a generic kernel virtual mapping
> function, so re-name it in preparation.
> 
> Signed-off-by: Nicholas Piggin 
> ---
>  mm/ioremap.c | 55 ++--
>  1 file changed, 23 insertions(+), 32 deletions(-)
> 
> diff --git a/mm/ioremap.c b/mm/ioremap.c
> index 5fa1ab41d152..6016ae3227ad 100644
> --- a/mm/ioremap.c
> +++ b/mm/ioremap.c
> @@ -61,9 +61,8 @@ static inline int ioremap_pud_enabled(void) { return 0; }
>  static inline int ioremap_pmd_enabled(void) { return 0; }
>  #endif   /* CONFIG_HAVE_ARCH_HUGE_VMAP */
>  
> -static int ioremap_pte_range(pmd_t *pmd, unsigned long addr,
> - unsigned long end, phys_addr_t phys_addr, pgprot_t prot,
> - pgtbl_mod_mask *mask)
> +static int vmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
> + phys_addr_t phys_addr, pgprot_t prot, pgtbl_mod_mask 
> *mask)

Same here.


Re: [PATCH v5 5/8] mm: HUGE_VMAP arch support cleanup

2020-08-20 Thread Christophe Leroy




Le 21/08/2020 à 06:44, Nicholas Piggin a écrit :

This changes the awkward approach where architectures provide init
functions to determine which levels they can provide large mappings for,
to one where the arch is queried for each call.

This removes code and indirection, and allows constant-folding of dead
code for unsupported levels.


I think that in order to allow constant-folding of dead code for 
unsupported levels, you must define arch_vmap_xxx_supported() as static 
inline in a .h


If you have them in .c files, you'll get calls to tiny functions that 
will always return false, but will still be called and dead code won't 
be eliminated. And performance wise, that's probably not optimal either.


Christophe




This also adds a prot argument to the arch query. This is unused
currently but could help with some architectures (e.g., some powerpc
processors can't map uncacheable memory with large pages).

Signed-off-by: Nicholas Piggin 
---
  arch/arm64/mm/mmu.c  | 12 +--
  arch/powerpc/mm/book3s64/radix_pgtable.c | 10 ++-
  arch/x86/mm/ioremap.c| 12 +--
  include/linux/io.h   |  9 ---
  include/linux/vmalloc.h  | 10 +++
  init/main.c  |  1 -
  mm/ioremap.c | 96 +++-
  7 files changed, 73 insertions(+), 77 deletions(-)

diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index 75df62fea1b6..bbb3ccf6a7ce 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -1304,12 +1304,13 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int 
*size, pgprot_t prot)
return dt_virt;
  }
  
-int __init arch_ioremap_p4d_supported(void)

+#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
+bool arch_vmap_p4d_supported(pgprot_t prot)
  {
-   return 0;
+   return false;
  }
  
-int __init arch_ioremap_pud_supported(void)

+bool arch_vmap_pud_supported(pgprot_t prot)
  {
/*
 * Only 4k granule supports level 1 block mappings.
@@ -1319,11 +1320,12 @@ int __init arch_ioremap_pud_supported(void)
   !IS_ENABLED(CONFIG_PTDUMP_DEBUGFS);
  }
  
-int __init arch_ioremap_pmd_supported(void)

+bool arch_vmap_pmd_supported(pgprot_t prot)
  {
-   /* See arch_ioremap_pud_supported() */
+   /* See arch_vmap_pud_supported() */
return !IS_ENABLED(CONFIG_PTDUMP_DEBUGFS);
  }
+#endif
  
  int pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot)

  {
diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c 
b/arch/powerpc/mm/book3s64/radix_pgtable.c
index ae823bba29f2..7d3a620c5adf 100644
--- a/arch/powerpc/mm/book3s64/radix_pgtable.c
+++ b/arch/powerpc/mm/book3s64/radix_pgtable.c
@@ -1182,13 +1182,14 @@ void radix__ptep_modify_prot_commit(struct 
vm_area_struct *vma,
set_pte_at(mm, addr, ptep, pte);
  }
  
-int __init arch_ioremap_pud_supported(void)

+#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
+bool arch_vmap_pud_supported(pgprot_t prot)
  {
/* HPT does not cope with large pages in the vmalloc area */
return radix_enabled();
  }
  
-int __init arch_ioremap_pmd_supported(void)

+bool arch_vmap_pmd_supported(pgprot_t prot)
  {
return radix_enabled();
  }
@@ -1197,6 +1198,7 @@ int p4d_free_pud_page(p4d_t *p4d, unsigned long addr)
  {
return 0;
  }
+#endif
  
  int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)

  {
@@ -1282,7 +1284,7 @@ int pmd_free_pte_page(pmd_t *pmd, unsigned long addr)
return 1;
  }
  
-int __init arch_ioremap_p4d_supported(void)

+bool arch_vmap_p4d_supported(pgprot_t prot)
  {
-   return 0;
+   return false;
  }
diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index 84d85dbd1dad..5b8b495ab4ed 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -481,24 +481,26 @@ void iounmap(volatile void __iomem *addr)
  }
  EXPORT_SYMBOL(iounmap);
  
-int __init arch_ioremap_p4d_supported(void)

+#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
+bool arch_vmap_p4d_supported(pgprot_t prot)
  {
-   return 0;
+   return false;
  }
  
-int __init arch_ioremap_pud_supported(void)

+bool arch_vmap_pud_supported(pgprot_t prot)
  {
  #ifdef CONFIG_X86_64
return boot_cpu_has(X86_FEATURE_GBPAGES);
  #else
-   return 0;
+   return false;
  #endif
  }
  
-int __init arch_ioremap_pmd_supported(void)

+bool arch_vmap_pmd_supported(pgprot_t prot)
  {
return boot_cpu_has(X86_FEATURE_PSE);
  }
+#endif
  
  /*

   * Convert a physical pointer to a virtual kernel pointer for /dev/mem
diff --git a/include/linux/io.h b/include/linux/io.h
index 8394c56babc2..f1effd4d7a3c 100644
--- a/include/linux/io.h
+++ b/include/linux/io.h
@@ -31,15 +31,6 @@ static inline int ioremap_page_range(unsigned long addr, 
unsigned long end,
  }
  #endif
  
-#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP

-void __init ioremap_huge_init(void);
-int arch_ioremap_p4d_supported(void);
-int arch_ioremap_pud_supported(void);
-int arch_ioremap_pmd_supported(void);
-#else
-static inline 

Re: [PATCH v3] mm: Fix kthread_use_mm() vs TLB invalidate

2020-08-20 Thread Aneesh Kumar K.V
Peter Zijlstra  writes:

> For SMP systems using IPI based TLB invalidation, looking at
> current->active_mm is entirely reasonable. This then presents the
> following race condition:
>
>
>   CPU0CPU1
>
>   flush_tlb_mm(mm)use_mm(mm)
> 
> tsk->active_mm = mm;
> 
>   if (tsk->active_mm == mm)
> // flush TLBs
> 
> switch_mm(old_mm,mm,tsk);
>
>
> Where it is possible the IPI flushed the TLBs for @old_mm, not @mm,
> because the IPI lands before we actually switched.
>
> Avoid this by disabling IRQs across changing ->active_mm and
> switch_mm().
>
> [ There are all sorts of reasons this might be harmless for various
> architecture specific reasons, but best not leave the door open at
> all. ]


Do we have similar race with exec_mmap()? I am looking at exec_mmap()
runnning parallel to do_exit_flush_lazy_tlb(). We can get

if (current->active_mm == mm) {

true and if we don't disable irq around updating tsk->mm/active_mm we
can end up doing mmdrop on wrong mm?

>
> Cc: sta...@kernel.org
> Reported-by: Andy Lutomirski 
> Signed-off-by: Peter Zijlstra (Intel) 
> ---
>
> Sorry, I dropped the ball on this and only found it because I was
> looking at the whole membarrier things vs use_mm().
>
>
>  kernel/kthread.c | 6 +-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/kthread.c b/kernel/kthread.c
> index 1d9e2fdfd67a..7221dcbffef3 100644
> --- a/kernel/kthread.c
> +++ b/kernel/kthread.c
> @@ -1241,13 +1241,15 @@ void kthread_use_mm(struct mm_struct *mm)
>   WARN_ON_ONCE(tsk->mm);
>  
>   task_lock(tsk);
> + local_irq_disable();
>   active_mm = tsk->active_mm;
>   if (active_mm != mm) {
>   mmgrab(mm);
>   tsk->active_mm = mm;
>   }
>   tsk->mm = mm;
> - switch_mm(active_mm, mm, tsk);
> + switch_mm_irqs_off(active_mm, mm, tsk);
> + local_irq_enable();
>   task_unlock(tsk);
>  #ifdef finish_arch_post_lock_switch
>   finish_arch_post_lock_switch();
> @@ -1276,9 +1278,11 @@ void kthread_unuse_mm(struct mm_struct *mm)
>  
>   task_lock(tsk);
>   sync_mm_rss(mm);
> + local_irq_disable();
>   tsk->mm = NULL;
>   /* active_mm is still 'mm' */
>   enter_lazy_tlb(mm, tsk);
> + local_irq_enable();
>   task_unlock(tsk);
>  }
>  EXPORT_SYMBOL_GPL(kthread_unuse_mm);


Re: [PATCH] memory: brcmstb_dpfe: fix array index out of bounds

2020-08-20 Thread Krzysztof Kozlowski
On Thu, Aug 20, 2020 at 06:03:33PM -0700, Markus Mayer wrote:
> We would overrun the error_text array if we hit a TIMEOUT condition,
> because we were using the error code "ETIMEDOUT" (which is 110) as an
> array index.
> 
> We fix the problem by correcting the array index and by providing a
> function to retrieve error messages rather than accessing the array
> directly. The function includes a bounds check that prevents the array
> from being overrun.
> 
> Signed-off-by: Markus Mayer 
> ---
> 
> This patch was prepared in response to https://lkml.org/lkml/2020/8/18/505.
> 
>  drivers/memory/brcmstb_dpfe.c | 23 ---
>  1 file changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/memory/brcmstb_dpfe.c b/drivers/memory/brcmstb_dpfe.c
> index 81abc4a98a27..a986a849f58e 100644
> --- a/drivers/memory/brcmstb_dpfe.c
> +++ b/drivers/memory/brcmstb_dpfe.c
> @@ -190,11 +190,6 @@ struct brcmstb_dpfe_priv {
>   struct mutex lock;
>  };
>  
> -static const char * const error_text[] = {
> - "Success", "Header code incorrect", "Unknown command or argument",
> - "Incorrect checksum", "Malformed command", "Timed out",
> -};
> -
>  /*
>   * Forward declaration of our sysfs attribute functions, so we can declare 
> the
>   * attribute data structures early.
> @@ -307,6 +302,20 @@ static const struct dpfe_api dpfe_api_v3 = {
>   },
>  };
>  
> +static const char * const get_error_text(unsigned int i)

The pointer itself is returned by value and you cannot return a const
value. I mean, you can but it does not have an effect. Only pointed
memory should be const (const const char*).

Best regards,
Krzysztof


> +{
> + static const char * const error_text[] = {
> + "Success", "Header code incorrect",
> + "Unknown command or argument", "Incorrect checksum",
> + "Malformed command", "Timed out", "Unknown error",
> + };
> +
> + if (unlikely(i >= ARRAY_SIZE(error_text)))
> + i = ARRAY_SIZE(error_text) - 1;
> +
> + return error_text[i];
> +}
> +
>  static bool is_dcpu_enabled(struct brcmstb_dpfe_priv *priv)
>  {
>   u32 val;
> @@ -446,7 +455,7 @@ static int __send_command(struct brcmstb_dpfe_priv *priv, 
> unsigned int cmd,
>   }
>   if (resp != 0) {
>   mutex_unlock(>lock);
> - return -ETIMEDOUT;
> + return -ffs(DCPU_RET_ERR_TIMEDOUT);
>   }
>  
>   /* Compute checksum over the message */
> @@ -695,7 +704,7 @@ static ssize_t generic_show(unsigned int command, u32 
> response[],
>  
>   ret = __send_command(priv, command, response);
>   if (ret < 0)
> - return sprintf(buf, "ERROR: %s\n", error_text[-ret]);
> + return sprintf(buf, "ERROR: %s\n", get_error_text(-ret));
>  
>   return 0;
>  }
> -- 
> 2.17.1
> 


[PATCH v1 1/1] pinctrl: mediatek: remove log message in mtk_hw_pin_field_lookup

2020-08-20 Thread light.hsieh
From: Light Hsieh 

Originally, mtk_hw_pin_field_lookup() print log message in 2
conditions:
1. when soc does not support target property
2. when target pin does not support target property

Now, mtk_hw_pin_field_lookup() does not print log message according
to the following rationale:
1. Users of pinctrl have the duty to pass correct parameters and
   check return vale. After checking return value, the users can
   determine if log message shall be printed according to users'
   scenario.
2. Prevent message flooding when a bad user continously pass bad
   parameters to pinctrl.

Signed-off-by: Light Hsieh 
---
 drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c | 12 +++-
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c 
b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
index 2f3dfb5..161d4eb 100644
--- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
+++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
@@ -74,13 +74,10 @@ static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw,
bool found = false;
u32 bits;
 
-   if (hw->soc->reg_cal && hw->soc->reg_cal[field].range) {
+   if (hw->soc->reg_cal && hw->soc->reg_cal[field].range)
rc = >soc->reg_cal[field];
-   } else {
-   dev_dbg(hw->dev,
-   "Not support field %d for this soc\n", field);
+   else
return -ENOTSUPP;
-   }
 
end = rc->nranges - 1;
 
@@ -98,11 +95,8 @@ static int mtk_hw_pin_field_lookup(struct mtk_pinctrl *hw,
start = check + 1;
}
 
-   if (!found) {
-   dev_dbg(hw->dev, "Not support field %d for pin = %d (%s)\n",
-   field, desc->number, desc->name);
+   if (!found)
return -ENOTSUPP;
-   }
 
c = rc->range + check;
 
-- 
1.8.1.1.dirty


[tip:auto-latest] BUILD SUCCESS a9bd3a91d6e49ebd2d7d8ace91d4cc339c382a31

2020-08-20 Thread kernel test robot
tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git  
auto-latest
branch HEAD: a9bd3a91d6e49ebd2d7d8ace91d4cc339c382a31  Merge branch 'perf/core'

elapsed time: 724m

configs tested: 78
configs skipped: 3

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

arm defconfig
arm64allyesconfig
arm64   defconfig
arm  allyesconfig
arm  allmodconfig
mips   ip28_defconfig
x86_64   allyesconfig
armmmp2_defconfig
h8300h8300h-sim_defconfig
riscv   defconfig
m68k   m5275evb_defconfig
armkeystone_defconfig
s390 alldefconfig
ia64 allmodconfig
ia64defconfig
ia64 allyesconfig
m68kdefconfig
m68k allmodconfig
m68k allyesconfig
nios2   defconfig
arc  allyesconfig
nds32 allnoconfig
c6x  allyesconfig
nds32   defconfig
nios2allyesconfig
cskydefconfig
alpha   defconfig
alphaallyesconfig
xtensa   allyesconfig
h8300allyesconfig
arc defconfig
sh   allmodconfig
parisc  defconfig
s390 allyesconfig
parisc   allyesconfig
s390defconfig
i386 allyesconfig
sparcallyesconfig
sparc   defconfig
i386defconfig
mips allyesconfig
mips allmodconfig
powerpc  allyesconfig
powerpc  allmodconfig
powerpc   allnoconfig
powerpc defconfig
i386 randconfig-a002-20200820
i386 randconfig-a004-20200820
i386 randconfig-a005-20200820
i386 randconfig-a003-20200820
i386 randconfig-a006-20200820
i386 randconfig-a001-20200820
x86_64   randconfig-a015-20200820
x86_64   randconfig-a012-20200820
x86_64   randconfig-a016-20200820
x86_64   randconfig-a014-20200820
x86_64   randconfig-a011-20200820
x86_64   randconfig-a013-20200820
i386 randconfig-a013-20200820
i386 randconfig-a012-20200820
i386 randconfig-a011-20200820
i386 randconfig-a016-20200820
i386 randconfig-a014-20200820
i386 randconfig-a015-20200820
i386 randconfig-a013-20200821
i386 randconfig-a012-20200821
i386 randconfig-a011-20200821
i386 randconfig-a016-20200821
i386 randconfig-a014-20200821
i386 randconfig-a015-20200821
riscvallyesconfig
riscv allnoconfig
riscvallmodconfig
x86_64   rhel
x86_64rhel-7.6-kselftests
x86_64  defconfig
x86_64   rhel-8.3
x86_64  kexec

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


Re: [PATCH v3] usb-serial:cp210x: add support to software flow control

2020-08-20 Thread Jan Kiszka
On 20.08.20 09:52, Sheng Long Wang wrote:
> From: Wang Sheng Long 
> 
> When data is transmitted between two serial ports,
> the phenomenon of data loss often occurs. The two kinds
> of flow control commonly used in serial communication
> are hardware flow control and software flow control.
> 
> In serial communication, If you only use RX/TX/GND Pins, you
> can't do hardware flow. So we often used software flow control
> and prevent data loss. The user sets the software flow control
> through the application program, and the application program
> sets the software flow control mode for the serial port
> chip through the driver.
> 
> For the cp210 serial port chip, its driver lacks the
> software flow control setting code, so the user cannot set
> the software flow control function through the application
> program. This adds the missing software flow control.
> 
> Signed-off-by: Wang Sheng Long 
> 
> Changes in v3:
> -fixed code style, It mainly adjusts the code style acccording
>  to kernel specification.

Patch does not apply. You forgot to rebase over latest tty/tty-next or
linux master.

Jan

> ---
>  drivers/usb/serial/cp210x.c | 118 ++--
>  1 file changed, 113 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
> index e732949f65..c66a0e0fb9 100644
> --- a/drivers/usb/serial/cp210x.c
> +++ b/drivers/usb/serial/cp210x.c
> @@ -380,6 +380,9 @@ static struct usb_serial_driver * const serial_drivers[] 
> = {
>  #define CP210X_PARTNUM_CP2102N_QFN20 0x22
>  #define CP210X_PARTNUM_UNKNOWN   0xFF
>  
> +#define CP210X_VSTART0x11
> +#define CP210X_VSTOP 0x13
> +
>  /* CP210X_GET_COMM_STATUS returns these 0x13 bytes */
>  struct cp210x_comm_status {
>   __le32   ulErrors;
> @@ -391,6 +394,15 @@ struct cp210x_comm_status {
>   u8   bReserved;
>  } __packed;
>  
> +struct cp210x_chars_response {
> + u8  eofchar;
> + u8  errochar;
> + u8  breakchar;
> + u8  eventchar;
> + u8  xonchar;
> + u8  xoffchar;
> +} __packed;
> +
>  /*
>   * CP210X_PURGE - 16 bits passed in wValue of USB request.
>   * SiLabs app note AN571 gives a strange description of the 4 bits:
> @@ -624,6 +636,45 @@ static int cp210x_read_vendor_block(struct usb_serial 
> *serial, u8 type, u16 val,
>   return result;
>  }
>  
> +/*
> + * Read and Write Character Responses operate
> + * Register SET_CHARS/GET_CHATS
> + */
> +static int cp210x_operate_chars_block(struct usb_serial_port *port,
> + u8 req, u8 type, void *buf, int bufsize)
> +{
> + struct usb_serial *serial = port->serial;
> + struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
> + void *dmabuf;
> + int result;
> +
> + dmabuf = kmemdup(buf, bufsize, GFP_KERNEL);
> + if (!dmabuf)
> + return -ENOMEM;
> +
> + result = usb_control_msg(serial->dev,
> + usb_rcvctrlpipe(serial->dev, 0),
> + req, type, 0, port_priv->bInterfaceNumber,
> + dmabuf, bufsize, USB_CTRL_SET_TIMEOUT);
> +
> + if (result == bufsize) {
> + if (type == REQTYPE_DEVICE_TO_HOST)
> + memcpy(buf, dmabuf, bufsize);
> +
> + result = 0;
> + } else {
> + dev_err(>dev, "failed get req 0x%x size %d status: %d\n",
> + req, bufsize, result);
> + if (result >= 0)
> + result = -EIO;
> +
> + }
> +
> + kfree(dmabuf);
> +
> + return result;
> +}
> +
>  /*
>   * Writes any 16-bit CP210X_ register (req) whose value is passed
>   * entirely in the wValue field of the USB request.
> @@ -1134,11 +1185,17 @@ static void cp210x_set_termios(struct tty_struct *tty,
>   struct usb_serial_port *port, struct ktermios *old_termios)
>  {
>   struct device *dev = >dev;
> - unsigned int cflag, old_cflag;
> + struct cp210x_chars_response charsres;
> + struct cp210x_flow_ctl flow_ctl;
> + unsigned int cflag, old_cflag, iflag;
>   u16 bits;
> + int result;
> + u32 ctl_hs;
> + u32 flow_repl;
>  
>   cflag = tty->termios.c_cflag;
>   old_cflag = old_termios->c_cflag;
> + iflag = tty->termios.c_iflag;
>  
>   if (tty->termios.c_ospeed != old_termios->c_ospeed)
>   cp210x_change_speed(tty, port, old_termios);
> @@ -1212,10 +1269,6 @@ static void cp210x_set_termios(struct tty_struct *tty,
>   }
>  
>   if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
> - struct cp210x_flow_ctl flow_ctl;
> - u32 ctl_hs;
> - u32 flow_repl;
> -
>   cp210x_read_reg_block(port, CP210X_GET_FLOW, _ctl,
>   sizeof(flow_ctl));
>   ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake);
> @@ -1252,6 +1305,61 @@ static void cp210x_set_termios(struct tty_struct *tty,
>   

[PATCH bpf-next] docs: correct subject prefix and update LLVM info

2020-08-20 Thread Jianlin Lv
bpf_devel_QA.rst:152 The subject prefix information is not accurate, it
should be 'PATCH bpf-next v2'

Also update LLVM version info and add information about
‘-DLLVM_TARGETS_TO_BUILD’ to prompt the developer to build the desired
target.

Signed-off-by: Jianlin Lv 
---
 Documentation/bpf/bpf_devel_QA.rst | 19 ---
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/Documentation/bpf/bpf_devel_QA.rst 
b/Documentation/bpf/bpf_devel_QA.rst
index a26aa1b9b259..75a0dca5f295 100644
--- a/Documentation/bpf/bpf_devel_QA.rst
+++ b/Documentation/bpf/bpf_devel_QA.rst
@@ -149,7 +149,7 @@ In case the patch or patch series has to be reworked and 
sent out
 again in a second or later revision, it is also required to add a
 version number (``v2``, ``v3``, ...) into the subject prefix::
 
-  git format-patch --subject-prefix='PATCH net-next v2' start..finish
+  git format-patch --subject-prefix='PATCH bpf-next v2' start..finish
 
 When changes have been requested to the patch series, always send the
 whole patch series again with the feedback incorporated (never send
@@ -479,17 +479,18 @@ LLVM's static compiler lists the supported targets through
 
  $ llc --version
  LLVM (http://llvm.org/):
-   LLVM version 6.0.0svn
+   LLVM version 10.0.0
Optimized build.
Default target: x86_64-unknown-linux-gnu
Host CPU: skylake
 
Registered Targets:
- bpf- BPF (host endian)
- bpfeb  - BPF (big endian)
- bpfel  - BPF (little endian)
- x86- 32-bit X86: Pentium-Pro and above
- x86-64 - 64-bit X86: EM64T and AMD64
+ aarch64- AArch64 (little endian)
+ bpf- BPF (host endian)
+ bpfeb  - BPF (big endian)
+ bpfel  - BPF (little endian)
+ x86- 32-bit X86: Pentium-Pro and above
+ x86-64 - 64-bit X86: EM64T and AMD64
 
 For developers in order to utilize the latest features added to LLVM's
 BPF back end, it is advisable to run the latest LLVM releases. Support
@@ -517,6 +518,10 @@ from the git repositories::
 The built binaries can then be found in the build/bin/ directory, where
 you can point the PATH variable to.
 
+Set ``-DLLVM_TARGETS_TO_BUILD`` equal to the target you wish to build, you
+will find a full list of targets within the llvm-project/llvm/lib/Target
+directory.
+
 Q: Reporting LLVM BPF issues
 
 Q: Should I notify BPF kernel maintainers about issues in LLVM's BPF code
-- 
2.17.1



[PATCH v2 2/2] exfat: write only modified part of dir-entry set

2020-08-20 Thread Tetsuhiro Kohada
Currently exfat_free_dentry_set() writes all of dir-entry set.
Change it to write only the modified part of dir-entry set.
And, Integrate exfat_free_dentry_set() and
exfat_update_dir_chksum_with_entry_set() as exfat_put_dentry_set().

** This patch depends on:
  '[PATCH v3] exfat: integrates dir-entry getting and validation'
  '[PATCH v2] exfat: add NameLength check when extracting name'
  '[PATCH v2] exfat: unify name extraction'

Signed-off-by: Tetsuhiro Kohada 
---
Changes in v2
 - Based on v2 'name-length' patches

 fs/exfat/dir.c  | 31 +++
 fs/exfat/exfat_fs.h |  4 +---
 fs/exfat/file.c |  3 +--
 fs/exfat/inode.c|  6 ++
 fs/exfat/namei.c|  4 ++--
 5 files changed, 21 insertions(+), 27 deletions(-)

diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c
index 6f9de364a919..ad6fef854c30 100644
--- a/fs/exfat/dir.c
+++ b/fs/exfat/dir.c
@@ -129,7 +129,7 @@ static int exfat_readdir(struct inode *inode, struct 
exfat_dir_entry *dir_entry)
dir_entry->size = 
le64_to_cpu(es->de_stream->valid_size);
 
err = exfat_get_uniname_from_name_entries(es, 
_name);
-   exfat_free_dentry_set(es, false);
+   exfat_put_dentry_set(es, 0, false);
if (err)
return err;
 
@@ -581,21 +581,21 @@ static int exfat_calc_entry_set_chksum(struct 
exfat_entry_set_cache *es, u16 *ch
return 0;
 }
 
-void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es)
-{
-   u16 chksum;
-
-   exfat_calc_entry_set_chksum(es, );
-   es->de_file->checksum = cpu_to_le16(chksum);
-   es->modified = true;
-}
-
-int exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync)
+int exfat_put_dentry_set(struct exfat_entry_set_cache *es, int modified, int 
sync)
 {
int i, err = 0;
 
-   if (es->modified)
-   err = exfat_update_bhs(es->bh, es->num_bh, sync);
+   if (modified) {
+   int off = es->start_off + (modified - 1) * DENTRY_SIZE;
+   int modified_bh = min(EXFAT_B_TO_BLK(off, es->sb) + 1, 
es->num_bh);
+   u16 chksum;
+
+   err = exfat_calc_entry_set_chksum(es, );
+   if (!err) {
+   es->de_file->checksum = cpu_to_le16(chksum);
+   err = exfat_update_bhs(es->bh, modified_bh, sync);
+   }
+   }
 
for (i = 0; i < es->num_bh; i++)
if (err)
@@ -802,7 +802,6 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct 
super_block *sb,
if (!es)
return NULL;
es->sb = sb;
-   es->modified = false;
es->num_entries = 1;
 
/* byte offset in cluster */
@@ -861,7 +860,7 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct 
super_block *sb,
return es;
 
 free_es:
-   exfat_free_dentry_set(es, false);
+   exfat_put_dentry_set(es, 0, false);
return NULL;
 }
 
@@ -973,7 +972,7 @@ int exfat_find_dir_entry(struct super_block *sb, struct 
exfat_inode_info *ei,
!exfat_get_uniname_from_name_entries(es, 
_name) &&
!exfat_uniname_ncmp(sb, p_uniname->name, 
uni_name.name, name_len);
 
-   exfat_free_dentry_set(es, false);
+   exfat_put_dentry_set(es, 0, false);
 
if (found) {
/* set the last used position as hint */
diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h
index 489881bf9bde..4dc5ce857d1f 100644
--- a/fs/exfat/exfat_fs.h
+++ b/fs/exfat/exfat_fs.h
@@ -170,7 +170,6 @@ struct exfat_hint {
 
 struct exfat_entry_set_cache {
struct super_block *sb;
-   bool modified;
unsigned int start_off;
int num_bh;
struct buffer_head *bh[DIR_CACHE_SIZE];
@@ -452,7 +451,6 @@ int exfat_remove_entries(struct inode *inode, struct 
exfat_chain *p_dir,
int entry, int order, int num_entries);
 int exfat_update_dir_chksum(struct inode *inode, struct exfat_chain *p_dir,
int entry);
-void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es);
 int exfat_calc_num_entries(struct exfat_uni_name *p_uniname);
 int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei,
struct exfat_chain *p_dir, struct exfat_uni_name *p_uniname,
@@ -467,7 +465,7 @@ struct exfat_dentry *exfat_get_validated_dentry(struct 
exfat_entry_set_cache *es
int num, unsigned int type);
 struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
struct exfat_chain *p_dir, int entry, int max_entries);
-int exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync);
+int exfat_put_dentry_set(struct exfat_entry_set_cache *es, int modified, int 
sync);
 int exfat_count_dir_entries(struct super_block *sb, struct exfat_chain 

Re: [RFC 1/3] Initialize devlink health dump framework for the dlge driver

2020-08-20 Thread Benjamin Poirier
On 2020-08-21 11:08 +0800, Coiby Xu wrote:
[...]
> > > diff --git a/drivers/staging/qlge/qlge_health.h 
> > > b/drivers/staging/qlge/qlge_health.h
> > > new file mode 100644
> > > index ..07d3bafab845
> > > --- /dev/null
> > > +++ b/drivers/staging/qlge/qlge_health.h
> > > @@ -0,0 +1,2 @@
> > > +#include 
> > > +int qlge_health_create_reporters(struct qlge_devlink *priv);
> > 
> > I would suggest to put this in qlge.h instead of creating a new file.
> 
> Although there are only two lines for now, is it possible qlge will add
> more devlink code? If that's the case, a file to single out these code

I would say that if there's more content in the future, it can move to a
separate file in the future.

If you feel strongly about putting this in its own file right away, then
make sure to add the usual
#ifndef QLGE_HEALTH_H
#define QLGE_HEALTH_H
...


[PATCH v2 1/2] exfat: add dir-entry set checksum validation

2020-08-20 Thread Tetsuhiro Kohada
Add checksum validation for dir-entry set when getting it.
exfat_calc_entry_set_chksum_with() also validates entry-type.

** This patch depends on:
  '[PATCH v3] exfat: integrates dir-entry getting and validation'

Signed-off-by: Tetsuhiro Kohada 
---
Changes in v2
 - Add error log if checksum mismatch

 fs/exfat/dir.c | 36 
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c
index 0b42544e6340..6f9de364a919 100644
--- a/fs/exfat/dir.c
+++ b/fs/exfat/dir.c
@@ -565,18 +565,27 @@ int exfat_remove_entries(struct inode *inode, struct 
exfat_chain *p_dir,
return 0;
 }
 
-void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es)
+static int exfat_calc_entry_set_chksum(struct exfat_entry_set_cache *es, u16 
*chksum)
 {
-   int chksum_type = CS_DIR_ENTRY, i;
-   unsigned short chksum = 0;
struct exfat_dentry *ep;
+   int i;
 
-   for (i = 0; i < es->num_entries; i++) {
-   ep = exfat_get_validated_dentry(es, i, TYPE_ALL);
-   chksum = exfat_calc_chksum16(ep, DENTRY_SIZE, chksum,
-chksum_type);
-   chksum_type = CS_DEFAULT;
+   ep = container_of(es->de_file, struct exfat_dentry, dentry.file);
+   *chksum = exfat_calc_chksum16(ep, DENTRY_SIZE, 0, CS_DIR_ENTRY);
+   for (i = 0; i < es->de_file->num_ext; i++) {
+   ep = exfat_get_validated_dentry(es, 1 + i, TYPE_SECONDARY);
+   if (!ep)
+   return -EIO;
+   *chksum = exfat_calc_chksum16(ep, DENTRY_SIZE, *chksum, 
CS_DEFAULT);
}
+   return 0;
+}
+
+void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es)
+{
+   u16 chksum;
+
+   exfat_calc_entry_set_chksum(es, );
es->de_file->checksum = cpu_to_le16(chksum);
es->modified = true;
 }
@@ -777,6 +786,7 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct 
super_block *sb,
struct exfat_entry_set_cache *es;
struct exfat_dentry *ep;
struct buffer_head *bh;
+   u16 chksum;
 
if (p_dir->dir == DIR_DELETED) {
exfat_err(sb, "access to deleted dentry");
@@ -841,11 +851,13 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct 
super_block *sb,
goto free_es;
es->de_stream = >dentry.stream;
 
-   for (i = 2; i < es->num_entries; i++) {
-   if (!exfat_get_validated_dentry(es, i, TYPE_SECONDARY))
-   goto free_es;
+   if (max_entries == ES_ALL_ENTRIES &&
+   ((exfat_calc_entry_set_chksum(es, ) ||
+ chksum != le16_to_cpu(es->de_file->checksum {
+   exfat_err(sb, "invalid entry-set checksum (entry : 0x%08x, 
set-checksum : 0x%04x, checksum : 0x%04x)",
+ entry, le16_to_cpu(es->de_file->checksum), chksum);
+   goto free_es;
}
-
return es;
 
 free_es:
-- 
2.25.1



Re: [Patch] cpufreq: replace cpu_logical_map with read_cpuid_mpir

2020-08-20 Thread Viresh Kumar
On 20-08-20, 13:37, Sudeep Holla wrote:
> On Thu, Aug 20, 2020 at 11:09:45AM +0530, Viresh Kumar wrote:
> > On 12-08-20, 01:13, Sumit Gupta wrote:
> > > Commit eaecca9e7710 ("arm64: Fix __cpu_logical_map undefined issue")
> > > fixes the issue with building tegra194 cpufreq driver as module. But
> > > the fix might cause problem while supporting physical cpu hotplug[1].
> > > 
> > > This patch fixes the original problem by avoiding use of 
> > > cpu_logical_map().
> > > Instead calling read_cpuid_mpidr() to get MPIDR on target cpu.
> > > 
> > > [1] https://lore.kernel.org/linux-arm-kernel/20200724131059.GB6521@bogus/
> > > 
> > > Reviewed-by: Sudeep Holla 
> > > Signed-off-by: Sumit Gupta 
> > > ---
> > >  drivers/cpufreq/tegra194-cpufreq.c | 10 +++---
> > >  1 file changed, 7 insertions(+), 3 deletions(-)
> > 
> > Applied. Thanks.
> 
> Just to confirm, is this going as a fix ? We want to drop exporting
> cpu_logical_map in v5.9 so this needs to go as fix. I missed it earlier,
> actually,
> 
> Fixes: df320f89359c ("cpufreq: Add Tegra194 cpufreq driver")
> is appropriate here so that we can drop export symbol which was part of
> Commit eaecca9e7710 ("arm64: Fix __cpu_logical_map undefined issue")
> as a workaround to  fix the build.

Okay.

Rafael: Please pick this patch directly for next rc with 

Acked-by: Viresh Kumar 

-- 
viresh


linux-next: Signed-off-by missing for commits in the arm-soc-fixes tree

2020-08-20 Thread Stephen Rothwell
Hi all,

Commits

  8d53ecfbf231 ("arm64: dts: xilinx: Align IOMMU nodename with dtschema")
  b4b6fb8de8dc ("arm64: dts: zynqmp: Add GTR transceivers")

are missing a Signed-off-by from their committer.

-- 
Cheers,
Stephen Rothwell


pgpIMTrZ27tON.pgp
Description: OpenPGP digital signature


Re: [PATCH v3 1/1] phy: tusb1210: use bitmasks to set VENDOR_SPECIFIC2

2020-08-20 Thread Vinod Koul
On 19-08-20, 15:57, Geert Uytterhoeven wrote:
> Hi Liam,
> 
> 
> On Mon, Aug 17, 2020 at 7:38 PM Liam Beguin  wrote:
> > From: Liam Beguin 
> >
> > Start by reading the content of the VENDOR_SPECIFIC2 register and update
> > each bit field based on device properties when defined.
> >
> > The use of bit masks prevents fields from overriding each other and
> > enables users to clear bits which are set by default, like datapolarity
> > in this instance.
> >
> > Signed-off-by: Liam Beguin 
> > ---
> > Changes since v1:
> > - use set_mask_bits
> >
> > Changes since v2:
> > - fix missing bit shift dropped in v2
> > - rebase on 5.9-rc1
> >
> >  drivers/phy/ti/phy-tusb1210.c | 27 +--
> >  1 file changed, 17 insertions(+), 10 deletions(-)
> >
> > diff --git a/drivers/phy/ti/phy-tusb1210.c b/drivers/phy/ti/phy-tusb1210.c
> > index d8d0cc11d187..358842b5790f 100644
> > --- a/drivers/phy/ti/phy-tusb1210.c
> > +++ b/drivers/phy/ti/phy-tusb1210.c
> > @@ -14,8 +14,11 @@
> >
> >  #define TUSB1210_VENDOR_SPECIFIC2  0x80
> >  #define TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT  0
> > +#define TUSB1210_VENDOR_SPECIFIC2_IHSTX_MASK   GENMASK(3, 0)
> >  #define TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_SHIFT 4
> > +#define TUSB1210_VENDOR_SPECIFIC2_ZHSDRV_MASK  GENMASK(5, 4)
> >  #define TUSB1210_VENDOR_SPECIFIC2_DP_SHIFT 6
> > +#define TUSB1210_VENDOR_SPECIFIC2_DP_MASK  BIT(6)
> >
> >  struct tusb1210 {
> > struct ulpi *ulpi;
> > @@ -118,23 +121,27 @@ static int tusb1210_probe(struct ulpi *ulpi)
> >  * diagram optimization and DP/DM swap.
> >  */
> >
> > +   reg = ulpi_read(ulpi, TUSB1210_VENDOR_SPECIFIC2);
> > +
> > /* High speed output drive strength configuration */
> > -   device_property_read_u8(>dev, "ihstx", );
> > -   reg = val << TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT;
> > +   if (!device_property_read_u8(>dev, "ihstx", ))
> > +   reg = set_mask_bits(, 
> > TUSB1210_VENDOR_SPECIFIC2_IHSTX_MASK,
> > +   val << 
> > TUSB1210_VENDOR_SPECIFIC2_IHSTX_SHIFT);
> 
> Triggered by your patches to add support for cmpxchg on u8 pointers to
> various architectures (which is a valuable goal in itself ;-), I decided
> to have a look at the underlying problem you were facing.
> 
> IMHO, using set_mask_bits() is overkill here.  That helper is meant to
> update individual bits in a variable that may be accessed concurrently,
> hence its use of cmpxchg().
> 
> In this driver, you just want to modify a local variable, by clearing a
> field, and setting some bits. No concurrency is involved.
> Perhaps using FIELD_PREP() from include/linux/bitfield.h is more
> appropriate?

Yeah i discovered the include/linux/bitfield.h and yes that looks more
apt here. u32_encode_bits() would make sense here and get rid of mask
and shift stuff too.

-- 
~Vinod


Re: [PATCH v5] phy: omap-usb2-phy: disable PHY charger detect

2020-08-20 Thread Vinod Koul
On 20-08-20, 20:27, Sekhar Nori wrote:
> On 8/20/20 7:09 PM, Roger Quadros wrote:
> > AM654x PG1.0 has a silicon bug that D+ is pulled high after POR, which
> > could cause enumeration failure with some USB hubs.  Disabling the
> > USB2_PHY Charger Detect function will put D+ into the normal state.
> > 
> > This addresses Silicon Errata:
> > i2075 - "USB2PHY: USB2PHY Charger Detect is Enabled by Default Without VBUS
> > Presence"
> > 
> > Signed-off-by: Roger Quadros 
> 
> + Vinod as well

Thanks, can you please rebase and resend these patches. I dont have
them in my inbox

Regards
-- 
~Vinod


Re: [PATCH 2/2] soundwire: fix port_ready[] dynamic allocation in mipi_disco and ASoC codecs

2020-08-20 Thread Vinod Koul
On 18-08-20, 07:09, Pierre-Louis Bossart wrote:
> 
> 
> On 8/18/20 1:36 AM, Vinod Koul wrote:
> > On 18-08-20, 01:47, Bard Liao wrote:
> > > From: Pierre-Louis Bossart 
> > > 
> > > The existing code allocates memory for the total number of ports.
> > > This only works if the ports are contiguous, but will break if e.g. a
> > > Devices uses port0, 1, and 14. The port_ready[] array would contain 3
> > > elements, which would lead to an out-of-bounds access. Conversely in
> > > other cases, the wrong port index would be used leading to timeouts on
> > > prepare.
> > > 
> > > This can be fixed by allocating for the worst-case of 15
> > > ports (DP0..DP14). In addition since the number is now fixed, we can
> > > use an array instead of a dynamic allocation.
> > > 
> > > Signed-off-by: Pierre-Louis Bossart 
> > > Reviewed-by: Rander Wang 
> > > Reviewed-by: Guennadi Liakhovetski 
> > > Signed-off-by: Bard Liao 
> > > ---
> > >   drivers/soundwire/mipi_disco.c  | 18 +-
> > >   drivers/soundwire/slave.c   |  4 
> > >   include/linux/soundwire/sdw.h   |  2 +-
> > >   sound/soc/codecs/max98373-sdw.c | 15 +--
> > >   sound/soc/codecs/rt1308-sdw.c   | 14 +-
> > >   sound/soc/codecs/rt5682-sdw.c   | 15 +--
> > >   sound/soc/codecs/rt700-sdw.c| 15 +--
> > >   sound/soc/codecs/rt711-sdw.c| 15 +--
> > >   sound/soc/codecs/rt715-sdw.c| 33 +
> > 
> > This looks fine, but the asoc changes are not dependent, so maybe we
> > should split them up and then can go thru Mark. Or Mark acks, either way
> > would work for me
> 
> There are 3 dependencies that we tracked between SoundWire and ASoC
> subsystems:
> 
> a) addition of SDCA control macro (needed before SDCA codec drivers can be
> shared)
> b) this series - we could indeed submit the codec changes to Mark's tree
> separately, but then the SoundWire tree would be broken: the codec drivers
> would still try to allocate dynamically what is now a fixed-size array.
> c) configuration of the interrupt masks in codec drivers instead of
> hard-coded in bus driver + spurious parity error workaround (not posted yet
> but ready).
> 
> The changes in ASoC codecs are really only on the initialization part
> (either removing a dynamic allocation or setting masks), there's no
> functional change otherwise.
> 
> I think the simplest to avoid multiple back-and-forth is to have these small
> interface/initialization changes merged through the SoundWire subsystem,
> then merged by Mark from a single immutable tag. Would this work for
> everyone?

That would work for me, but you need to split the asoc, regmap, sdw
patches. I am sure looking at patch tag, other maintainers would have
skipped these patches..

> In addition, there's a WIP change to regmap to add support for SoundWire 1.2
> MBQ-based register access, but this only affects regmap and ASoC trees, all
> handled by Mark.
> 
> I don't think we have any other cross-tree changes planned for now, the SDCA
> infrastructure plumbing is still rather open.

-- 
~Vinod


Re: [PATCH v2] soundwire: SDCA: add helper macro to access controls

2020-08-20 Thread Vinod Koul
On 17-08-20, 10:14, Pierre-Louis Bossart wrote:
> 
> > > The upcoming SDCA (SoundWire Device Class Audio) specification defines
> > > a hiearchical encoding to interface with Class-defined capabilities,
> > 
> > typo hiearchical
> 
> ok
> 
> > > based on which audio function, entity, control and channel being used.
> > 
> > Can you please elaborate on what do these terms refer to?
> > 
> > Also can we have some documentation for this and how Linux is going to
> > use it..
> 
> These are concepts in the SDCA draft spec, and that should be the reference.
> We worked with MIPI so that this spec will be available with a click-through
> agreement when ratified, for now it's only available to contributors per
> MIPI bylaws.
> 
> If you do not have access to this specification, then that's a real problem.
> Maybe you need to let Bard take care of this part as a co-maintainer?
> 
> The goal with this macro is to enable a first set of codecs drivers using
> these concepts to be released upstream. All you need to know at this point
> is that controls are defined in a hierarchical way and accessed with a
> read/write transaction from/to the address created with the following macro.

Hmmm, if we cannot get some kind of Documentation of what it means and
review the code, then I do not see a point in getting this into kernel.

As kernel community we would like to see some form of Documentation
associated with the patches on what this means.

If that is not possible due to MIPI regulations, maybe deferring
this would make sense

Thanks
> 
> > > +/* v1.2 device - SDCA address mapping */
> > > +#define SDW_SDCA_CTL(fun, ent, ctl, ch)  (BIT(30) |  
> > > \
> > > +  (((fun) & 0x7) << 22) |
> > > \
> > > +  (((ent) & 0x40) << 15) |   
> > > \
> > > +  (((ent) & 0x3f) << 7) |
> > > \
> > > +  (((ctl) & 0x30) << 15) |   
> > > \
> > > +  (((ctl) & 0x0f) << 3) |
> > > \
> > > +  (((ch) & 0x38) << 12) |
> > > \
> > > +  ((ch) & 0x07))
> > > +
> > 
> > how about adding an underscore to the arguments here:
> > 
> > #define SDW_SDCA_CTL(_fun, _ent, _ctl, _ch)
> > and so on..
> 
> I checked the SoundWire defines and the vast majority of the macros don't
> use underscores, and when they do there's no consistency between 1 or 2
> underscores.

-- 
~Vinod


Re: [PATCH v2 3/6] powerpc/32s: Only leave NX unset on segments used for modules

2020-08-20 Thread Christophe Leroy




Le 21/08/2020 à 00:00, Andreas Schwab a écrit :

On Jun 29 2020, Christophe Leroy wrote:


Instead of leaving NX unset on all segments above the start
of vmalloc space, only leave NX unset on segments used for
modules.


I'm getting this crash:

kernel tried to execute exec-protected page (f294b000) - exploit attempt (uid: 
0)
BUG: Unable to handle kernel instruction fetch
Faulting instruction address: 0xf294b000
Oops: Kernel access of bad area, sig: 11 [#1]
BE PAGE_SIZE=4K MMU=Hash PowerMac
Modules linked in: pata_macio(+)
CPU: 0 PID: 87 Comm: udevd Not tainted 5.8.0-rc2-test #49
NIP:  f294b000 LR: 0005c60 CTR: f294b000
REGS: f18d9cc0 TRAP: 0400  Not tainted  (5.8.0-rc2-test)
MSR:  10009032   CR: 84222422  XER: 2000
GPR00: c0005c14 f18d9d78 ef30ca20  efe0 c00993d0 ef6da038 005e
GPR08: c09050b8 c08b  f18d9d78 44222422 10072070  0fefaca4
GPR16: 1006a00c f294d50b 0120 0124 c0096ea8 000e ef2776c0 ef2776e4
GPR24: f18fd6e8 0001 c086fe64 c086fe04  c08b f294b000 
NIP [f294b000] pata_macio_init+0x0/0xc0 [pata_macio]
LR [c0005c60] do_one_initcall+0x6c/0x160
Call Trace:
[f18d9d78] [c0005c14] do_one_initcall+0x20/0x160 (unreliable)
[f18d9dd8] [c009a22c] do_init_module+0x60/0x1c0
[f18d9df8] [c00993d8] load_module+0x16a8/0x1c14
[f18d9ea8] [c0099aa4] sys_finit_module+0x8c/0x94
[f18d9f38] [c0012174] ret_from_syscall+0x0/0x34
--- interrupt: c01 at 0xfdb4318
LR = 0xfeee9c0
Instruction dump:
       
    <3d20c08b> 3d40c086 9421ffe0 8129106c
---[ end trace 85a98cc836109871 ]---



Please try the patch at 
https://patchwork.ozlabs.org/project/linuxppc-dev/patch/07884ed033c31e074747b7eb8eaa329d15db07ec.1596641219.git.christophe.le...@csgroup.eu/


And if you are using KAsan, also take 
https://patchwork.ozlabs.org/project/linuxppc-dev/patch/6eddca2d5611fd57312a88eae31278c87a8fc99d.1596641224.git.christophe.le...@csgroup.eu/


Allthough I have some doubt that it will fix it, because the faulting 
instruction address is at 0xf294b000 which is within the vmalloc area. 
In the likely case the patch doesn't fix the issue, can you provide your 
.config and a dump of /sys/kernel/debug/powerpc/segment_registers (You 
have to have CONFIG_PPC_PTDUMP enabled for that) and also the below part 
from boot log.


[0.00] Memory: 509556K/524288K available (7088K kernel code, 
592K rwdata, 1304K rodata, 356K init, 803K bss, 14732K reserved, 0K 
cma-reserved)

[0.00] Kernel virtual memory layout:
[0.00]   * 0xff7ff000..0xf000  : fixmap
[0.00]   * 0xff7fd000..0xff7ff000  : early ioremap
[0.00]   * 0xe100..0xff7fd000  : vmalloc & ioremap


Thanks
Christophe


Re: [PATCH] soundwire: cadence: fix race condition between suspend and Slave device alerts

2020-08-20 Thread Vinod Koul
On 19-08-20, 07:51, Pierre-Louis Bossart wrote:
> 
> 
> On 8/19/20 4:06 AM, Vinod Koul wrote:
> > On 18-08-20, 06:23, Bard Liao wrote:
> > > From: Pierre-Louis Bossart 
> > > 
> > > In system suspend stress cases, the SOF CI reports timeouts. The root
> > > cause is that an alert is generated while the system suspends. The
> > > interrupt handling generates transactions on the bus that will never
> > > be handled because the interrupts are disabled in parallel.
> > > 
> > > As a result, the transaction never completes and times out on resume.
> > > This error doesn't seem too problematic since it happens in a work
> > > queue, and the system recovers without issues.
> > > 
> > > Nevertheless, this race condition should not happen. When doing a
> > > system suspend, or when disabling interrupts, we should make sure the
> > > current transaction can complete, and prevent new work from being
> > > queued.
> > > 
> > > BugLink: https://github.com/thesofproject/linux/issues/2344
> > > Signed-off-by: Pierre-Louis Bossart 
> > > Reviewed-by: Ranjani Sridharan 
> > > Reviewed-by: Rander Wang 
> > > Signed-off-by: Bard Liao 
> > > ---
> > >   drivers/soundwire/cadence_master.c | 24 +++-
> > >   drivers/soundwire/cadence_master.h |  1 +
> > >   2 files changed, 24 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/soundwire/cadence_master.c 
> > > b/drivers/soundwire/cadence_master.c
> > > index 24eafe0aa1c3..1330ffc47596 100644
> > > --- a/drivers/soundwire/cadence_master.c
> > > +++ b/drivers/soundwire/cadence_master.c
> > > @@ -791,7 +791,16 @@ irqreturn_t sdw_cdns_irq(int irq, void *dev_id)
> > >CDNS_MCP_INT_SLAVE_MASK, 0);
> > >   int_status &= ~CDNS_MCP_INT_SLAVE_MASK;
> > > - schedule_work(>work);
> > > +
> > > + /*
> > > +  * Deal with possible race condition between interrupt
> > > +  * handling and disabling interrupts on suspend.
> > > +  *
> > > +  * If the master is in the process of disabling
> > > +  * interrupts, don't schedule a workqueue
> > > +  */
> > > + if (cdns->interrupt_enabled)
> > > + schedule_work(>work);
> > 
> > would it not make sense to mask the interrupts first and then cancel the
> > work? that way you are guaranteed that after this call you dont have
> > interrupts and work scheduled?
> 
> cancel_work_sync() will either
> a) wait until the current work completes, or
> b) prevent a new one from starting.
> 
> there's no way to really 'abort' a workqueue, 'cancel' means either complete
> or don't start.

Quite right, as that is how everyone deals with it. Stop the irq from
firing first and then wait until work is cancelled or completed, hence
cancel_work_sync()

> if you disable the interrupts then cancel the work, you have a risk of not
> letting the work complete if it already started (case a).
> 
> The race is
> a) the interrupt thread (this function) starts
> b) the work is scheduled and starts
> c) the suspend handler starts and disables interrupts in [1] below.
> d) the work initiates transactions which will never complete since Cadence
> interrupts have been disabled.

Would it not be better to let work handle the case of interrupts
disabled and not initiates transactions which wont complete here? That
sounds more reasonable to do rather than complete the work which anyone
doesn't matter as you are suspending

> So the idea was that before disabling interrupts, the suspend handler
> changes the status, and then calls cancel_work_sync(). the status is also
> used to prevent a new work from being scheduled if you already know the
> suspend is on-going. The test on the status above is not strictly necessary,
> I believe the sequence is safe without it but it avoid starting a useless
> work.
> 
> If you want to follow the flow it's better to start with what the suspend
> handler does below first, then look at how the interrupt thread might
> interfere. The diff format does not help, might be also easier to apply the
> patch and look at the rest of the code, e.g the 3 mask updates mentioned
> below are not included in the diff.
> 
> > 
> > >   }
> > >   cdns_writel(cdns, CDNS_MCP_INTSTAT, int_status);
> > > @@ -924,6 +933,19 @@ int sdw_cdns_enable_interrupt(struct sdw_cdns *cdns, 
> > > bool state)
> > >   slave_state = cdns_readl(cdns, CDNS_MCP_SLAVE_INTSTAT1);
> > >   cdns_writel(cdns, CDNS_MCP_SLAVE_INTSTAT1, slave_state);
> > >   }
> 
> [1]
> 
> > > + cdns->interrupt_enabled = state;
> > > +
> > > + /*
> > > +  * Complete any on-going status updates before updating masks,
> > > +  * and cancel queued status updates.
> > > +  *
> > > +  * There could be a race with a new interrupt thrown before
> > > +  * the 3 mask updates below are complete, so in the interrupt
> > > +  * we use the 'interrupt_enabled' status to prevent new work
> > > +  * from being 

Re: [PATCH 1/1] md: Simplify code with existing definition RESYNC_SECTORS in raid10.c

2020-08-20 Thread Song Liu
On Thu, Aug 20, 2020 at 6:29 PM Zhen Lei  wrote:
>
> #define RESYNC_SECTORS (RESYNC_BLOCK_SIZE >> 9)
>
> "RESYNC_BLOCK_SIZE/512" is equal to "RESYNC_BLOCK_SIZE >> 9", replace it
> with RESYNC_SECTORS.
>
> Signed-off-by: Zhen Lei 

Applied to md-next. Thanks!


linux-next: Tree for Aug 21

2020-08-20 Thread Stephen Rothwell
Hi all,

Changes since 20200820:

My fixes tree is empty again.

The dma-mapping tree lost its qemu test boot failure.

The bpf-next tree gained a build failure for which I disabled BPF_PRELOAD.

The pinctrl-intel tree lost its build failure.

Non-merge commits (relative to Linus' tree): 1973
 3350 files changed, 67749 insertions(+), 24189 deletions(-)



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

You can see which trees have been included by looking in the Next/Trees
file in the source.  There are also quilt-import.log and merge.log
files in the Next directory.  Between each merge, the tree was built
with a ppc64_defconfig for powerpc, an allmodconfig for x86_64, a
multi_v7_defconfig for arm and a native build of tools/perf. After
the final fixups (if any), I do an x86_64 modules_install followed by
builds for x86_64 allnoconfig, powerpc allnoconfig (32 and 64 bit),
ppc44x_defconfig, allyesconfig and pseries_le_defconfig and i386, sparc
and sparc64 defconfig and htmldocs. And finally, a simple boot test
of the powerpc pseries_le_defconfig kernel in qemu (with and without
kvm enabled).

Below is a summary of the state of the merge.

I am currently merging 328 trees (counting Linus' and 86 trees of bug
fix patches pending for the current merge release).

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

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

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

-- 
Cheers,
Stephen Rothwell

$ git checkout master
$ git reset --hard stable
Merging origin/master (da2968ff879b Merge tag 'pci-v5.9-fixes-1' of 
git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci)
Merging fixes/master (9123e3a74ec7 Linux 5.9-rc1)
Merging kbuild-current/fixes (66c262be8f50 kconfig: qconf: remove unused colNr)
Merging arc-current/for-curr (97363c07f023 ARC: show_regs: fix r12 printing and 
simplify)
Merging arm-current/fixes (5c6360ee4a0e ARM: 8988/1: mmu: fix crash in EFI 
calls due to p4d typo in create_mapping_late())
Merging arm64-fixes/for-next/fixes (6a7389f0312f MAINTAINERS: Include drivers 
subdirs for ARM PMU PROFILING AND DEBUGGING entry)
Merging arm-soc-fixes/arm/fixes (fe1d899f4212 ARM: dts: keystone-k2g-evm: fix 
rgmii phy-mode for ksz9031 phy)
Merging uniphier-fixes/fixes (48778464bb7d Linux 5.8-rc2)
Merging drivers-memory-fixes/fixes (7ff3a2a626f7 memory: jz4780_nemc: Fix an 
error pointer vs NULL check in probe())
Merging m68k-current/for-linus (382f429bb559 m68k: defconfig: Update defconfigs 
for v5.8-rc3)
Merging powerpc-fixes/fixes (90a9b102eddf powerpc/pseries: Do not initiate 
shutdown when system is running on UPS)
Merging s390-fixes/fixes (b97bf44f9915 s390/pci: fix PF/VF linking on hot plug)
Merging sparc/master (0a95a6d1a4cd sparc: use for_each_child_of_node() macro)
Merging fscrypt-current/for-stable (2b4eae95c736 fscrypt: don't evict dirty 
inodes after removing key)
Merging net/master (ce51f63e63c5 net/smc: Prevent kernel-infoleak in 
__smc_diag_dump())
Merging bpf/master (c210773d6c6f bpf: selftests: global_funcs: Check err_str 
before strstr)
Merging ipsec/master (4eb2e1341575 espintcp: restore IP CB before handing the 
packet to xfrm)
Merging netfilter/master (cc5453a5b7e9 netfilter: conntrack: allow sctp 
hearbeat after connection re-use)
Merging ipvs/master (7c7ab580db49 net: Convert to use the fallthrough macro)
Merging wireless-drivers/master (9a2a0862d973 brcmfmac: reserve tx credit only 
when txctl is ready to send)
Merging mac80211/master (fce2ff728f95 nl80211: fix 
NL80211_ATTR_HE_6GHZ_CAPABILITY usage)
Merging rdma-fixes/for-rc (6da06c6291f3 Revert "RDMA/hns: Reserve one sge in 
order to avoid local length error")
Merging sound-current/for-linus (b90b925fd52c ALSA: hda: avoid reset of 
sdo_limit)
Merging sound-asoc-fixes/for-linus (82cb71d68c22 ASoC: SOF: Intel: add build 
support for SoundWire)
Merging regmap-fixes/for-linus (9123e3a74ec7 Linux 5.9-rc1)
Merging regulator-fixes/for-linus (ff945eff122d Merge remote-tracking branch 
'regulator/for-5.9' into regulator-linus)
Merging spi-fixes/for-linus (bd70f2c7c37c Merge remote-tracking branch 
'spi/for-5.9' into spi-linus)
Merging pci-current/for-linus (7c2308f79fc8 PCI/P2PDMA: Fix build without DMA 
ops)
Merging driver-core.current/driver-core-linus (9123e3a74ec7 Linux 5.9-rc1)

Re: [PATCH] soundwire: intel: fix CONFIG_PM and CONFIG_PM_SLEEP confusion

2020-08-20 Thread Vinod Koul
On 20-08-20, 22:04, Bard Liao wrote:
> From: Pierre-Louis Bossart 
> 
> When CONFIG_PM_SLEEP is not defined, GCC throws compilation warnings:
> 
> drivers/soundwire/intel.c:1816:12: warning: ‘intel_resume’ defined but
> not used [-Wunused-function]
>  1816 | static int intel_resume(struct device *dev)
>   |^~~~
> 
> drivers/soundwire/intel.c:1697:12: warning: ‘intel_suspend’ defined
> but not used [-Wunused-function]
>  1697 | static int intel_suspend(struct device *dev)
> 
> Fix by adding the missing CONFIG_PM_SLEEP.

Can you rather use __maybe for for these rather than wrapping in another
ifdef, that is the recommended way to do this

Thanks

> Note that we could move code around and use only 2 ifdefs, but this
> will generate conflicts so let's do this when all the pm handling is
> merged.
> 
> Signed-off-by: Pierre-Louis Bossart 
> Signed-off-by: Bard Liao 
> ---
>  drivers/soundwire/intel.c | 12 ++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/soundwire/intel.c b/drivers/soundwire/intel.c
> index dbcbe2708563..a2f0026cb2c1 100644
> --- a/drivers/soundwire/intel.c
> +++ b/drivers/soundwire/intel.c
> @@ -1525,7 +1525,7 @@ int intel_master_process_wakeen_event(struct 
> platform_device *pdev)
>   * PM calls
>   */
>  
> -#ifdef CONFIG_PM
> +#ifdef CONFIG_PM_SLEEP
>  
>  static int intel_suspend(struct device *dev)
>  {
> @@ -1562,6 +1562,9 @@ static int intel_suspend(struct device *dev)
>  
>   return 0;
>  }
> +#endif
> +
> +#ifdef CONFIG_PM
>  
>  static int intel_suspend_runtime(struct device *dev)
>  {
> @@ -1624,6 +1627,9 @@ static int intel_suspend_runtime(struct device *dev)
>  
>   return ret;
>  }
> +#endif
> +
> +#ifdef CONFIG_PM_SLEEP
>  
>  static int intel_resume(struct device *dev)
>  {
> @@ -1691,6 +1697,9 @@ static int intel_resume(struct device *dev)
>  
>   return ret;
>  }
> +#endif
> +
> +#ifdef CONFIG_PM
>  
>  static int intel_resume_runtime(struct device *dev)
>  {
> @@ -1797,7 +1806,6 @@ static int intel_resume_runtime(struct device *dev)
>  
>   return ret;
>  }
> -
>  #endif
>  
>  static const struct dev_pm_ops intel_pm = {
> -- 
> 2.17.1

-- 
~Vinod


Re: [PATCH] thermal: sysfs: Fall back to vmalloc() for cooling device's statistics

2020-08-20 Thread Viresh Kumar
On 21-08-20, 10:44, Yue Hu wrote:
> From: Yue Hu 
> 
> We observed warning about kzalloc() when register thermal cooling device
> in backlight_device_register(). backlight display can be a cooling device
> since reducing screen brightness will can help reduce temperature.
> 
> However, ->get_max_state of backlight will assign max brightness of 1024
> to states. The memory size can be getting 1MB+ due to states * states.
> That is so large to trigger kmalloc() warning.
> 
> So, let's use kvzalloc() to avoid the issue, also change kfree -> kvfree.
> 
> Suggested-by: Amit Kucheria 
> Signed-off-by: Yue Hu 
> ---
>  drivers/thermal/thermal_sysfs.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

Acked-by: Viresh Kumar 

-- 
viresh


Re: [PATCH] lib: Convert test_printf.c to KUnit

2020-08-20 Thread Arpitha Raghunandan
On 17/08/20 12:36 pm, Rasmus Villemoes wrote:
> On 17/08/2020 06.30, Arpitha Raghunandan wrote:
>> Converts test lib/test_printf.c to KUnit.
>> More information about KUnit can be found at
>> https://www.kernel.org/doc/html/latest/dev-tools/kunit/index.html.
>> KUnit provides a common framework for unit tests in the kernel.
> 
> So I can continue to build a kernel with some appropriate CONFIG set to
> y, boot it under virt-me, run dmesg and see if I broke printf? That's
> what I do now, and I don't want to have to start using some enterprisy
> framework.
> 

Yes, the test can be run on boot up. More information about this can be found 
here: 
https://www.kernel.org/doc/html/latest/dev-tools/kunit/start.html#running-tests-without-the-kunit-wrapper.

>> diff --git a/lib/test_printf.c b/lib/printf_kunit.c
>> similarity index 45%
>> rename from lib/test_printf.c
>> rename to lib/printf_kunit.c
>> index 7ac87f18a10f..68ac5f9b8d28 100644
>> --- a/lib/test_printf.c
>> +++ b/lib/printf_kunit.c
>> @@ -5,6 +5,7 @@
>>  
>>  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>>  
>> +#include 
>>  #include 
>>  #include 
>>  #include 
>> @@ -30,79 +31,61 @@
>>  #define PAD_SIZE 16
>>  #define FILL_CHAR '$'
>>  
>> -static unsigned total_tests __initdata;
>> -static unsigned failed_tests __initdata;
>> -static char *test_buffer __initdata;
>> -static char *alloced_buffer __initdata;
>> +static char *test_buffer;
>> +static char *alloced_buffer;
>>  
>> -static int __printf(4, 0) __init
>> -do_test(int bufsize, const char *expect, int elen,
>> +static void __printf(5, 0)
>> +do_test(struct kunit *kunittest, int bufsize, const char *expect, int elen,
>>  const char *fmt, va_list ap)
>>  {
>>  va_list aq;
>>  int ret, written;
>>  
>> -total_tests++;
>> -
>>  memset(alloced_buffer, FILL_CHAR, BUF_SIZE + 2*PAD_SIZE);
>>  va_copy(aq, ap);
>>  ret = vsnprintf(test_buffer, bufsize, fmt, aq);
>>  va_end(aq);
>>  
>> -if (ret != elen) {
>> -pr_warn("vsnprintf(buf, %d, \"%s\", ...) returned %d, expected 
>> %d\n",
>> +KUNIT_EXPECT_EQ_MSG(kunittest, ret, elen,
>> +"vsnprintf(buf, %d, \"%s\", ...) returned %d, expected 
>> %d\n",
>>  bufsize, fmt, ret, elen);
>> -return 1;
>> -}
> 
> 
> IIRC, some of these early returns are required to ensure the following
> checks do not fail (as in, potentially crash the kernel) simply because
> they go off into the weeds. Please double-check that they are all safe
> to continue to perform (though, another reason I might have put them in
> is to simply avoid lots of useless collateral).
> 

These are safe to perform. I will check once again though.

> 
>> -if (memchr_inv(alloced_buffer, FILL_CHAR, PAD_SIZE)) {
>> +KUNIT_EXPECT_EQ_MSG(kunittest, memchr_inv(alloced_buffer, FILL_CHAR, 
>> PAD_SIZE), NULL,
> 
>> -if (memchr_inv(test_buffer, FILL_CHAR, BUF_SIZE + PAD_SIZE)) {
>> +KUNIT_EXPECT_FALSE_MSG(kunittest,
> 
>> -if (memchr_inv(test_buffer + written + 1, FILL_CHAR, BUF_SIZE + 
>> PAD_SIZE - (written + 1))) {
>> +KUNIT_EXPECT_FALSE_MSG(kunittest,
>> +memchr_inv(test_buffer + written + 1, FILL_CHAR, 
>> BUF_SIZE + PAD_SIZE - (written + 1))
> 
> Why the inconsistency in what a memchr_inv != NULL check gets converted to?
> 

Oh my bad. I will make this consistent.

> 
>>  
>> -static void __printf(3, 4) __init
>> -__test(const char *expect, int elen, const char *fmt, ...)
>> +static void __printf(4, 5)
>> +__test(struct kunit *kunittest, const char *expect, int elen, const char 
>> *fmt, ...)
>>  {
>>  va_list ap;
>>  int rand;
>>  char *p;
>>  
>> -if (elen >= BUF_SIZE) {
>> -pr_err("error in test suite: expected output length %d too 
>> long. Format was '%s'.\n",
>> -   elen, fmt);
>> -failed_tests++;
>> -return;
>> -}
>> +KUNIT_EXPECT_LT_MSG(kunittest, elen, BUF_SIZE,
>> +"error in test suite: expected output length %d too 
>> long. Format was '%s'.\n",
>> +elen, fmt);
> 
> And it's ok to continue with the tests when the test suite itself is
> buggy because? [*]
> 
>>  va_start(ap, fmt);
>>  
>> @@ -112,49 +95,46 @@ __test(const char *expect, int elen, const char *fmt, 
>> ...)
>>   * enough and 0), and then we also test that kvasprintf would
>>   * be able to print it as expected.
>>   */
>> -failed_tests += do_test(BUF_SIZE, expect, elen, fmt, ap);
>> +do_test(kunittest, BUF_SIZE, expect, elen, fmt, ap);
>>  rand = 1 + prandom_u32_max(elen+1);
>>  /* Since elen < BUF_SIZE, we have 1 <= rand <= BUF_SIZE. */
>> -failed_tests += do_test(rand, expect, elen, fmt, ap);
> 
> [*] Certainly this invariant gets violated, so we (may) provide do_test
> with a buffer size larger than, well, BUF_SIZE.
> 
>>  
>> -#define test(expect, fmt, ...)  \
>> -

Re: [PATCH v1 1/2] pinctrl: mediatek: support access registers without race-condition

2020-08-20 Thread Light Hsieh
On Wed, 2020-08-19 at 16:11 -0700, Sean Wang wrote:
> Hi Light,
> 
> On Tue, Aug 18, 2020 at 1:36 AM  wrote:
> >
> > From: Light Hsieh 
> >
> > Some MediaTek SOC provide more control registers other than value register.
> 
> s/MT6765/Some MediaTek SoC/
> 
> > Generanll, a value register need read-modify-write is at offset 0x0.
> 
> s/Generally/Generanll/
> 
> > A corresponding SET register is at offset 0xXXX4. Write 1s' to some bits
> >   of SET register will set same bits in value register.
> > A corresponding CLR register is at offset 0xXXX8. Write 1s' to some bits
> >   of CLR register will clear same bits in value register.
> > For GPIO mode selection, MWR register is provided at offset 0xXXXC.
> >   With MWR, the MSBit of GPIO mode selection field is for 
> > modification-enable,
> >   not for GPIO mode selection, and the remaining LSBits are for mode
> >   selection.
> >   Take mode selection field with 4-bits as example, to select mode 0~7 via
> >   MWR register, 8~15 (instead of 0~7) shall be written to corresponding mode
> >   selection field.
> > When using SET/CLR/MWR registers, read-modify-write of value register is not
> >   necessary. This can prevent from race condition when multiple bus masters
> >   concurrently read-modify-write the same value register for setting 
> > different
> >   fields of the same value register.
> >
> > Signed-off-by: Light Hsieh 
> > ---
> >  drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c | 69 
> > ++--
> >  drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h |  2 +
> >  2 files changed, 67 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c 
> > b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
> > index b77b18f..51f0b53 100644
> > --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
> > +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
> > @@ -18,6 +18,29 @@
> >  #include "mtk-eint.h"
> >  #include "pinctrl-mtk-common-v2.h"
> >
> > +/* Some MediaTek SOC provide more control registers other than value 
> > register.
> 
> s/MT6765/Some MediaTek SoC/

Not only MT6765 provides such control registers.
Actually, many (but not all) MediaTek SoC support.
Other MediaTek SoC can enable such control according to its HW support.

> 
> > + * Generanll, a value register need read-modify-write is at offset 
> > 0x0.
> 
> s/Generally/Generanll/
> 
> > + * A corresponding SET register is at offset 0xXXX4. Write 1s' to some 
> > bits
> > + *  of SET register will set same bits in value register.
> > + * A corresponding CLR register is at offset 0xXXX8. Write 1s' to some 
> > bits
> > + *  of CLR register will clear same bits in value register.
> > + * For GPIO mode selection, MWR register is provided at offset 0xXXXC.
> > + *  With MWR, the MSBit of GPIO mode selection field is for 
> > modification-enable,
> > + *  not for GPIO mode selection, and the remaining LSBits are for mode
> > + *  selection.
> > + *  Take mode selection field with 4-bits as example, to select mode 0~7 
> > via
> > + *  MWR register, 8~15 (instead of 0~7) shall be written to corresponding 
> > mode
> > + *  selection field.
> > + * When using SET/CLR/MWR registers, read-modify-write of value register 
> > is not
> > + *  necessary. This can prevent from race condition when multiple bus 
> > masters
> > + *  concurrently read-modify-write the same value register for setting 
> > different
> > + *  fields of the same value register.
> > + */
> > +
> > +#define SET_OFFSET 0x4
> > +#define CLR_OFFSET 0x8
> 
> can set/clr offset work for mode register?

Yes. However, use set/clr to change mode require 2 register access when
target mode is not all 0's or all 1's.
The mwr HW support is not available on mode register.

> 
> > +#define MWR_OFFSET 0xC
> > +
> >  /**
> >   * struct mtk_drive_desc - the structure that holds the information
> >   * of the driving current
> > @@ -64,6 +87,38 @@ void mtk_rmw(struct mtk_pinctrl *pctl, u8 i, u32 reg, 
> > u32 mask, u32 set)
> > mtk_w32(pctl, i, reg, val);
> >  }
> >
> > +
> > +static void mtk_hw_set_value_race_free(struct mtk_pinctrl *pctl,
> > +   struct mtk_pin_field *pf, u32 value)
> 
> s/mtk_hw_set_value_race_free/mtk_hw_w1sc/ to explictly indicate
> write-one ethier set or clear operation supported by hw
> 
> > +{
> > +   unsigned int set, clr;
> > +
> > +   set = value & pf->mask;
> > +   clr = (~set) & pf->mask;
> > +
> > +   if (set)
> > +   mtk_w32(pctl, pf->index, pf->offset + SET_OFFSET,
> > +   set << pf->bitpos);
> > +   if (clr)
> > +   mtk_w32(pctl, pf->index, pf->offset + CLR_OFFSET,
> > +   clr << pf->bitpos);
> > +}
> > +
> > +static void mtk_hw_set_mode_race_free(struct mtk_pinctrl *pctl,
> > +   struct mtk_pin_field *pf, u32 value)
> 
> s/mtk_hw_set_mode_race_free/mtk_hw_mwr/
> 
> > +{
> > +   

Re: [PATCH] rtlwifi: switch from 'pci_' to 'dma_' API

2020-08-20 Thread Larry Finger

On 8/20/20 9:46 AM, Christophe JAILLET wrote:

The wrappers in include/linux/pci-dma-compat.h should go away.

The patch has been generated with the coccinelle script below and has been
hand modified to replace GFP_ with a correct flag.
It has been compile tested.

The only file where some GFP_ flags are updated is 'pci.c'.

When memory is allocated in '_rtl_pci_init_tx_ring()' and
'_rtl_pci_init_rx_ring()' GFP_KERNEL can be used because both functions are
called from a probe function and no spinlock is taken.

The call chain is:
   rtl_pci_probe
 --> rtl_pci_init
   --> _rtl_pci_init_trx_ring
 --> _rtl_pci_init_rx_ring
 --> _rtl_pci_init_tx_ring


@@
@@
-PCI_DMA_BIDIRECTIONAL
+DMA_BIDIRECTIONAL

@@
@@
-PCI_DMA_TODEVICE
+DMA_TO_DEVICE

@@
@@
-PCI_DMA_FROMDEVICE
+DMA_FROM_DEVICE

@@
@@
-PCI_DMA_NONE
+DMA_NONE

@@
expression e1, e2, e3;
@@
-pci_alloc_consistent(e1, e2, e3)
+dma_alloc_coherent(>dev, e2, e3, GFP_)

@@
expression e1, e2, e3;
@@
-pci_zalloc_consistent(e1, e2, e3)
+dma_alloc_coherent(>dev, e2, e3, GFP_)

@@
expression e1, e2, e3, e4;
@@
-pci_free_consistent(e1, e2, e3, e4)
+dma_free_coherent(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_map_single(e1, e2, e3, e4)
+dma_map_single(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_single(e1, e2, e3, e4)
+dma_unmap_single(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4, e5;
@@
-pci_map_page(e1, e2, e3, e4, e5)
+dma_map_page(>dev, e2, e3, e4, e5)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_page(e1, e2, e3, e4)
+dma_unmap_page(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_map_sg(e1, e2, e3, e4)
+dma_map_sg(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_unmap_sg(e1, e2, e3, e4)
+dma_unmap_sg(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_single_for_cpu(e1, e2, e3, e4)
+dma_sync_single_for_cpu(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_single_for_device(e1, e2, e3, e4)
+dma_sync_single_for_device(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_sg_for_cpu(e1, e2, e3, e4)
+dma_sync_sg_for_cpu(>dev, e2, e3, e4)

@@
expression e1, e2, e3, e4;
@@
-pci_dma_sync_sg_for_device(e1, e2, e3, e4)
+dma_sync_sg_for_device(>dev, e2, e3, e4)

@@
expression e1, e2;
@@
-pci_dma_mapping_error(e1, e2)
+dma_mapping_error(>dev, e2)

@@
expression e1, e2;
@@
-pci_set_dma_mask(e1, e2)
+dma_set_mask(>dev, e2)

@@
expression e1, e2;
@@
-pci_set_consistent_dma_mask(e1, e2)
+dma_set_coherent_mask(>dev, e2)

Signed-off-by: Christophe JAILLET 
---
If needed, see post from Christoph Hellwig on the kernel-janitors ML:
https://marc.info/?l=kernel-janitors=158745678307186=4
---
  drivers/net/wireless/realtek/rtlwifi/pci.c| 116 +-
  .../wireless/realtek/rtlwifi/rtl8188ee/hw.c   |   9 +-
  .../wireless/realtek/rtlwifi/rtl8188ee/trx.c  |  13 +-
  .../wireless/realtek/rtlwifi/rtl8192ce/trx.c  |  14 +--
  .../wireless/realtek/rtlwifi/rtl8192de/trx.c  |  12 +-
  .../wireless/realtek/rtlwifi/rtl8192ee/trx.c  |  13 +-
  .../wireless/realtek/rtlwifi/rtl8192se/trx.c  |  12 +-
  .../wireless/realtek/rtlwifi/rtl8723ae/trx.c  |  14 +--
  .../wireless/realtek/rtlwifi/rtl8723be/hw.c   |   9 +-
  .../wireless/realtek/rtlwifi/rtl8723be/trx.c  |  13 +-
  .../wireless/realtek/rtlwifi/rtl8821ae/hw.c   |   9 +-
  .../wireless/realtek/rtlwifi/rtl8821ae/trx.c  |  13 +-
  12 files changed, 115 insertions(+), 132 deletions(-)


Tested-by: Larry Finger  for rtl8821ae.

Larry




Re: [PATCH] memory: brcmstb_dpfe: fix array index out of bounds

2020-08-20 Thread kernel test robot
Hi Markus,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.9-rc1 next-20200820]
[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/Markus-Mayer/memory-brcmstb_dpfe-fix-array-index-out-of-bounds/20200821-090533
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
da2968ff879b9e74688cdc658f646971991d2c56
config: arm-defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm 

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

All warnings (new ones prefixed by >>):

>> drivers/memory/brcmstb_dpfe.c:305:8: warning: type qualifiers ignored on 
>> function return type [-Wignored-qualifiers]
 305 | static const char * const get_error_text(unsigned int i)
 |^

# 
https://github.com/0day-ci/linux/commit/a2de88715f98369b7e4478457a6455c3e2c72725
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review 
Markus-Mayer/memory-brcmstb_dpfe-fix-array-index-out-of-bounds/20200821-090533
git checkout a2de88715f98369b7e4478457a6455c3e2c72725
vim +305 drivers/memory/brcmstb_dpfe.c

   304  
 > 305  static const char * const get_error_text(unsigned int i)
   306  {
   307  static const char * const error_text[] = {
   308  "Success", "Header code incorrect",
   309  "Unknown command or argument", "Incorrect checksum",
   310  "Malformed command", "Timed out", "Unknown error",
   311  };
   312  
   313  if (unlikely(i >= ARRAY_SIZE(error_text)))
   314  i = ARRAY_SIZE(error_text) - 1;
   315  
   316  return error_text[i];
   317  }
   318  

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


.config.gz
Description: application/gzip


Re: [PATCH] iomap: Fix the write_count in iomap_add_to_ioend().

2020-08-20 Thread Ritesh Harjani

Hello Dave,

Thanks for reviewing this.

On 8/21/20 4:41 AM, Dave Chinner wrote:

On Wed, Aug 19, 2020 at 03:58:41PM +0530, Anju T Sudhakar wrote:

From: Ritesh Harjani 

__bio_try_merge_page() may return same_page = 1 and merged = 0.
This could happen when bio->bi_iter.bi_size + len > UINT_MAX.


Ummm, silly question, but exactly how are we getting a bio that
large in ->writepages getting built? Even with 64kB pages, that's a
bio with 2^16 pages attached to it. We shouldn't be building single
bios in writeback that large - what storage hardware is allowing
such huge bios to be built? (i.e. can you dump all the values in
/sys/block//queue/* for that device for us?)


Please correct me here, but as I see, bio has only these two limits
which it checks for adding page to bio. It doesn't check for limits
of /sys/block//queue/* no? I guess then it could be checked
by block layer below b4 submitting the bio?

113 static inline bool bio_full(struct bio *bio, unsigned len)
114 {
115 if (bio->bi_vcnt >= bio->bi_max_vecs)
116 return true;
117
118 if (bio->bi_iter.bi_size > UINT_MAX - len)
119 return true;
120
121 return false;
122 }


This issue was first observed while running a fio run on a system with
huge memory. But then here is an easy way we figured out to trigger the
issue almost everytime with loop device on my VM setup. I have provided
all the details on this below.


===
echo  > /proc/sys/vm/dirtytime_expire_seconds
echo  > /proc/sys/vm/dirty_expire_centisecs
echo 90  > /proc/sys/vm/dirty_rati0
echo 90  > /proc/sys/vm/dirty_background_ratio
echo 0  > /proc/sys/vm/dirty_writeback_centisecs

sudo perf probe -s ~/host_shared/src/linux/ -a '__bio_try_merge_page:10 
bio page page->index bio->bi_iter.bi_size len same_page[0]'


sudo perf record -e probe:__bio_try_merge_page_L10 -a --filter 'bi_size 
> 0xff00' sudo fio --rw=write --bs=1M --numjobs=1 
--name=/mnt/testfile --size=24G --ioengine=libaio



# on running this 2nd time it gets hit everytime on my setup

sudo perf record -e probe:__bio_try_merge_page_L10 -a --filter 'bi_size 
> 0xff00' sudo fio --rw=write --bs=1M --numjobs=1 
--name=/mnt/testfile --size=24G --ioengine=libaio



Perf o/p from above filter causing overflow
===
<...>
 fio 25194 [029] 70471.559084: 
probe:__bio_try_merge_page_L10: (c0aa054c) 
bio=0xc013d49a4b80 page=0xc00c04029d80 index=0x10a9d 
bi_size=0x8000 len=0x1000 same_page=0x1
 fio 25194 [029] 70471.559087: 
probe:__bio_try_merge_page_L10: (c0aa054c) 
bio=0xc013d49a4b80 page=0xc00c04029d80 index=0x10a9d 
bi_size=0x9000 len=0x1000 same_page=0x1
 fio 25194 [029] 70471.559090: 
probe:__bio_try_merge_page_L10: (c0aa054c) 
bio=0xc013d49a4b80 page=0xc00c04029d80 index=0x10a9d 
bi_size=0xa000 len=0x1000 same_page=0x1
 fio 25194 [029] 70471.559093: 
probe:__bio_try_merge_page_L10: (c0aa054c) 
bio=0xc013d49a4b80 page=0xc00c04029d80 index=0x10a9d 
bi_size=0xb000 len=0x1000 same_page=0x1
 fio 25194 [029] 70471.559095: 
probe:__bio_try_merge_page_L10: (c0aa054c) 
bio=0xc013d49a4b80 page=0xc00c04029d80 index=0x10a9d 
bi_size=0xc000 len=0x1000 same_page=0x1
 fio 25194 [029] 70471.559098: 
probe:__bio_try_merge_page_L10: (c0aa054c) 
bio=0xc013d49a4b80 page=0xc00c04029d80 index=0x10a9d 
bi_size=0xd000 len=0x1000 same_page=0x1
 fio 25194 [029] 70471.559101: 
probe:__bio_try_merge_page_L10: (c0aa054c) 
bio=0xc013d49a4b80 page=0xc00c04029d80 index=0x10a9d 
bi_size=0xe000 len=0x1000 same_page=0x1
 fio 25194 [029] 70471.559104: 
probe:__bio_try_merge_page_L10: (c0aa054c) 
bio=0xc013d49a4b80 page=0xc00c04029d80 index=0x10a9d 
bi_size=0xf000 len=0x1000 same_page=0x1


^^ (this could cause an overflow)

loop dev
=
NAME   SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILEDIO LOG-SEC
/dev/loop1 0  0 0  0 /mnt1/filefs   0 512


mount o/p
=
/dev/loop1 on /mnt type xfs 
(rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)



/sys/block//queue/*


setup:/run/perf$ cat /sys/block/loop1/queue/max_segments
128
setup:/run/perf$ cat /sys/block/loop1/queue/max_segment_size
65536
setup:/run/perf$ cat /sys/block/loop1/queue/max_hw_sectors_kb
1280
setup:/run/perf$ cat /sys/block/loop1/queue/logical_block_size
512
setup:/run/perf$ cat /sys/block/loop1/queue/max_sectors_kb
1280
setup:/run/perf$ cat /sys/block/loop1/queue/hw_sector_size
512
setup:/run/perf$ cat /sys/block/loop1/queue/discard_max_bytes
4294966784
setup:/run/perf$ cat /sys/block/loop1/queue/discard_max_hw_bytes
4294966784
setup:/run/perf$ cat /sys/block/loop1/queue/discard_zeroes_data
0
setup:/run/perf$ cat 

[PATCH v5 8/8] mm/vmalloc: Hugepage vmalloc mappings

2020-08-20 Thread Nicholas Piggin
On platforms that define HAVE_ARCH_HUGE_VMAP and support PMD vmaps,
vmalloc will attempt to allocate PMD-sized pages first, before falling
back to small pages.

Allocations which use something other than PAGE_KERNEL protections are
not permitted to use huge pages yet, not all callers expect this (e.g.,
module allocations vs strict module rwx).

This reduces TLB misses by nearly 30x on a `git diff` workload on a
2-node POWER9 (59,800 -> 2,100) and reduces CPU cycles by 0.54%.

This can result in more internal fragmentation and memory overhead for a
given allocation, an option nohugevmalloc is added to disable at boot.

Signed-off-by: Nicholas Piggin 
---
 .../admin-guide/kernel-parameters.txt |   2 +
 arch/Kconfig  |   4 +
 arch/powerpc/Kconfig  |   1 +
 include/linux/vmalloc.h   |   1 +
 mm/page_alloc.c   |   4 +-
 mm/vmalloc.c  | 188 +-
 6 files changed, 152 insertions(+), 48 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt 
b/Documentation/admin-guide/kernel-parameters.txt
index bdc1f33fd3d1..6f0b41289a90 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -3190,6 +3190,8 @@
 
nohugeiomap [KNL,X86,PPC] Disable kernel huge I/O mappings.
 
+   nohugevmalloc   [PPC] Disable kernel huge vmalloc mappings.
+
nosmt   [KNL,S390] Disable symmetric multithreading (SMT).
Equivalent to smt=1.
 
diff --git a/arch/Kconfig b/arch/Kconfig
index af14a567b493..b2b89d629317 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -616,6 +616,10 @@ config HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
 config HAVE_ARCH_HUGE_VMAP
bool
 
+config HAVE_ARCH_HUGE_VMALLOC
+   depends on HAVE_ARCH_HUGE_VMAP
+   bool
+
 config ARCH_WANT_HUGE_PMD_SHARE
bool
 
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 95dfd8ef3d4b..044e5a94967a 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -175,6 +175,7 @@ config PPC
select GENERIC_TIME_VSYSCALL
select HAVE_ARCH_AUDITSYSCALL
select HAVE_ARCH_HUGE_VMAP  if PPC_BOOK3S_64 && 
PPC_RADIX_MMU
+   select HAVE_ARCH_HUGE_VMALLOC   if HAVE_ARCH_HUGE_VMAP
select HAVE_ARCH_JUMP_LABEL
select HAVE_ARCH_KASAN  if PPC32 && PPC_PAGE_SHIFT <= 14
select HAVE_ARCH_KASAN_VMALLOC  if PPC32 && PPC_PAGE_SHIFT <= 14
diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index e3590e93bfff..8f25dbaca0a1 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -58,6 +58,7 @@ struct vm_struct {
unsigned long   size;
unsigned long   flags;
struct page **pages;
+   unsigned intpage_order;
unsigned intnr_pages;
phys_addr_t phys_addr;
const void  *caller;
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 0e2bab486fea..d785e5335529 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -8102,6 +8102,7 @@ void *__init alloc_large_system_hash(const char 
*tablename,
void *table = NULL;
gfp_t gfp_flags;
bool virt;
+   bool huge;
 
/* allow the kernel cmdline to have a say */
if (!numentries) {
@@ -8169,6 +8170,7 @@ void *__init alloc_large_system_hash(const char 
*tablename,
} else if (get_order(size) >= MAX_ORDER || hashdist) {
table = __vmalloc(size, gfp_flags);
virt = true;
+   huge = (find_vm_area(table)->page_order > 0);
} else {
/*
 * If bucketsize is not a power-of-two, we may free
@@ -8185,7 +8187,7 @@ void *__init alloc_large_system_hash(const char 
*tablename,
 
pr_info("%s hash table entries: %ld (order: %d, %lu bytes, %s)\n",
tablename, 1UL << log2qty, ilog2(size) - PAGE_SHIFT, size,
-   virt ? "vmalloc" : "linear");
+   virt ? (huge ? "vmalloc hugepage" : "vmalloc") : "linear");
 
if (_hash_shift)
*_hash_shift = log2qty;
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 4e5cb7c7f780..564d7497e551 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -45,6 +45,19 @@
 #include "internal.h"
 #include "pgalloc-track.h"
 
+#ifdef CONFIG_HAVE_ARCH_HUGE_VMALLOC
+static bool __ro_after_init vmap_allow_huge = true;
+
+static int __init set_nohugevmalloc(char *str)
+{
+   vmap_allow_huge = false;
+   return 0;
+}
+early_param("nohugevmalloc", set_nohugevmalloc);
+#else /* CONFIG_HAVE_ARCH_HUGE_VMALLOC */
+static const bool vmap_allow_huge = false;
+#endif /* CONFIG_HAVE_ARCH_HUGE_VMALLOC */
+
 bool is_vmalloc_addr(const void *x)
 {
unsigned long addr = (unsigned long)x;
@@ -468,31 

[PATCH v5 5/8] mm: HUGE_VMAP arch support cleanup

2020-08-20 Thread Nicholas Piggin
This changes the awkward approach where architectures provide init
functions to determine which levels they can provide large mappings for,
to one where the arch is queried for each call.

This removes code and indirection, and allows constant-folding of dead
code for unsupported levels.

This also adds a prot argument to the arch query. This is unused
currently but could help with some architectures (e.g., some powerpc
processors can't map uncacheable memory with large pages).

Signed-off-by: Nicholas Piggin 
---
 arch/arm64/mm/mmu.c  | 12 +--
 arch/powerpc/mm/book3s64/radix_pgtable.c | 10 ++-
 arch/x86/mm/ioremap.c| 12 +--
 include/linux/io.h   |  9 ---
 include/linux/vmalloc.h  | 10 +++
 init/main.c  |  1 -
 mm/ioremap.c | 96 +++-
 7 files changed, 73 insertions(+), 77 deletions(-)

diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index 75df62fea1b6..bbb3ccf6a7ce 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -1304,12 +1304,13 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int 
*size, pgprot_t prot)
return dt_virt;
 }
 
-int __init arch_ioremap_p4d_supported(void)
+#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
+bool arch_vmap_p4d_supported(pgprot_t prot)
 {
-   return 0;
+   return false;
 }
 
-int __init arch_ioremap_pud_supported(void)
+bool arch_vmap_pud_supported(pgprot_t prot)
 {
/*
 * Only 4k granule supports level 1 block mappings.
@@ -1319,11 +1320,12 @@ int __init arch_ioremap_pud_supported(void)
   !IS_ENABLED(CONFIG_PTDUMP_DEBUGFS);
 }
 
-int __init arch_ioremap_pmd_supported(void)
+bool arch_vmap_pmd_supported(pgprot_t prot)
 {
-   /* See arch_ioremap_pud_supported() */
+   /* See arch_vmap_pud_supported() */
return !IS_ENABLED(CONFIG_PTDUMP_DEBUGFS);
 }
+#endif
 
 int pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot)
 {
diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c 
b/arch/powerpc/mm/book3s64/radix_pgtable.c
index ae823bba29f2..7d3a620c5adf 100644
--- a/arch/powerpc/mm/book3s64/radix_pgtable.c
+++ b/arch/powerpc/mm/book3s64/radix_pgtable.c
@@ -1182,13 +1182,14 @@ void radix__ptep_modify_prot_commit(struct 
vm_area_struct *vma,
set_pte_at(mm, addr, ptep, pte);
 }
 
-int __init arch_ioremap_pud_supported(void)
+#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
+bool arch_vmap_pud_supported(pgprot_t prot)
 {
/* HPT does not cope with large pages in the vmalloc area */
return radix_enabled();
 }
 
-int __init arch_ioremap_pmd_supported(void)
+bool arch_vmap_pmd_supported(pgprot_t prot)
 {
return radix_enabled();
 }
@@ -1197,6 +1198,7 @@ int p4d_free_pud_page(p4d_t *p4d, unsigned long addr)
 {
return 0;
 }
+#endif
 
 int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot)
 {
@@ -1282,7 +1284,7 @@ int pmd_free_pte_page(pmd_t *pmd, unsigned long addr)
return 1;
 }
 
-int __init arch_ioremap_p4d_supported(void)
+bool arch_vmap_p4d_supported(pgprot_t prot)
 {
-   return 0;
+   return false;
 }
diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index 84d85dbd1dad..5b8b495ab4ed 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -481,24 +481,26 @@ void iounmap(volatile void __iomem *addr)
 }
 EXPORT_SYMBOL(iounmap);
 
-int __init arch_ioremap_p4d_supported(void)
+#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
+bool arch_vmap_p4d_supported(pgprot_t prot)
 {
-   return 0;
+   return false;
 }
 
-int __init arch_ioremap_pud_supported(void)
+bool arch_vmap_pud_supported(pgprot_t prot)
 {
 #ifdef CONFIG_X86_64
return boot_cpu_has(X86_FEATURE_GBPAGES);
 #else
-   return 0;
+   return false;
 #endif
 }
 
-int __init arch_ioremap_pmd_supported(void)
+bool arch_vmap_pmd_supported(pgprot_t prot)
 {
return boot_cpu_has(X86_FEATURE_PSE);
 }
+#endif
 
 /*
  * Convert a physical pointer to a virtual kernel pointer for /dev/mem
diff --git a/include/linux/io.h b/include/linux/io.h
index 8394c56babc2..f1effd4d7a3c 100644
--- a/include/linux/io.h
+++ b/include/linux/io.h
@@ -31,15 +31,6 @@ static inline int ioremap_page_range(unsigned long addr, 
unsigned long end,
 }
 #endif
 
-#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
-void __init ioremap_huge_init(void);
-int arch_ioremap_p4d_supported(void);
-int arch_ioremap_pud_supported(void);
-int arch_ioremap_pmd_supported(void);
-#else
-static inline void ioremap_huge_init(void) { }
-#endif
-
 /*
  * Managed iomap interface
  */
diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index 0221f852a7e1..787d77ad7536 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -84,6 +84,16 @@ struct vmap_area {
};
 };
 
+#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
+bool arch_vmap_p4d_supported(pgprot_t prot);
+bool arch_vmap_pud_supported(pgprot_t prot);
+bool arch_vmap_pmd_supported(pgprot_t prot);
+#else
+static inline bool 

[PATCH v5 4/8] lib/ioremap: rename ioremap_*_range to vmap_*_range

2020-08-20 Thread Nicholas Piggin
This will be moved to mm/ and used as a generic kernel virtual mapping
function, so re-name it in preparation.

Signed-off-by: Nicholas Piggin 
---
 mm/ioremap.c | 55 ++--
 1 file changed, 23 insertions(+), 32 deletions(-)

diff --git a/mm/ioremap.c b/mm/ioremap.c
index 5fa1ab41d152..6016ae3227ad 100644
--- a/mm/ioremap.c
+++ b/mm/ioremap.c
@@ -61,9 +61,8 @@ static inline int ioremap_pud_enabled(void) { return 0; }
 static inline int ioremap_pmd_enabled(void) { return 0; }
 #endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */
 
-static int ioremap_pte_range(pmd_t *pmd, unsigned long addr,
-   unsigned long end, phys_addr_t phys_addr, pgprot_t prot,
-   pgtbl_mod_mask *mask)
+static int vmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
+   phys_addr_t phys_addr, pgprot_t prot, pgtbl_mod_mask 
*mask)
 {
pte_t *pte;
u64 pfn;
@@ -81,9 +80,8 @@ static int ioremap_pte_range(pmd_t *pmd, unsigned long addr,
return 0;
 }
 
-static int ioremap_try_huge_pmd(pmd_t *pmd, unsigned long addr,
-   unsigned long end, phys_addr_t phys_addr,
-   pgprot_t prot)
+static int vmap_try_huge_pmd(pmd_t *pmd, unsigned long addr, unsigned long end,
+   phys_addr_t phys_addr, pgprot_t prot)
 {
if (!ioremap_pmd_enabled())
return 0;
@@ -103,9 +101,8 @@ static int ioremap_try_huge_pmd(pmd_t *pmd, unsigned long 
addr,
return pmd_set_huge(pmd, phys_addr, prot);
 }
 
-static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
-   unsigned long end, phys_addr_t phys_addr, pgprot_t prot,
-   pgtbl_mod_mask *mask)
+static int vmap_pmd_range(pud_t *pud, unsigned long addr, unsigned long end,
+   phys_addr_t phys_addr, pgprot_t prot, pgtbl_mod_mask 
*mask)
 {
pmd_t *pmd;
unsigned long next;
@@ -116,20 +113,19 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned 
long addr,
do {
next = pmd_addr_end(addr, end);
 
-   if (ioremap_try_huge_pmd(pmd, addr, next, phys_addr, prot)) {
+   if (vmap_try_huge_pmd(pmd, addr, next, phys_addr, prot)) {
*mask |= PGTBL_PMD_MODIFIED;
continue;
}
 
-   if (ioremap_pte_range(pmd, addr, next, phys_addr, prot, mask))
+   if (vmap_pte_range(pmd, addr, next, phys_addr, prot, mask))
return -ENOMEM;
} while (pmd++, phys_addr += (next - addr), addr = next, addr != end);
return 0;
 }
 
-static int ioremap_try_huge_pud(pud_t *pud, unsigned long addr,
-   unsigned long end, phys_addr_t phys_addr,
-   pgprot_t prot)
+static int vmap_try_huge_pud(pud_t *pud, unsigned long addr, unsigned long end,
+   phys_addr_t phys_addr, pgprot_t prot)
 {
if (!ioremap_pud_enabled())
return 0;
@@ -149,9 +145,8 @@ static int ioremap_try_huge_pud(pud_t *pud, unsigned long 
addr,
return pud_set_huge(pud, phys_addr, prot);
 }
 
-static inline int ioremap_pud_range(p4d_t *p4d, unsigned long addr,
-   unsigned long end, phys_addr_t phys_addr, pgprot_t prot,
-   pgtbl_mod_mask *mask)
+static int vmap_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end,
+   phys_addr_t phys_addr, pgprot_t prot, pgtbl_mod_mask 
*mask)
 {
pud_t *pud;
unsigned long next;
@@ -162,20 +157,19 @@ static inline int ioremap_pud_range(p4d_t *p4d, unsigned 
long addr,
do {
next = pud_addr_end(addr, end);
 
-   if (ioremap_try_huge_pud(pud, addr, next, phys_addr, prot)) {
+   if (vmap_try_huge_pud(pud, addr, next, phys_addr, prot)) {
*mask |= PGTBL_PUD_MODIFIED;
continue;
}
 
-   if (ioremap_pmd_range(pud, addr, next, phys_addr, prot, mask))
+   if (vmap_pmd_range(pud, addr, next, phys_addr, prot, mask))
return -ENOMEM;
} while (pud++, phys_addr += (next - addr), addr = next, addr != end);
return 0;
 }
 
-static int ioremap_try_huge_p4d(p4d_t *p4d, unsigned long addr,
-   unsigned long end, phys_addr_t phys_addr,
-   pgprot_t prot)
+static int vmap_try_huge_p4d(p4d_t *p4d, unsigned long addr, unsigned long end,
+   phys_addr_t phys_addr, pgprot_t prot)
 {
if (!ioremap_p4d_enabled())
return 0;
@@ -195,9 +189,8 @@ static int ioremap_try_huge_p4d(p4d_t *p4d, unsigned long 
addr,
return p4d_set_huge(p4d, phys_addr, prot);
 }
 
-static inline int ioremap_p4d_range(pgd_t *pgd, unsigned long addr,
-   unsigned long end, phys_addr_t phys_addr, pgprot_t 

[PATCH v5 3/8] mm/vmalloc: rename vmap_*_range vmap_pages_*_range

2020-08-20 Thread Nicholas Piggin
The vmalloc mapper operates on a struct page * array rather than a
linear physical address, re-name it to make this distinction clear.

Signed-off-by: Nicholas Piggin 
---
 mm/vmalloc.c | 28 
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 49f225b0f855..3a1e45fd1626 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -190,9 +190,8 @@ void unmap_kernel_range_noflush(unsigned long start, 
unsigned long size)
arch_sync_kernel_mappings(start, end);
 }
 
-static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
-   unsigned long end, pgprot_t prot, struct page **pages, int *nr,
-   pgtbl_mod_mask *mask)
+static int vmap_pages_pte_range(pmd_t *pmd, unsigned long addr, unsigned long 
end,
+   pgprot_t prot, struct page **pages, int *nr, pgtbl_mod_mask 
*mask)
 {
pte_t *pte;
 
@@ -218,9 +217,8 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
return 0;
 }
 
-static int vmap_pmd_range(pud_t *pud, unsigned long addr,
-   unsigned long end, pgprot_t prot, struct page **pages, int *nr,
-   pgtbl_mod_mask *mask)
+static int vmap_pages_pmd_range(pud_t *pud, unsigned long addr, unsigned long 
end,
+   pgprot_t prot, struct page **pages, int *nr, pgtbl_mod_mask 
*mask)
 {
pmd_t *pmd;
unsigned long next;
@@ -230,15 +228,14 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
return -ENOMEM;
do {
next = pmd_addr_end(addr, end);
-   if (vmap_pte_range(pmd, addr, next, prot, pages, nr, mask))
+   if (vmap_pages_pte_range(pmd, addr, next, prot, pages, nr, 
mask))
return -ENOMEM;
} while (pmd++, addr = next, addr != end);
return 0;
 }
 
-static int vmap_pud_range(p4d_t *p4d, unsigned long addr,
-   unsigned long end, pgprot_t prot, struct page **pages, int *nr,
-   pgtbl_mod_mask *mask)
+static int vmap_pages_pud_range(p4d_t *p4d, unsigned long addr, unsigned long 
end,
+   pgprot_t prot, struct page **pages, int *nr, pgtbl_mod_mask 
*mask)
 {
pud_t *pud;
unsigned long next;
@@ -248,15 +245,14 @@ static int vmap_pud_range(p4d_t *p4d, unsigned long addr,
return -ENOMEM;
do {
next = pud_addr_end(addr, end);
-   if (vmap_pmd_range(pud, addr, next, prot, pages, nr, mask))
+   if (vmap_pages_pmd_range(pud, addr, next, prot, pages, nr, 
mask))
return -ENOMEM;
} while (pud++, addr = next, addr != end);
return 0;
 }
 
-static int vmap_p4d_range(pgd_t *pgd, unsigned long addr,
-   unsigned long end, pgprot_t prot, struct page **pages, int *nr,
-   pgtbl_mod_mask *mask)
+static int vmap_pages_p4d_range(pgd_t *pgd, unsigned long addr, unsigned long 
end,
+   pgprot_t prot, struct page **pages, int *nr, pgtbl_mod_mask 
*mask)
 {
p4d_t *p4d;
unsigned long next;
@@ -266,7 +262,7 @@ static int vmap_p4d_range(pgd_t *pgd, unsigned long addr,
return -ENOMEM;
do {
next = p4d_addr_end(addr, end);
-   if (vmap_pud_range(p4d, addr, next, prot, pages, nr, mask))
+   if (vmap_pages_pud_range(p4d, addr, next, prot, pages, nr, 
mask))
return -ENOMEM;
} while (p4d++, addr = next, addr != end);
return 0;
@@ -307,7 +303,7 @@ int map_kernel_range_noflush(unsigned long addr, unsigned 
long size,
next = pgd_addr_end(addr, end);
if (pgd_bad(*pgd))
mask |= PGTBL_PGD_MODIFIED;
-   err = vmap_p4d_range(pgd, addr, next, prot, pages, , );
+   err = vmap_pages_p4d_range(pgd, addr, next, prot, pages, , 
);
if (err)
return err;
} while (pgd++, addr = next, addr != end);
-- 
2.23.0



[PATCH v5 6/8] mm: Move vmap_range from lib/ioremap.c to mm/vmalloc.c

2020-08-20 Thread Nicholas Piggin
This is a generic kernel virtual memory mapper, not specific to ioremap.

Signed-off-by: Nicholas Piggin 
---
 include/linux/vmalloc.h |   2 +
 mm/ioremap.c| 192 
 mm/vmalloc.c| 191 +++
 3 files changed, 193 insertions(+), 192 deletions(-)

diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index 787d77ad7536..e3590e93bfff 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -181,6 +181,8 @@ extern struct vm_struct *remove_vm_area(const void *addr);
 extern struct vm_struct *find_vm_area(const void *addr);
 
 #ifdef CONFIG_MMU
+extern int vmap_range(unsigned long addr, unsigned long end, phys_addr_t 
phys_addr, pgprot_t prot,
+   unsigned int max_page_shift);
 extern int map_kernel_range_noflush(unsigned long start, unsigned long size,
pgprot_t prot, struct page **pages);
 int map_kernel_range(unsigned long start, unsigned long size, pgprot_t prot,
diff --git a/mm/ioremap.c b/mm/ioremap.c
index b0032dbadaf7..cdda0e022740 100644
--- a/mm/ioremap.c
+++ b/mm/ioremap.c
@@ -28,198 +28,6 @@ early_param("nohugeiomap", set_nohugeiomap);
 static const bool iomap_allow_huge = false;
 #endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */
 
-static int vmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
-   phys_addr_t phys_addr, pgprot_t prot, pgtbl_mod_mask 
*mask)
-{
-   pte_t *pte;
-   u64 pfn;
-
-   pfn = phys_addr >> PAGE_SHIFT;
-   pte = pte_alloc_kernel_track(pmd, addr, mask);
-   if (!pte)
-   return -ENOMEM;
-   do {
-   BUG_ON(!pte_none(*pte));
-   set_pte_at(_mm, addr, pte, pfn_pte(pfn, prot));
-   pfn++;
-   } while (pte++, addr += PAGE_SIZE, addr != end);
-   *mask |= PGTBL_PTE_MODIFIED;
-   return 0;
-}
-
-static int vmap_try_huge_pmd(pmd_t *pmd, unsigned long addr, unsigned long end,
-   phys_addr_t phys_addr, pgprot_t prot, unsigned int 
max_page_shift)
-{
-   if (max_page_shift < PMD_SHIFT)
-   return 0;
-
-   if (!arch_vmap_pmd_supported(prot))
-   return 0;
-
-   if ((end - addr) != PMD_SIZE)
-   return 0;
-
-   if (!IS_ALIGNED(addr, PMD_SIZE))
-   return 0;
-
-   if (!IS_ALIGNED(phys_addr, PMD_SIZE))
-   return 0;
-
-   if (pmd_present(*pmd) && !pmd_free_pte_page(pmd, addr))
-   return 0;
-
-   return pmd_set_huge(pmd, phys_addr, prot);
-}
-
-static int vmap_pmd_range(pud_t *pud, unsigned long addr, unsigned long end,
-   phys_addr_t phys_addr, pgprot_t prot, unsigned int 
max_page_shift,
-   pgtbl_mod_mask *mask)
-{
-   pmd_t *pmd;
-   unsigned long next;
-
-   pmd = pmd_alloc_track(_mm, pud, addr, mask);
-   if (!pmd)
-   return -ENOMEM;
-   do {
-   next = pmd_addr_end(addr, end);
-
-   if (vmap_try_huge_pmd(pmd, addr, next, phys_addr, prot, 
max_page_shift)) {
-   *mask |= PGTBL_PMD_MODIFIED;
-   continue;
-   }
-
-   if (vmap_pte_range(pmd, addr, next, phys_addr, prot, mask))
-   return -ENOMEM;
-   } while (pmd++, phys_addr += (next - addr), addr = next, addr != end);
-   return 0;
-}
-
-static int vmap_try_huge_pud(pud_t *pud, unsigned long addr, unsigned long end,
-   phys_addr_t phys_addr, pgprot_t prot, unsigned int 
max_page_shift)
-{
-   if (max_page_shift < PUD_SHIFT)
-   return 0;
-
-   if (!arch_vmap_pud_supported(prot))
-   return 0;
-
-   if ((end - addr) != PUD_SIZE)
-   return 0;
-
-   if (!IS_ALIGNED(addr, PUD_SIZE))
-   return 0;
-
-   if (!IS_ALIGNED(phys_addr, PUD_SIZE))
-   return 0;
-
-   if (pud_present(*pud) && !pud_free_pmd_page(pud, addr))
-   return 0;
-
-   return pud_set_huge(pud, phys_addr, prot);
-}
-
-static int vmap_pud_range(p4d_t *p4d, unsigned long addr, unsigned long end,
-   phys_addr_t phys_addr, pgprot_t prot, unsigned int 
max_page_shift,
-   pgtbl_mod_mask *mask)
-{
-   pud_t *pud;
-   unsigned long next;
-
-   pud = pud_alloc_track(_mm, p4d, addr, mask);
-   if (!pud)
-   return -ENOMEM;
-   do {
-   next = pud_addr_end(addr, end);
-
-   if (vmap_try_huge_pud(pud, addr, next, phys_addr, prot, 
max_page_shift)) {
-   *mask |= PGTBL_PUD_MODIFIED;
-   continue;
-   }
-
-   if (vmap_pmd_range(pud, addr, next, phys_addr, prot, 
max_page_shift, mask))
-   return -ENOMEM;
-   } while (pud++, phys_addr += (next - addr), addr = next, addr != end);
-   return 0;
-}
-

[PATCH v5 1/8] mm/vmalloc: fix vmalloc_to_page for huge vmap mappings

2020-08-20 Thread Nicholas Piggin
vmalloc_to_page returns NULL for addresses mapped by larger pages[*].
Whether or not a vmap is huge depends on the architecture details,
alignments, boot options, etc., which the caller can not be expected
to know. Therefore HUGE_VMAP is a regression for vmalloc_to_page.

This change teaches vmalloc_to_page about larger pages, and returns
the struct page that corresponds to the offset within the large page.
This makes the API agnostic to mapping implementation details.

[*] As explained by commit 029c54b095995 ("mm/vmalloc.c: huge-vmap:
fail gracefully on unexpected huge vmap mappings")

Signed-off-by: Nicholas Piggin 
---
 mm/vmalloc.c | 40 ++--
 1 file changed, 26 insertions(+), 14 deletions(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index b482d240f9a2..49f225b0f855 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -38,6 +38,7 @@
 #include 
 
 #include 
+#include 
 #include 
 #include 
 
@@ -343,7 +344,9 @@ int is_vmalloc_or_module_addr(const void *x)
 }
 
 /*
- * Walk a vmap address to the struct page it maps.
+ * Walk a vmap address to the struct page it maps. Huge vmap mappings will
+ * return the tail page that corresponds to the base page address, which
+ * matches small vmap mappings.
  */
 struct page *vmalloc_to_page(const void *vmalloc_addr)
 {
@@ -363,25 +366,33 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
 
if (pgd_none(*pgd))
return NULL;
+   if (WARN_ON_ONCE(pgd_leaf(*pgd)))
+   return NULL; /* XXX: no allowance for huge pgd */
+   if (WARN_ON_ONCE(pgd_bad(*pgd)))
+   return NULL;
+
p4d = p4d_offset(pgd, addr);
if (p4d_none(*p4d))
return NULL;
-   pud = pud_offset(p4d, addr);
+   if (p4d_leaf(*p4d))
+   return p4d_page(*p4d) + ((addr & ~P4D_MASK) >> PAGE_SHIFT);
+   if (WARN_ON_ONCE(p4d_bad(*p4d)))
+   return NULL;
 
-   /*
-* Don't dereference bad PUD or PMD (below) entries. This will also
-* identify huge mappings, which we may encounter on architectures
-* that define CONFIG_HAVE_ARCH_HUGE_VMAP=y. Such regions will be
-* identified as vmalloc addresses by is_vmalloc_addr(), but are
-* not [unambiguously] associated with a struct page, so there is
-* no correct value to return for them.
-*/
-   WARN_ON_ONCE(pud_bad(*pud));
-   if (pud_none(*pud) || pud_bad(*pud))
+   pud = pud_offset(p4d, addr);
+   if (pud_none(*pud))
+   return NULL;
+   if (pud_leaf(*pud))
+   return pud_page(*pud) + ((addr & ~PUD_MASK) >> PAGE_SHIFT);
+   if (WARN_ON_ONCE(pud_bad(*pud)))
return NULL;
+
pmd = pmd_offset(pud, addr);
-   WARN_ON_ONCE(pmd_bad(*pmd));
-   if (pmd_none(*pmd) || pmd_bad(*pmd))
+   if (pmd_none(*pmd))
+   return NULL;
+   if (pmd_leaf(*pmd))
+   return pmd_page(*pmd) + ((addr & ~PMD_MASK) >> PAGE_SHIFT);
+   if (WARN_ON_ONCE(pmd_bad(*pmd)))
return NULL;
 
ptep = pte_offset_map(pmd, addr);
@@ -389,6 +400,7 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
if (pte_present(pte))
page = pte_page(pte);
pte_unmap(ptep);
+
return page;
 }
 EXPORT_SYMBOL(vmalloc_to_page);
-- 
2.23.0



[PATCH v5 7/8] mm/vmalloc: add vmap_range_noflush variant

2020-08-20 Thread Nicholas Piggin
As a side-effect, the order of flush_cache_vmap() and
arch_sync_kernel_mappings() calls are switched, but that now matches
the other callers in this file.

Signed-off-by: Nicholas Piggin 
---
 mm/vmalloc.c | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 129f10545bb1..4e5cb7c7f780 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -234,8 +234,8 @@ static int vmap_p4d_range(pgd_t *pgd, unsigned long addr, 
unsigned long end,
return 0;
 }
 
-int vmap_range(unsigned long addr, unsigned long end, phys_addr_t phys_addr, 
pgprot_t prot,
-   unsigned int max_page_shift)
+static int vmap_range_noflush(unsigned long addr, unsigned long end, 
phys_addr_t phys_addr,
+   pgprot_t prot, unsigned int max_page_shift)
 {
pgd_t *pgd;
unsigned long start;
@@ -255,14 +255,23 @@ int vmap_range(unsigned long addr, unsigned long end, 
phys_addr_t phys_addr, pgp
break;
} while (pgd++, phys_addr += (next - addr), addr = next, addr != end);
 
-   flush_cache_vmap(start, end);
-
if (mask & ARCH_PAGE_TABLE_SYNC_MASK)
arch_sync_kernel_mappings(start, end);
 
return err;
 }
 
+int vmap_range(unsigned long addr, unsigned long end, phys_addr_t phys_addr, 
pgprot_t prot,
+   unsigned int max_page_shift)
+{
+   int err;
+
+   err = vmap_range_noflush(addr, end, phys_addr, prot, max_page_shift);
+   flush_cache_vmap(addr, end);
+
+   return err;
+}
+
 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
 pgtbl_mod_mask *mask)
 {
-- 
2.23.0



[PATCH v5 0/8] huge vmalloc mappings

2020-08-20 Thread Nicholas Piggin
I made this powerpc-only for the time being. It shouldn't be too hard to
add support for other archs that define HUGE_VMAP. I have booted x86
with it enabled, just may not have audited everything.

Hi Andrew, would you care to put this in your tree?

Thanks,
Nick

Since v4:
- Fixed an off-by-page-order bug in v4
- Several minor cleanups.
- Added page order to /proc/vmallocinfo
- Added hugepage to alloc_large_system_hage output.
- Made an architecture config option, powerpc only for now.

Since v3:
- Fixed an off-by-one bug in a loop
- Fix !CONFIG_HAVE_ARCH_HUGE_VMAP build fail
- Hopefully this time fix the arm64 vmap stack bug, thanks Jonathan
  Cameron for debugging the cause of this (hopefully).

Since v2:
- Rebased on vmalloc cleanups, split series into simpler pieces.
- Fixed several compile errors and warnings
- Keep the page array and accounting in small page units because
  struct vm_struct is an interface (this should fix x86 vmap stack debug
  assert). [Thanks Zefan]

Nicholas Piggin (8):
  mm/vmalloc: fix vmalloc_to_page for huge vmap mappings
  mm: apply_to_pte_range warn and fail if a large pte is encountered
  mm/vmalloc: rename vmap_*_range vmap_pages_*_range
  lib/ioremap: rename ioremap_*_range to vmap_*_range
  mm: HUGE_VMAP arch support cleanup
  mm: Move vmap_range from lib/ioremap.c to mm/vmalloc.c
  mm/vmalloc: add vmap_range_noflush variant
  mm/vmalloc: Hugepage vmalloc mappings

 .../admin-guide/kernel-parameters.txt |   2 +
 arch/Kconfig  |   4 +
 arch/arm64/mm/mmu.c   |  12 +-
 arch/powerpc/Kconfig  |   1 +
 arch/powerpc/mm/book3s64/radix_pgtable.c  |  10 +-
 arch/x86/mm/ioremap.c |  12 +-
 include/linux/io.h|   9 -
 include/linux/vmalloc.h   |  13 +
 init/main.c   |   1 -
 mm/ioremap.c  | 231 +
 mm/memory.c   |  60 ++-
 mm/page_alloc.c   |   4 +-
 mm/vmalloc.c  | 456 +++---
 13 files changed, 476 insertions(+), 339 deletions(-)

-- 
2.23.0



[PATCH v5 2/8] mm: apply_to_pte_range warn and fail if a large pte is encountered

2020-08-20 Thread Nicholas Piggin
Signed-off-by: Nicholas Piggin 
---
 mm/memory.c | 60 +++--
 1 file changed, 44 insertions(+), 16 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index f95edbb77326..19986af291e0 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2261,13 +2261,20 @@ static int apply_to_pmd_range(struct mm_struct *mm, 
pud_t *pud,
}
do {
next = pmd_addr_end(addr, end);
-   if (create || !pmd_none_or_clear_bad(pmd)) {
-   err = apply_to_pte_range(mm, pmd, addr, next, fn, data,
-create);
-   if (err)
-   break;
+   if (pmd_none(*pmd) && !create)
+   continue;
+   if (WARN_ON_ONCE(pmd_leaf(*pmd)))
+   return -EINVAL;
+   if (WARN_ON_ONCE(pmd_bad(*pmd))) {
+   if (!create)
+   continue;
+   pmd_clear_bad(pmd);
}
+   err = apply_to_pte_range(mm, pmd, addr, next, fn, data, create);
+   if (err)
+   break;
} while (pmd++, addr = next, addr != end);
+
return err;
 }
 
@@ -2288,13 +2295,20 @@ static int apply_to_pud_range(struct mm_struct *mm, 
p4d_t *p4d,
}
do {
next = pud_addr_end(addr, end);
-   if (create || !pud_none_or_clear_bad(pud)) {
-   err = apply_to_pmd_range(mm, pud, addr, next, fn, data,
-create);
-   if (err)
-   break;
+   if (pud_none(*pud) && !create)
+   continue;
+   if (WARN_ON_ONCE(pud_leaf(*pud)))
+   return -EINVAL;
+   if (WARN_ON_ONCE(pud_bad(*pud))) {
+   if (!create)
+   continue;
+   pud_clear_bad(pud);
}
+   err = apply_to_pmd_range(mm, pud, addr, next, fn, data, create);
+   if (err)
+   break;
} while (pud++, addr = next, addr != end);
+
return err;
 }
 
@@ -2315,13 +2329,20 @@ static int apply_to_p4d_range(struct mm_struct *mm, 
pgd_t *pgd,
}
do {
next = p4d_addr_end(addr, end);
-   if (create || !p4d_none_or_clear_bad(p4d)) {
-   err = apply_to_pud_range(mm, p4d, addr, next, fn, data,
-create);
-   if (err)
-   break;
+   if (p4d_none(*p4d) && !create)
+   continue;
+   if (WARN_ON_ONCE(p4d_leaf(*p4d)))
+   return -EINVAL;
+   if (WARN_ON_ONCE(p4d_bad(*p4d))) {
+   if (!create)
+   continue;
+   p4d_clear_bad(p4d);
}
+   err = apply_to_pud_range(mm, p4d, addr, next, fn, data, create);
+   if (err)
+   break;
} while (p4d++, addr = next, addr != end);
+
return err;
 }
 
@@ -2340,8 +2361,15 @@ static int __apply_to_page_range(struct mm_struct *mm, 
unsigned long addr,
pgd = pgd_offset(mm, addr);
do {
next = pgd_addr_end(addr, end);
-   if (!create && pgd_none_or_clear_bad(pgd))
+   if (pgd_none(*pgd) && !create)
continue;
+   if (WARN_ON_ONCE(pgd_leaf(*pgd)))
+   return -EINVAL;
+   if (WARN_ON_ONCE(pgd_bad(*pgd))) {
+   if (!create)
+   continue;
+   pgd_clear_bad(pgd);
+   }
err = apply_to_p4d_range(mm, pgd, addr, next, fn, data, create);
if (err)
break;
-- 
2.23.0



Re: [PATCH 1/1] mm, oom_adj: don't loop through tasks in __set_oom_adj when not necessary

2020-08-20 Thread Eric W. Biederman
Michal Hocko  writes:

> On Thu 20-08-20 08:56:53, Suren Baghdasaryan wrote:
> [...]
>> Catching up on the discussion which was going on while I was asleep...
>> So it sounds like there is a consensus that oom_adj should be moved to
>> mm_struct rather than trying to synchronize it among tasks sharing mm.
>> That sounds reasonable to me too. Michal answered all the earlier
>> questions about this patch, so I won't be reiterating them, thanks
>> Michal. If any questions are still lingering about the original patch
>> I'll be glad to answer them.
>
> I think it still makes some sense to go with a simpler (aka less tricky)
> solution which would be your original patch with an incremental fix for
> vfork and the proper ordering 
> (http://lkml.kernel.org/r/20200820124109.gi5...@dhcp22.suse.cz)
> and then make a more complex shift to mm struct on top of that. The
> former will be less tricky to backport to stable IMHO.

So I am confused.

I don't know how a subtle dependency on something in clone
is better than something flat footed in exec.


That said if we are going for a small change why not:

/*
 * Make sure we will check other processes sharing the mm if this is
 * not vfrok which wants its own oom_score_adj.
 * pin the mm so it doesn't go away and get reused after task_unlock
 */
if (!task->vfork_done) {
struct task_struct *p = find_lock_task_mm(task);

if (p) {
-   if (atomic_read(>mm->mm_users) > 1) {
+   if (atomic_read(>mm->mm_users) > 
p->signal->nr_threads) {
mm = p->mm;
mmgrab(mm);
}
task_unlock(p);
}
}

That would seem to be the minimal change to make this happen.  That has
the advantage that if a processes does vfork it won't always have to
take the slow path.

Moving to the mm_struct is much less racy but this is simple.

Eric


[REGRESSION] x86/cpu fsgsbase breaks TLS in 32 bit rr tracees on a 64 bit system

2020-08-20 Thread Kyle Huey
On the x86-64 5.9-rc1 TLS is completely broken in 32 bit tracees when
running under rr[0]. Booting the kernel with `nofsgsbase` fixes it and
I bisected to 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v5.8=673903495c85137791d5820d690229efe09c8f7b.

STR:
1. Build rr from source by
  a. git clone https://github.com/mozilla/rr
  b. mkdir rr/obj
  c. cd rr/obj
  d. cmake ..
  e. make -j16
2. Run the simple 32 bit tracee outside of rr with `./bin/simple_32`.
It should print a message and exit cleanly.
3. Run it under rr with `./bin/rr ./bin/simple_32`.

It should behave the same way, but with fsgsbase enabled it will
segfault. The `simple_32` binary is a simple "hello world" type
program but it does link to pthreads, so pre-main code attempts to
access TLS variables.

The interplay between 32 bit and 64 bit TLS is dark magic to me
unfortunately so this is all the useful information I have.

- Kyle

[0] https://rr-project.org/


Re: pcm|dmaengine|imx-sdma race condition on i.MX6

2020-08-20 Thread Richard Leitner
On Thu, Aug 20, 2020 at 03:01:44PM +, Robin Gong wrote:
> On 2020/08/19 22:26 Benjamin Bara - SKIDATA  
> wrote: 
> > 
> > @Robin:
> > Is it possible to tag the commits for the stable-tree
> > Cc: sta...@vger.kernel.org?
> Could my patch work in your side? If yes, I will add
> Cc: sta...@vger.kernel.org 

I've tested the patches 3 & 4 (removing sdmac->context_loaded) of the
series you mentioned and sent Tested-by tags for them [1,2], as they
fix the EIO problems for our use case.

So from our side they are fine for stable.

[1] https://lore.kernel.org/dmaengine/20200817053813.GA551027@pcleri/T/#u
[2] https://lore.kernel.org/dmaengine/20200817053820.GB551027@pcleri/T/#u

regards;rl


RE: [PATCH] mm/gup_benchmark: update the documentation in Kconfig

2020-08-20 Thread Song Bao Hua (Barry Song)


> -Original Message-
> From: linux-kselftest-ow...@vger.kernel.org
> [mailto:linux-kselftest-ow...@vger.kernel.org] On Behalf Of John Hubbard
> Sent: Friday, August 21, 2020 3:51 PM
> To: Song Bao Hua (Barry Song) ;
> a...@linux-foundation.org; linux...@kvack.org;
> linux-kselft...@vger.kernel.org
> Cc: Linuxarm ; linux-kernel@vger.kernel.org; Keith
> Busch ; Ira Weiny ; Kirill A .
> Shutemov 
> Subject: Re: [PATCH] mm/gup_benchmark: update the documentation in
> Kconfig
> 
> On 8/20/20 8:25 PM, Barry Song wrote:
> > In the beginning, mm/gup_benchmark.c supported get_user_pages_fast()
> > only, but right now, it supports the benchmarking of a couple of
> > get_user_pages() related calls like:
> > * get_user_pages_fast()
> > * get_user_pages()
> > * pin_user_pages_fast()
> > * pin_user_pages()
> > The documentation is confusing and needs update.
> 
> hmmm, it's not that confusing, given that pin_user_pages() and
> get_user_pages() use the same underlying get_user_pages()
> implementation.

get_user_pages_fast() is not get_user_pages(). It is a specific function :-)

In the beginning, gup_benchmark was only for get_user_pages_fast():
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/mm/gup_benchmark.c?id=64c349f4ae78


> 
> >
> > Cc: John Hubbard 
> > Cc: Keith Busch 
> > Cc: Ira Weiny 
> > Cc: Kirill A. Shutemov 
> > Signed-off-by: Barry Song 
> > ---
> >   mm/Kconfig | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/mm/Kconfig b/mm/Kconfig
> > index 6c974888f86f..f7c9374da7b3 100644
> > --- a/mm/Kconfig
> > +++ b/mm/Kconfig
> > @@ -831,10 +831,10 @@ config PERCPU_STATS
> >   be used to help understand percpu memory usage.
> >
> >   config GUP_BENCHMARK
> > -   bool "Enable infrastructure for get_user_pages_fast() benchmarking"
> > +   bool "Enable infrastructure for get_user_pages() and related calls
> benchmarking"
> 
> If we really want to go to the trouble of tweaking this, then I'd go with
> something more like:
> 
> "Enable infrastructure for get_user_pages() and pin_user_pages benchmarking"
> 
> ...but I don't think it really warrants a patch just yet. *However*, my
> judgment is skewed right now, because I'm planning a small patchset to split
> up gup_benchmark a little bit, and to add some more testing and take
> advantage
> of parts of it to do a dump_page() test. At which point "related calls" would
> make more sense, but then it would be different enough that this patch would
> still need changing.

Ok. Fair enough. I was copying the "related calls" from:
Documentation/core-api/pin_user_pages.rst

> 
> So I'm inclined to just recommend leaving this alone for a bit, but if others
> want to put it in, I'm OK with that too.
> 
> > help
> >   Provides /sys/kernel/debug/gup_benchmark that helps with testing
> > - performance of get_user_pages_fast().
> > + performance of get_user_pages() and related calls.
> >
> >   See tools/testing/selftests/vm/gup_benchmark.c
> >

Thanks
Barry




Re: [PATCH v2] checkpatch: Fix the usage of capture group ( ... )

2020-08-20 Thread Joe Perches
On Thu, 2020-08-20 at 10:22 +0530, Mrinal Pandey wrote:
> On 20/07/30 12:31AM, Joe Perches wrote:
> > On Thu, 2020-07-30 at 07:58 +0200, Lukas Bulwahn wrote:
> > > Hi Joe,
> > > 
> > > did you see this quick fix to checkpatch.pl? Can you comment on the 
> > > commit and can we get a quick ack on that fix, please?
> > 
> > Yes, in a bit.
> > 
> > > General question on patches for ./scripts/checkpatch.pl:
> > > How do they travel to Linus?
> > 
> > Generally via Andrew Morton.
> > 
> > > Do you pick those patches and provide them to Andrew Morton?
> > > Or do you just ack them and we need to send them to Andrew Morton to get 
> > > them into mainline?
> > 
> > Generally, ack and forward.

https://lore.kernel.org/lkml/20200714032352.f476hanaj2dlmiot@mrinalpandey/

Andrew, can you pick up this patch please.

Thanks



Re: cma_alloc(), add sleep-and-retry for temporary page pinning

2020-08-20 Thread cgoldswo

On 2020-08-11 15:20, cgold...@codeaurora.org wrote:

On 2020-08-06 18:31, Andrew Morton wrote:

On Wed,  5 Aug 2020 19:56:21 -0700 Chris Goldsworthy
 wrote:


On mobile devices, failure to allocate from a CMA area constitutes a
functional failure.  Sometimes during CMA allocations, we have 
observed
that pages in a CMA area allocated through alloc_pages(), that we're 
trying
to migrate away to make room for a CMA allocation, are temporarily 
pinned.
This temporary pinning can occur when a process that owns the pinned 
page
is being forked (the example is explained further in the commit 
text).

This patch addresses this issue by adding a sleep-and-retry loop in
cma_alloc() . There's another example we know of similar to the above 
that
occurs during exit_mmap() (in zap_pte_range() specifically), but I 
need to

determine if this is still relevant today.





Sounds fairly serious but boy, we're late for 5.9.

I can queue it for 5.10 with a cc:stable so that it gets backported
into earlier kernels a couple of months from now, if we think the
seriousness justifies backporting(?).



Queuing this seems like the best way to proceed, if we were to pick up
this patch.
I think we can forgo back-porting this, as this is something that will 
only be
needed as vendors such as our selves start using Google's Generic 
Kernel Image

(we've carried this patch in our tree for over four years).



And...  it really is a sad little patch, isn't it?  Instead of fixing
the problem, it reduces the problem's probability by 5x.  Can't we do
better than this?


I have one alternative in mind.  I have been able to review the 
exit_mmap()

case, so before proceeding, let's do a breakdown of the problem: we can
categorize the pinning issue we're trying to address here as being one 
of

(1) incrementing _refcount and getting context-switched out before
incrementing _mapcount (applies to forking a process / copy_one_pte()), 
and

(2) decrementing _mapcount and getting context-switched out before
decrementing _refcount (applies to tearing down a process / 
exit_mmap()).
So, one alternative would be to insert preempt_disable/enable() calls 
at
affected sites. So, for the copy_one_pte() pinning case, we could do 
the

following inside of copy_one_pte():

if (page) {
+   preempt_disable();
get_page(page);
page_dup_rmap(page, false);
+   preempt_enable();
rss[mm_counter(page)]++;
}

I'm not sure if this approach would be acceptable for the exit_mmap()
pinning case (applicable when CONFIG_MMU_GATHER_NO_GATHER=y).  For the
purposes of this discussion, we can look at two function calls inside 
of

exit_mmap(), in the order they're called in, to show how the pinning is
occuring:

1. Calling unmap_vmas(): this unmaps the pages in each VMA for an
exiting task, using zap_pte_range() - zap_pte_range() reduces the
_mapcount for each page in a VMA, using page_remove_rmap().  After
calling page_remove_rmap(), the page is placed into a list in
__tlb_remove_page().  This list of pages will be used when flushing
TLB entries later on during the process teardown.

2. Calling tlb_finish_mmu(): This is will flush the TLB entries
associated with pages, before calling put_page() on them, using the
previously collected pages from __tlb_remove_page() - the call flow 
is

tlb_flush_mmu() > tlb_flush_mmu() > tlb_flush_mmu_free()
> tlb_batch_pages_flush() > free_pages_and_swap_cache() >
release_pages(), where release_pages() is described as a "batched
put_page()"

The preempt_disable/enable() approach would entail doing the following
inside of exit_mmap():

+   preempt_disable();
unmap_vmas(, vma, 0, -1);
free_pgtables(, vma, FIRST_USER_ADDRESS, 
USER_PGTABLES_CEILING);

tlb_finish_mmu(, 0, -1);
+   preempt_enable();

I'm not sure doing this is feasible, given how long it could take to do 
the

process teardown.

The good thing about this patch is that it has been stable in our 
kernel
for four years (though for some SoCs we increased the retry counts).  
One
thing to stress is that there are other instances of CMA page pinning, 
that
this patch isn't attempting to address. Please let me know if you're 
okay

with queuing this for the 5.10 merge window - if you are, I can add an
option to configure the number of retries, and will resend the patch 
once

the 5.9 merge window closes.

Thanks,

Chris.


Hi Andrew,

Have you been able to give the patch any further consideration?

Thanks,

Chris.

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

a Linux Foundation Collaborative Project


[PATCH] media: mtk-vcodec: set dma max segment size

2020-08-20 Thread Hsin-Yi Wang
Set dma max segment size for encoder and decoder driver.

Fix following warning with CONFIG_DMA_API_DEBUG_SG=y

[   75.147825] [ cut here ]
[   75.147844] mtk-vcodec-enc 19002000.vcodec: DMA-API: mapping sg segment 
longer than device claims to support [len=983040] [max=65536]
[   75.147876] WARNING: CPU: 2 PID: 4069 at kernel/dma/debug.c:1302 
debug_dma_map_sg+0x1a8/0x2c4
...
[   75.148139] Call trace:
[   75.148149]  debug_dma_map_sg+0x1a8/0x2c4
[   75.148165]  vb2_dc_get_userptr+0x228/0x364 [videobuf2_dma_contig]
[   75.148178]  __buf_prepare+0x3ac/0x8c0 [videobuf2_common]
[   75.148188]  vb2_core_qbuf+0xa4/0x58c [videobuf2_common]
[   75.148199]  vb2_qbuf+0x88/0xe4 [videobuf2_v4l2]
[   75.148211]  v4l2_m2m_qbuf+0x80/0xf8 [v4l2_mem2mem]
[   75.148221]  vidioc_venc_qbuf+0x3c/0x70 [mtk_vcodec_enc]
[   75.148234]  v4l_qbuf+0x48/0x58
[   75.148242]  __video_do_ioctl+0x200/0x37c
[   75.148250]  video_usercopy+0x360/0x834
[   75.148259]  video_ioctl2+0x38/0x48
[   75.148267]  v4l2_ioctl+0x6c/0x80
[   75.148276]  do_video_ioctl+0xefc/0x4b70
[   75.148284]  v4l2_compat_ioctl32+0x5c/0xcc
[   75.148294]  __arm64_compat_sys_ioctl+0xf4/0x240
[   75.148304]  el0_svc_common+0xac/0x198
[   75.148312]  el0_svc_compat_handler+0x2c/0x40
[   75.148321]  el0_svc_compat+0x8/0x18
[   75.148328] irq event stamp: 0
[   75.148337] hardirqs last  enabled at (0): [<>]   
(null)
[   75.148347] hardirqs last disabled at (0): [] 
copy_process+0x380/0x115c
[   75.148356] softirqs last  enabled at (0): [] 
copy_process+0x398/0x115c
[   75.148364] softirqs last disabled at (0): [<>]   
(null)
[   75.148372] ---[ end trace 588bf529451e3531 ]---

Reported-by: Anand K Mistry 
Signed-off-by: Hsin-Yi Wang 
---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 8 
 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 8 
 2 files changed, 16 insertions(+)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
index 97a1b6664c20..3bbd0bac56d6 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c
@@ -242,6 +242,14 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
mtk_v4l2_err("[VPU] vpu device in not ready");
return -EPROBE_DEFER;
}
+   if (!pdev->dev.dma_parms) {
+   pdev->dev.dma_parms = devm_kzalloc(>dev,
+   sizeof(*pdev->dev.dma_parms),
+   GFP_KERNEL);
+   if (!pdev->dev.dma_parms)
+   return -ENOMEM;
+   }
+   dma_set_max_seg_size(>dev, DMA_BIT_MASK(32));
 
vpu_wdt_reg_handler(dev->vpu_plat_dev, mtk_vcodec_dec_reset_handler,
dev, VPU_RST_DEC);
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c 
b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
index 4d31f1ed113f..ff4a87485d69 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
@@ -249,6 +249,14 @@ static int mtk_vcodec_probe(struct platform_device *pdev)
mtk_v4l2_err("[VPU] vpu device in not ready");
return -EPROBE_DEFER;
}
+   if (!pdev->dev.dma_parms) {
+   pdev->dev.dma_parms = devm_kzalloc(>dev,
+   sizeof(*pdev->dev.dma_parms),
+   GFP_KERNEL);
+   if (!pdev->dev.dma_parms)
+   return -ENOMEM;
+   }
+   dma_set_max_seg_size(>dev, DMA_BIT_MASK(32));
 
vpu_wdt_reg_handler(dev->vpu_plat_dev, mtk_vcodec_enc_reset_handler,
dev, VPU_RST_ENC);
-- 
2.28.0.297.g1956fa8f8d-goog



Re: [PATCH 1/1] block: move the PAGE_SECTORS definition into

2020-08-20 Thread Coly Li
On 2020/8/21 10:03, Zhen Lei wrote:
> There are too many PAGE_SECTORS definitions, and all of them are the
> same. It looks a bit of a mess. So why not move it into ,
> to achieve a basic and unique definition.
> 
> Signed-off-by: Zhen Lei 


A lazy question about page size > 4KB: currently in bcache code the
sector size is assumed to be 512 sectors, if kernel page > 4KB, it is
possible that PAGE_SECTORS in bcache will be a number > 8 ?

Thanks.

Coly Li


> ---
>  drivers/block/brd.c   | 1 -
>  drivers/block/null_blk_main.c | 1 -
>  drivers/md/bcache/util.h  | 2 --
>  include/linux/blkdev.h| 5 +++--
>  include/linux/device-mapper.h | 1 -
>  5 files changed, 3 insertions(+), 7 deletions(-)
> 

[snipped]

> diff --git a/drivers/md/bcache/util.h b/drivers/md/bcache/util.h
> index c029f7443190805..55196e0f37c32c6 100644
> --- a/drivers/md/bcache/util.h
> +++ b/drivers/md/bcache/util.h
> @@ -15,8 +15,6 @@
>  
>  #include "closure.h"
>  
> -#define PAGE_SECTORS (PAGE_SIZE / 512)
> -
>  struct closure;
>  
>  #ifdef CONFIG_BCACHE_DEBUG
> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
> index bb5636cc17b91a7..b068dfc5f2ef0ab 100644
> --- a/include/linux/blkdev.h
> +++ b/include/linux/blkdev.h
> @@ -949,11 +949,12 @@ static inline struct request_queue 
> *bdev_get_queue(struct block_device *bdev)
>   * multiple of 512 bytes. Hence these two constants.
>   */
>  #ifndef SECTOR_SHIFT
> -#define SECTOR_SHIFT 9
> +#define SECTOR_SHIFT 9
>  #endif
>  #ifndef SECTOR_SIZE
> -#define SECTOR_SIZE (1 << SECTOR_SHIFT)
> +#define SECTOR_SIZE  (1 << SECTOR_SHIFT)
>  #endif
> +#define PAGE_SECTORS (PAGE_SIZE / SECTOR_SIZE)
>  
>  /*
>   * blk_rq_pos()  : the current sector
[snipped]


Re: [RFC PATCH 0/5] KVM: arm64: Add pvtime LPT support

2020-08-20 Thread zhukeqian



On 2020/8/19 16:54, Steven Price wrote:
> On 18/08/2020 15:41, Marc Zyngier wrote:
>> On 2020-08-17 09:41, Keqian Zhu wrote:
>>> Hi all,
>>>
>>> This patch series picks up the LPT pvtime feature originally developed
>>> by Steven Price: https://patchwork.kernel.org/cover/10726499/
>>>
>>> Backgroud:
>>>
>>> There is demand for cross-platform migration, which means we have to
>>> solve different CPU features and arch counter frequency between hosts.
>>> This patch series can solve the latter problem.
>>>
>>> About LPT:
>>>
>>> This implements support for Live Physical Time (LPT) which provides the
>>> guest with a method to derive a stable counter of time during which the
>>> guest is executing even when the guest is being migrated between hosts
>>> with different physical counter frequencies.
>>>
>>> Changes on Steven Price's work:
>>> 1. LPT structure: use symmatical semantics of scale multiplier, and use
>>>fraction bits instead of "shift" to make everything clear.
>>> 2. Structure allocation: host kernel does not allocates the LPT structure,
>>>instead it is allocated by userspace through VM attributes. The 
>>> save/restore
>>>functionality can be removed.
>>> 3. Since LPT structure just need update once for each guest run, add a flag 
>>> to
>>>indicate the update status. This has two benifits: 1) avoid multiple 
>>> update
>>>by each vCPUs. 2) If the update flag is not set, then return NOT SUPPORT 
>>> for
>>>coressponding guest HVC call.
>>> 4. Add VM device attributes interface for userspace configuration.
>>> 5. Add a base LPT read/write layer to reduce code.
>>> 6. Support ptimer scaling.
>>> 7. Support timer event stream translation.
>>>
>>> Things need concern:
>>> 1. https://developer.arm.com/docs/den0057/a needs update.
>>
>> LPT was explicitly removed from the spec because it doesn't really
>> solve the problem, specially for the firmware: EFI knows
>> nothing about this, for example. How is it going to work?
>> Also, nobody was ever able to explain how this would work for
>> nested virt.
>>
>> ARMv8.4 and ARMv8.6 have the feature set that is required to solve
>> this problem without adding more PV to the kernel.
> 
> Hi Marc,
> 
> These are good points, however we do still have the situation that CPUs that 
> don't have ARMv8.4/8.6 clearly cannot implement this. I presume the use-case 
> Keqian is looking at predates the necessary support in the CPU - Keqian if 
> you can provide more details on the architecture(s) involved that would be 
> helpful.
> 
> Nested virt is indeed more of an issue - we did have some ideas around using 
> SDEI that never made it to the spec. However I would argue that the most 
> pragmatic approach would be to not support the combination of nested virt and 
> LPT. Hopefully that can wait until the counter scaling support is available 
> and not require PV.
> 
> We are discussing (re-)releasing the spec with the LPT parts added. If you 
> have fundamental objections then please me know.
> 
> Thanks,
> 
> Steve
> .
> 
Hi Marc and Steven,

In fact, I have realize a demo which utilize v8.6-ECV to present a constant 
timer freq to guest. It seems
work well, but this approach has some shortcoming:

1. Guest access to cntvct cntv_ctl cntv_tval cntv_cval must trap to EL2. Every 
trap will take about
   hundreds of nano-seconds. For every timer interrupt, there is about 5~6 
traps, so it will spend
   several us (this seems not a serious problem :-) ). But trap will cause big 
deviation for nano-sleep.
2. We have to make cntfrq be a context of guest. However, only the highest 
exception level has right to
   modify cntfrq. It means we have to add a new SMC call.
3. cntkctl controls event stream freq, so KVM should also translate the guest 
access of cntkctl. However
   we cannot trap guest access of that. Any solution for this problem?

I think LPT as a software solution can solve these problems. However, as Marc 
said, UEFI knows nothing about
LPT, and it will access vtimer/counter directly. The key point is how serious 
the impact is on UEFI.

I can see that some UEFI runtime services and drivers/applications will access 
timer/counter.
For runtime services, it is OK. Because we can translate the result which 
return from UEFI for Linux.
For drivers/applications, they will feel time goes faster or slower after 
migration. This is a problem indeed :-)

Thanks,
Keqian


Re: [PATCH] mm/gup_benchmark: update the documentation in Kconfig

2020-08-20 Thread John Hubbard

On 8/20/20 8:25 PM, Barry Song wrote:

In the beginning, mm/gup_benchmark.c supported get_user_pages_fast()
only, but right now, it supports the benchmarking of a couple of
get_user_pages() related calls like:
* get_user_pages_fast()
* get_user_pages()
* pin_user_pages_fast()
* pin_user_pages()
The documentation is confusing and needs update.


hmmm, it's not that confusing, given that pin_user_pages() and
get_user_pages() use the same underlying get_user_pages()
implementation.



Cc: John Hubbard 
Cc: Keith Busch 
Cc: Ira Weiny 
Cc: Kirill A. Shutemov 
Signed-off-by: Barry Song 
---
  mm/Kconfig | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/Kconfig b/mm/Kconfig
index 6c974888f86f..f7c9374da7b3 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -831,10 +831,10 @@ config PERCPU_STATS
  be used to help understand percpu memory usage.
  
  config GUP_BENCHMARK

-   bool "Enable infrastructure for get_user_pages_fast() benchmarking"
+   bool "Enable infrastructure for get_user_pages() and related calls 
benchmarking"


If we really want to go to the trouble of tweaking this, then I'd go with
something more like:

"Enable infrastructure for get_user_pages() and pin_user_pages benchmarking"

...but I don't think it really warrants a patch just yet. *However*, my
judgment is skewed right now, because I'm planning a small patchset to split
up gup_benchmark a little bit, and to add some more testing and take advantage
of parts of it to do a dump_page() test. At which point "related calls" would
make more sense, but then it would be different enough that this patch would
still need changing.

So I'm inclined to just recommend leaving this alone for a bit, but if others
want to put it in, I'm OK with that too.


help
  Provides /sys/kernel/debug/gup_benchmark that helps with testing
- performance of get_user_pages_fast().
+ performance of get_user_pages() and related calls.
  
  	  See tools/testing/selftests/vm/gup_benchmark.c
  



thanks,
--
John Hubbard
NVIDIA


[PATCH v10 24/24] coresight: allow the coresight core driver to be built as a module

2020-08-20 Thread Tingwei Zhang
Enhance coresight developer's efficiency to debug coresight drivers.
- Kconfig becomes a tristate, to allow =m
- append -core to source file name to allow module to
  be called coresight by the Makefile
- modules can have only one init/exit, so we add the etm_perf
  register/unregister function calls to the core init/exit
  functions.
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/Kconfig   |  5 ++-
 drivers/hwtracing/coresight/Makefile  |  5 ++-
 .../{coresight.c => coresight-core.c} | 42 ++-
 .../hwtracing/coresight/coresight-etm-perf.c  |  8 +++-
 .../hwtracing/coresight/coresight-etm-perf.h  |  3 ++
 5 files changed, 48 insertions(+), 15 deletions(-)
 rename drivers/hwtracing/coresight/{coresight.c => coresight-core.c} (98%)

diff --git a/drivers/hwtracing/coresight/Kconfig 
b/drivers/hwtracing/coresight/Kconfig
index dfe407cde262..c1198245461d 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -3,7 +3,7 @@
 # Coresight configuration
 #
 menuconfig CORESIGHT
-   bool "CoreSight Tracing Support"
+   tristate "CoreSight Tracing Support"
depends on ARM || ARM64
depends on OF || ACPI
select ARM_AMBA
@@ -15,6 +15,9 @@ menuconfig CORESIGHT
  specification and configure the right series of components when a
  trace source gets enabled.
 
+ To compile this driver as a module, choose M here: the
+ module will be called coresight.
+
 if CORESIGHT
 config CORESIGHT_LINKS_AND_SINKS
tristate "CoreSight Link and Sink drivers"
diff --git a/drivers/hwtracing/coresight/Makefile 
b/drivers/hwtracing/coresight/Makefile
index 0359d5a1588f..1b35b55bd420 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -2,8 +2,9 @@
 #
 # Makefile for CoreSight drivers.
 #
-obj-$(CONFIG_CORESIGHT) += coresight.o coresight-etm-perf.o \
-  coresight-platform.o coresight-sysfs.o
+obj-$(CONFIG_CORESIGHT) += coresight.o
+coresight-y := coresight-core.o  coresight-etm-perf.o coresight-platform.o \
+   coresight-sysfs.o
 obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o
 coresight-tmc-y := coresight-tmc-core.o coresight-tmc-etf.o \
  coresight-tmc-etr.o
diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight-core.c
similarity index 98%
rename from drivers/hwtracing/coresight/coresight.c
rename to drivers/hwtracing/coresight/coresight-core.c
index 668963b4b7d4..bf6edf468963 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight-core.c
@@ -1460,16 +1460,6 @@ int coresight_timeout(void __iomem *addr, u32 offset, 
int position, int value)
 }
 EXPORT_SYMBOL_GPL(coresight_timeout);
 
-struct bus_type coresight_bustype = {
-   .name   = "coresight",
-};
-
-static int __init coresight_init(void)
-{
-   return bus_register(_bustype);
-}
-postcore_initcall(coresight_init);
-
 /*
  * coresight_release_platform_data: Release references to the devices connected
  * to the output port of this device.
@@ -1678,3 +1668,35 @@ char *coresight_alloc_device_name(struct 
coresight_dev_list *dict,
return name;
 }
 EXPORT_SYMBOL_GPL(coresight_alloc_device_name);
+
+struct bus_type coresight_bustype = {
+   .name   = "coresight",
+};
+
+static int __init coresight_init(void)
+{
+   int ret;
+
+   ret = bus_register(_bustype);
+   if (ret)
+   return ret;
+
+   ret = etm_perf_init();
+   if (ret)
+   bus_unregister(_bustype);
+
+   return ret;
+}
+
+static void __exit coresight_exit(void)
+{
+   etm_perf_exit();
+   bus_unregister(_bustype);
+}
+
+module_init(coresight_init);
+module_exit(coresight_exit);
+
+MODULE_AUTHOR("Pratik Patel ");
+MODULE_AUTHOR("Mathieu Poirier ");
+MODULE_DESCRIPTION("Arm CoreSight tracer driver");
diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c 
b/drivers/hwtracing/coresight/coresight-etm-perf.c
index 3728c44e5763..668b3ff11576 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.c
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
@@ -591,7 +591,7 @@ void etm_perf_del_symlink_sink(struct coresight_device 
*csdev)
csdev->ea = NULL;
 }
 
-static int __init etm_perf_init(void)
+int __init etm_perf_init(void)
 {
int ret;
 
@@ -618,4 +618,8 @@ static int __init etm_perf_init(void)
 
return ret;
 }
-device_initcall(etm_perf_init);
+
+void __exit etm_perf_exit(void)
+{
+   perf_pmu_unregister(_pmu);
+}
diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.h 

Re: [PATCH v3 1/2] fs/binfmt_elf: Use PT_LOAD p_align values for suitable start address.

2020-08-20 Thread Andrew Morton
On Thu, 20 Aug 2020 13:05:40 -0400 Chris Kennelly  wrote:

> The current ELF loading mechancism provides page-aligned mappings.  This
> can lead to the program being loaded in a way unsuitable for
> file-backed, transparent huge pages when handling PIE executables.
> 
> For binaries built with increased alignment, this limits the number of
> bits usable for ASLR, but provides some randomization over using fixed
> load addresses/non-PIE binaries.
> 
> @@ -421,6 +422,24 @@ static int elf_read(struct file *file, void *buf, size_t 
> len, loff_t pos)
>   return 0;
>  }
>  
> +static unsigned long maximum_alignment(struct elf_phdr *cmds, int nr)
> +{
> + unsigned long alignment = 0;
> + int i;
> +
> + for (i = 0; i < nr; i++) {
> + if (cmds[i].p_type == PT_LOAD) {
> + /* skip non-power of two alignments */

Comment isn't terribly helpful.  It explains "what" (which is utterly
obvious from the code anyway) but it fails to explain "why".

> + if (!is_power_of_2(cmds[i].p_align))
> + continue;
> + alignment = max(alignment, cmds[i].p_align);

generates a max() warning:

fs/binfmt_elf.c:435:16: note: in expansion of macro `max'
alignment = max(alignment, cmds[i].p_align);

p_align may be Elf64_Xword, may be Elf32_Word, may be something else. 
That's quite unwieldy and I don't like max_t.  How about this?

--- 
a/fs/binfmt_elf.c~fs-binfmt_elf-use-pt_load-p_align-values-for-suitable-start-address-fix
+++ a/fs/binfmt_elf.c
@@ -429,10 +429,12 @@ static unsigned long maximum_alignment(s
 
for (i = 0; i < nr; i++) {
if (cmds[i].p_type == PT_LOAD) {
+   unsigned long p_align = cmds[i].p_align;
+
/* skip non-power of two alignments */
-   if (!is_power_of_2(cmds[i].p_align))
+   if (!is_power_of_2(p_align))
continue;
-   alignment = max(alignment, cmds[i].p_align);
+   alignment = max(alignment, p_align);
}
}
 
_



Lockdep warning caused by "driver core: Fix sleeping in invalid context during device link deletion"

2020-08-20 Thread Dong Aisheng
Hi ALL,

We met the below WARNING during system suspend on an iMX6Q SDB board
with the latest linus/master branch (v5.9-rc1+) and next-20200820.
v5.8 kernel is ok. So i did bisect and finally found it's caused by
the patch below.
Reverting it can get rid of the warning, but I wonder if there may be
other potential issues.
Any ideas?

Defconfig used is: imx_v6_v7_defconfig

commit 843e600b8a2b01463c4d873a90b2c2ea8033f1f6
Author: Saravana Kannan 
Date:   Thu Jul 16 14:45:23 2020 -0700

driver core: Fix sleeping in invalid context during device link deletion

Marek and Guenter reported that commit 287905e68dd2 ("driver core:
Expose device link details in sysfs") caused sleeping/scheduling while
atomic warnings.

BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:935
in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 12, name: kworker/0:1
2 locks held by kworker/0:1/12:
  #0: ee8074a8 ((wq_completion)rcu_gp){+.+.}-{0:0}, at:
process_one_work+0x174/0x7dc
  #1: ee921f20 ((work_completion)(>work)){+.+.}-{0:0}, at:
process_one_work+0x174/0x7dc
Preemption disabled at:
[] srcu_invoke_callbacks+0xc0/0x154
- 8< - SNIP
[] (device_del) from [] (device_unregister+0x24/0x64)
[] (device_unregister) from []
(srcu_invoke_callbacks+0xcc/0x154)
[] (srcu_invoke_callbacks) from []
(process_one_work+0x234/0x7dc)
[] (process_one_work) from [] (worker_thread+0x44/0x51c)
[] (worker_thread) from [] (kthread+0x158/0x1a0)
[] (kthread) from [] (ret_from_fork+0x14/0x20)
Exception stack(0xee921fb0 to 0xee921ff8)

This was caused by the device link device being released in the context
of srcu_invoke_callbacks().  There is no need to wait till the RCU
callback to release the device link device.  So release the device
earlier and move the call_srcu() into the device release code. That way,
the memory will get freed only after the device is released AND the RCU
callback is called.

Fixes: 287905e68dd2 ("driver core: Expose device link details in sysfs")
Reported-by: Marek Szyprowski 
Reported-by: Guenter Roeck 
Reported-by: Naresh Kamboju 
Signed-off-by: Saravana Kannan 
Tested-by: Marek Szyprowski 
Tested-by: Guenter Roeck 
Link: 
https://lore.kernel.org/r/20200716214523.2924704-1-sarava...@google.com
Signed-off-by: Greg Kroah-Hartman 

Error log:
# echo mem > /sys/power/state
[   39.111865] PM: suspend entry (deep)
[   39.148650] Filesystems sync: 0.032 seconds
[   39.154034]
[   39.155537] ==
[   39.161723] WARNING: possible circular locking dependency detected
[   39.167911] 5.9.0-rc1-00103-g7eac66d0456f #37 Not tainted
[   39.173315] --
[   39.179500] sh/647 is trying to acquire lock:
[   39.183862] c15a310c (dpm_list_mtx){+.+.}-{3:3}, at:
dpm_for_each_dev+0x20/0x5c
[   39.191200]
[   39.191200] but task is already holding lock:
[   39.197036] c15a37e4 (fw_lock){+.+.}-{3:3}, at: fw_pm_notify+0x90/0xd4
[   39.203582]
[   39.203582] which lock already depends on the new lock.
[   39.203582]
[   39.211763]
[   39.211763] the existing dependency chain (in reverse order) is:
[   39.219249]
[   39.219249] -> #2 (fw_lock){+.+.}-{3:3}:
[   39.224673]mutex_lock_nested+0x1c/0x24
[   39.229126]firmware_uevent+0x18/0xa0
[   39.233411]dev_uevent+0xc4/0x1f8
[   39.237343]uevent_show+0x98/0x114
[   39.241362]dev_attr_show+0x18/0x48
[   39.245472]sysfs_kf_seq_show+0x84/0xec
[   39.249927]seq_read+0x138/0x550
[   39.253774]vfs_read+0x94/0x164
[   39.257529]ksys_read+0x60/0xe8
[   39.261288]ret_fast_syscall+0x0/0x28
[   39.265564]0xbed7c808
[   39.268538]
[   39.268538] -> #1 (kn->active#3){}-{0:0}:
[   39.274391]kernfs_remove_by_name_ns+0x40/0x94
[   39.279450]device_del+0x144/0x3fc
[   39.283467]__device_link_del+0x4c/0x70
[   39.287919]device_link_remove+0x5c/0x8c
[   39.292464]_regulator_put.part.0+0x104/0x1dc
[   39.297436]regulator_put+0x2c/0x3c
[   39.299731] regulator regulator.5: Failed to increase supply voltage: -110
[   39.301544]release_nodes+0x1b4/0x204
[   39.301553]really_probe+0x104/0x3b4
[   39.316881]driver_probe_device+0x58/0xb4
[   39.321506]device_driver_attach+0x58/0x60
[   39.326217]__driver_attach+0x58/0xd0
[   39.330499]bus_for_each_dev+0x74/0xbc
[   39.334863]bus_add_driver+0x150/0x1dc
[   39.339227]driver_register+0x74/0x108
[   39.343599]i2c_register_driver+0x38/0x8c
[   39.348227]do_one_initcall+0x84/0x3b4
[   39.352598]kernel_init_freeable+0x154/0x1e4
[   39.357485]kernel_init+0x8/0x118
[   39.361415]ret_from_fork+0x14/0x20
[   39.365518]0x0
[   39.367883]
[   39.3

[PATCH v10 22/24] coresight: tmc-etr: add function to register catu ops

2020-08-20 Thread Tingwei Zhang
From: Mian Yousaf Kaukab 

Make etr_catu_buf_ops static. Instead of directly accessing it in
etr_buf_ops[], add a function to let catu driver register the ops at
runtime. Break circular dependency between tmc-etr and catu drivers.

Signed-off-by: Mian Yousaf Kaukab 
Signed-off-by: Tingwei Zhang 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/coresight-catu.c  | 22 +--
 drivers/hwtracing/coresight/coresight-catu.h  |  2 --
 .../hwtracing/coresight/coresight-tmc-etr.c   | 15 +++--
 drivers/hwtracing/coresight/coresight-tmc.h   |  3 +++
 4 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-catu.c 
b/drivers/hwtracing/coresight/coresight-catu.c
index 1801804a7762..47696a7d24a7 100644
--- a/drivers/hwtracing/coresight/coresight-catu.c
+++ b/drivers/hwtracing/coresight/coresight-catu.c
@@ -358,7 +358,7 @@ static int catu_alloc_etr_buf(struct tmc_drvdata 
*tmc_drvdata,
return 0;
 }
 
-const struct etr_buf_operations etr_catu_buf_ops = {
+static const struct etr_buf_operations etr_catu_buf_ops = {
.alloc = catu_alloc_etr_buf,
.free = catu_free_etr_buf,
.sync = catu_sync_etr_buf,
@@ -582,4 +582,22 @@ static struct amba_driver catu_driver = {
.id_table   = catu_ids,
 };
 
-builtin_amba_driver(catu_driver);
+static int __init catu_init(void)
+{
+   int ret;
+
+   ret = amba_driver_register(_driver);
+   if (ret)
+   pr_info("Error registering catu driver\n");
+   tmc_etr_set_catu_ops(_catu_buf_ops);
+   return ret;
+}
+
+static void __exit catu_exit(void)
+{
+   tmc_etr_remove_catu_ops();
+   amba_driver_unregister(_driver);
+}
+
+module_init(catu_init);
+module_exit(catu_exit);
diff --git a/drivers/hwtracing/coresight/coresight-catu.h 
b/drivers/hwtracing/coresight/coresight-catu.h
index 80ceee3c739c..6160c2d75a56 100644
--- a/drivers/hwtracing/coresight/coresight-catu.h
+++ b/drivers/hwtracing/coresight/coresight-catu.h
@@ -108,6 +108,4 @@ static inline bool coresight_is_catu_device(struct 
coresight_device *csdev)
return true;
 }
 
-extern const struct etr_buf_operations etr_catu_buf_ops;
-
 #endif
diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c 
b/drivers/hwtracing/coresight/coresight-tmc-etr.c
index ad991a37e2d2..714f9e867e5f 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-etr.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c
@@ -794,10 +794,21 @@ static inline void tmc_etr_disable_catu(struct 
tmc_drvdata *drvdata)
 static const struct etr_buf_operations *etr_buf_ops[] = {
[ETR_MODE_FLAT] = _flat_buf_ops,
[ETR_MODE_ETR_SG] = _sg_buf_ops,
-   [ETR_MODE_CATU] = IS_ENABLED(CONFIG_CORESIGHT_CATU)
-   ? _catu_buf_ops : NULL,
+   [ETR_MODE_CATU] = NULL,
 };
 
+void tmc_etr_set_catu_ops(const struct etr_buf_operations *catu)
+{
+   etr_buf_ops[ETR_MODE_CATU] = catu;
+}
+EXPORT_SYMBOL_GPL(tmc_etr_set_catu_ops);
+
+void tmc_etr_remove_catu_ops(void)
+{
+   etr_buf_ops[ETR_MODE_CATU] = NULL;
+}
+EXPORT_SYMBOL_GPL(tmc_etr_remove_catu_ops);
+
 static inline int tmc_etr_mode_alloc_buf(int mode,
 struct tmc_drvdata *drvdata,
 struct etr_buf *etr_buf, int node,
diff --git a/drivers/hwtracing/coresight/coresight-tmc.h 
b/drivers/hwtracing/coresight/coresight-tmc.h
index 6e8d2dc33d17..b91ec7dde7bc 100644
--- a/drivers/hwtracing/coresight/coresight-tmc.h
+++ b/drivers/hwtracing/coresight/coresight-tmc.h
@@ -326,4 +326,7 @@ tmc_sg_table_buf_size(struct tmc_sg_table *sg_table)
 
 struct coresight_device *tmc_etr_get_catu_device(struct tmc_drvdata *drvdata);
 
+void tmc_etr_set_catu_ops(const struct etr_buf_operations *catu);
+void tmc_etr_remove_catu_ops(void);
+
 #endif
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 23/24] coresight: catu: allow catu drivers to be built as modules

2020-08-20 Thread Tingwei Zhang
Allow to build coresight-catu as modules, for ease of development.
- Kconfig becomes a tristate, to allow =m
- add catu_remove functions, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Signed-off-by: Tingwei Zhang 
Reviewed-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/Kconfig  |  5 -
 drivers/hwtracing/coresight/coresight-catu.c | 15 +++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/hwtracing/coresight/Kconfig 
b/drivers/hwtracing/coresight/Kconfig
index b04aae2ceecc..dfe407cde262 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -42,7 +42,7 @@ config CORESIGHT_LINK_AND_SINK_TMC
  module will be called coresight-tmc.
 
 config CORESIGHT_CATU
-   bool "Coresight Address Translation Unit (CATU) driver"
+   tristate "Coresight Address Translation Unit (CATU) driver"
depends on CORESIGHT_LINK_AND_SINK_TMC
help
   Enable support for the Coresight Address Translation Unit (CATU).
@@ -52,6 +52,9 @@ config CORESIGHT_CATU
   by looking up the provided table. CATU can also be used in 
pass-through
   mode where the address is not translated.
 
+  To compile this driver as a module, choose M here: the
+  module will be called coresight-catu.
+
 config CORESIGHT_SINK_TPIU
tristate "Coresight generic TPIU driver"
depends on CORESIGHT_LINKS_AND_SINKS
diff --git a/drivers/hwtracing/coresight/coresight-catu.c 
b/drivers/hwtracing/coresight/coresight-catu.c
index 47696a7d24a7..99430f6cf5a5 100644
--- a/drivers/hwtracing/coresight/coresight-catu.c
+++ b/drivers/hwtracing/coresight/coresight-catu.c
@@ -567,11 +567,21 @@ static int catu_probe(struct amba_device *adev, const 
struct amba_id *id)
return ret;
 }
 
+static int __exit catu_remove(struct amba_device *adev)
+{
+   struct catu_drvdata *drvdata = dev_get_drvdata(>dev);
+
+   coresight_unregister(drvdata->csdev);
+   return 0;
+}
+
 static struct amba_id catu_ids[] = {
CS_AMBA_ID(0x000bb9ee),
{},
 };
 
+MODULE_DEVICE_TABLE(amba, catu_ids);
+
 static struct amba_driver catu_driver = {
.drv = {
.name   = "coresight-catu",
@@ -579,6 +589,7 @@ static struct amba_driver catu_driver = {
.suppress_bind_attrs= true,
},
.probe  = catu_probe,
+   .remove = catu_remove,
.id_table   = catu_ids,
 };
 
@@ -601,3 +612,7 @@ static void __exit catu_exit(void)
 
 module_init(catu_init);
 module_exit(catu_exit);
+
+MODULE_AUTHOR("Suzuki K Poulose ");
+MODULE_DESCRIPTION("Arm CoreSight Address Translation Unit (CATU) Driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



Re: [PATCH v6 0/3] SELinux support for anonymous inodes and UFFD

2020-08-20 Thread Lokesh Gidra
On Thu, Aug 20, 2020 at 11:36 AM James Morris  wrote:
>
> On Fri, 7 Aug 2020, Lokesh Gidra wrote:
>
> > Userfaultfd in unprivileged contexts could be potentially very
> > useful. We'd like to harden userfaultfd to make such unprivileged use
> > less risky. This patch series allows SELinux to manage userfaultfd
> > file descriptors and in the future, other kinds of
> > anonymous-inode-based file descriptor.  SELinux policy authors can
> > apply policy types to anonymous inodes by providing name-based
> > transition rules keyed off the anonymous inode internal name (
> > "[userfaultfd]" in the case of userfaultfd(2) file descriptors) and
> > applying policy to the new SIDs thus produced.
>
> Can you expand more on why this would be useful, e.g. use-cases?
>
With SELinux managed userfaultfd file descriptors, an administrator
can control creation and movement of them. In particular, handling of
a userfaultfd descriptor by a different process is essentially a
ptrace access into the process, without any of the
corresponding security_ptrace_access_check() checks. For privacy, the
admin may want to deny such accesses,
which is possible with SELinux support.

I'll add this use case in the cover letter too in the next version.


[PATCH v10 19/24] coresight: cti: don't disable ect device if it's not enabled

2020-08-20 Thread Tingwei Zhang
If associated ect device is not enabled at first place, disable
routine should not be called. Add ect_enabled flag to check whether
ect device is enabled. Fix the issue in below case.  Ect device is
not available when associated coresight device enabled and the
association is established after coresight device is enabled.

Signed-off-by: Mike Leach 
Signed-off-by: Tingwei Zhang 
---
 drivers/hwtracing/coresight/coresight.c | 11 ---
 include/linux/coresight.h   |  1 +
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index 6c09be15d60c..d354fd57474e 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -244,13 +244,18 @@ coresight_control_assoc_ectdev(struct coresight_device 
*csdev, bool enable)
 
if (!ect_csdev)
return 0;
+   if ((!ect_ops(ect_csdev)->enable) || (!ect_ops(ect_csdev)->disable))
+   return 0;
 
if (enable) {
-   if (ect_ops(ect_csdev)->enable)
-   ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
+   ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
+   if (!ect_ret)
+   csdev->ect_enabled = true;
} else {
-   if (ect_ops(ect_csdev)->disable)
+   if (csdev->ect_enabled) {
ect_ret = ect_ops(ect_csdev)->disable(ect_csdev);
+   csdev->ect_enabled = false;
+   }
}
 
/* output warning if ECT enable is preventing trace operation */
diff --git a/include/linux/coresight.h b/include/linux/coresight.h
index 3bb738f9a326..7d3c87e5b97c 100644
--- a/include/linux/coresight.h
+++ b/include/linux/coresight.h
@@ -208,6 +208,7 @@ struct coresight_device {
/* sysfs links between components */
int nr_links;
bool has_conns_grp;
+   bool ect_enabled; /* true only if associated ect device is enabled */
 };
 
 /*
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 21/24] coresight: cti: allow cti to be built as a module

2020-08-20 Thread Tingwei Zhang
Allow to build coresight-cti as a module, for ease of development.

- Kconfig becomes a tristate, to allow =m
- append -core to source file name to allow module to
  be called coresight-cti by the Makefile
- add an cti_remove function, for module unload
- move cti_remove_conn_xrefs to cti_remove
- add a MODULE_DEVICE_TABLE for autoloading on boot

Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by Mike Leach 
---
 drivers/hwtracing/coresight/Kconfig   |  5 -
 drivers/hwtracing/coresight/Makefile  |  4 ++--
 .../{coresight-cti.c => coresight-cti-core.c} | 20 ++-
 .../hwtracing/coresight/coresight-platform.c  |  1 +
 drivers/hwtracing/coresight/coresight.c   |  1 +
 5 files changed, 27 insertions(+), 4 deletions(-)
 rename drivers/hwtracing/coresight/{coresight-cti.c => coresight-cti-core.c} 
(98%)

diff --git a/drivers/hwtracing/coresight/Kconfig 
b/drivers/hwtracing/coresight/Kconfig
index f31778dd0b5d..b04aae2ceecc 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -136,7 +136,7 @@ config CORESIGHT_CPU_DEBUG
  module will be called coresight-cpu-debug.
 
 config CORESIGHT_CTI
-   bool "CoreSight Cross Trigger Interface (CTI) driver"
+   tristate "CoreSight Cross Trigger Interface (CTI) driver"
depends on ARM || ARM64
help
  This driver provides support for CoreSight CTI and CTM components.
@@ -147,6 +147,9 @@ config CORESIGHT_CTI
  halt compared to disabling sources and sinks normally in driver
  software.
 
+ To compile this driver as a module, choose M here: the
+ module will be called coresight-cti.
+
 config CORESIGHT_CTI_INTEGRATION_REGS
bool "Access CTI CoreSight Integration Registers"
depends on CORESIGHT_CTI
diff --git a/drivers/hwtracing/coresight/Makefile 
b/drivers/hwtracing/coresight/Makefile
index f2a568b969c4..0359d5a1588f 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -19,6 +19,6 @@ coresight-etm4x-y := coresight-etm4x-core.o 
coresight-etm4x-sysfs.o
 obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
 obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
 obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
-obj-$(CONFIG_CORESIGHT_CTI) += coresight-cti.o \
-   coresight-cti-platform.o \
+obj-$(CONFIG_CORESIGHT_CTI) += coresight-cti.o
+coresight-cti-y := coresight-cti-core.ocoresight-cti-platform.o \
coresight-cti-sysfs.o
diff --git a/drivers/hwtracing/coresight/coresight-cti.c 
b/drivers/hwtracing/coresight/coresight-cti-core.c
similarity index 98%
rename from drivers/hwtracing/coresight/coresight-cti.c
rename to drivers/hwtracing/coresight/coresight-cti-core.c
index ec286d617b73..d6d5419ec21c 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti-core.c
@@ -838,7 +838,6 @@ static void cti_device_release(struct device *dev)
struct cti_drvdata *ect_item, *ect_tmp;
 
mutex_lock(_mutex);
-   cti_remove_conn_xrefs(drvdata);
cti_pm_release(drvdata);
 
/* remove from the list */
@@ -853,6 +852,18 @@ static void cti_device_release(struct device *dev)
if (drvdata->csdev_release)
drvdata->csdev_release(dev);
 }
+static int __exit cti_remove(struct amba_device *adev)
+{
+   struct cti_drvdata *drvdata = dev_get_drvdata(>dev);
+
+   mutex_lock(_mutex);
+   cti_remove_conn_xrefs(drvdata);
+   mutex_unlock(_mutex);
+
+   coresight_unregister(drvdata->csdev);
+
+   return 0;
+}
 
 static int cti_probe(struct amba_device *adev, const struct amba_id *id)
 {
@@ -973,6 +984,8 @@ static const struct amba_id cti_ids[] = {
{ 0, 0},
 };
 
+MODULE_DEVICE_TABLE(amba, cti_ids);
+
 static struct amba_driver cti_driver = {
.drv = {
.name   = "coresight-cti",
@@ -980,6 +993,7 @@ static struct amba_driver cti_driver = {
.suppress_bind_attrs = true,
},
.probe  = cti_probe,
+   .remove = cti_remove,
.id_table   = cti_ids,
 };
 
@@ -1002,3 +1016,7 @@ static void __exit cti_exit(void)
 
 module_init(cti_init);
 module_exit(cti_exit);
+
+MODULE_AUTHOR("Mike Leach ");
+MODULE_DESCRIPTION("Arm CoreSight CTI Driver");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/hwtracing/coresight/coresight-platform.c 
b/drivers/hwtracing/coresight/coresight-platform.c
index 227e234a2470..3629b7885aca 100644
--- a/drivers/hwtracing/coresight/coresight-platform.c
+++ b/drivers/hwtracing/coresight/coresight-platform.c
@@ -75,6 +75,7 @@ coresight_find_csdev_by_fwnode(struct fwnode_handle *r_fwnode)
}
return csdev;
 }
+EXPORT_SYMBOL_GPL(coresight_find_csdev_by_fwnode);
 
 #ifdef CONFIG_OF
 static inline bool of_coresight_legacy_ep_is_input(struct device_node *ep)
diff --git 

[PATCH v10 20/24] coresight: cti: increase reference count when enabling cti

2020-08-20 Thread Tingwei Zhang
CTI device is enabled when associated coresight device is enabled.
Increase the module and device reference count for CTI device
when it's enabled. This can prevent CTI device be removed or
module be unloaded when CTI device is enabled by an active trace
session.

Signed-off-by: Mike Leach 
Signed-off-by: Tingwei Zhang 
---
 drivers/hwtracing/coresight/coresight.c | 17 ++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index d354fd57474e..6c9f6930b8b8 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -241,19 +241,30 @@ coresight_control_assoc_ectdev(struct coresight_device 
*csdev, bool enable)
 {
int ect_ret = 0;
struct coresight_device *ect_csdev = csdev->ect_dev;
+   struct module *mod;
 
if (!ect_csdev)
return 0;
if ((!ect_ops(ect_csdev)->enable) || (!ect_ops(ect_csdev)->disable))
return 0;
 
+   mod = ect_csdev->dev.parent->driver->owner;
if (enable) {
-   ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
-   if (!ect_ret)
-   csdev->ect_enabled = true;
+   if (try_module_get(mod)) {
+   ect_ret = ect_ops(ect_csdev)->enable(ect_csdev);
+   if (ect_ret) {
+   module_put(mod);
+   } else {
+   get_device(ect_csdev->dev.parent);
+   csdev->ect_enabled = true;
+   }
+   } else
+   ect_ret = -ENODEV;
} else {
if (csdev->ect_enabled) {
ect_ret = ect_ops(ect_csdev)->disable(ect_csdev);
+   put_device(ect_csdev->dev.parent);
+   module_put(mod);
csdev->ect_enabled = false;
}
}
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 18/24] coresight: cti: Fix bug clearing sysfs links on callback

2020-08-20 Thread Tingwei Zhang
From: Mike Leach 

During module unload, a coresight driver module will call back into
the CTI driver to remove any links between the two devices.

The current code has 2 issues:-
1) in the CTI driver the matching code is matching to the wrong device
so misses all the links.
2) The callback is called too late in the unload process resulting in a
crash.

This fixes both the issues.

Fixes: 177af8285b59 ("coresight: cti: Enable CTI associated with devices")
Reported-by: Tingwei Zhang 
Signed-off-by: Mike Leach 
Signed-off-by: Tingwei Zhang 
Acked-by: Suzuki K Poulose 
---
 drivers/hwtracing/coresight/coresight-cti.c | 2 +-
 drivers/hwtracing/coresight/coresight.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-cti.c 
b/drivers/hwtracing/coresight/coresight-cti.c
index 73304374a155..ec286d617b73 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti.c
@@ -608,7 +608,7 @@ static void cti_remove_assoc_from_csdev(struct 
coresight_device *csdev)
ctidrv = csdev_to_cti_drvdata(csdev->ect_dev);
ctidev = >ctidev;
list_for_each_entry(tc, >trig_cons, node) {
-   if (tc->con_dev == csdev->ect_dev) {
+   if (tc->con_dev == csdev) {
cti_remove_sysfs_link(ctidrv, tc);
tc->con_dev = NULL;
break;
diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index c2174fed263b..6c09be15d60c 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -1254,8 +1254,6 @@ static void coresight_device_release(struct device *dev)
 {
struct coresight_device *csdev = to_coresight_device(dev);
 
-   if (cti_assoc_ops && cti_assoc_ops->remove)
-   cti_assoc_ops->remove(csdev);
fwnode_handle_put(csdev->dev.fwnode);
kfree(csdev->refcnt);
kfree(csdev);
@@ -1590,6 +1588,8 @@ void coresight_unregister(struct coresight_device *csdev)
 {
etm_perf_del_symlink_sink(csdev);
/* Remove references of that device in the topology */
+   if (cti_assoc_ops && cti_assoc_ops->remove)
+   cti_assoc_ops->remove(csdev);
coresight_remove_conns(csdev);
coresight_clear_default_sink(csdev);
coresight_release_platform_data(csdev, csdev->pdata);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



Re: [PATCH RESEND 1/9] crypto: caam/jr - add fallback for XTS with more than 8B IV

2020-08-20 Thread Herbert Xu
On Tue, Aug 11, 2020 at 05:30:41PM +0300, Horia Geantă wrote:
>
> > +   if (IS_ERR(fallback)) {
> > +   pr_err("Failed to allocate %s fallback: %ld\n",
> > +  tfm_name, PTR_ERR(fallback));
> > +   return PTR_ERR(fallback);
> Shouldn't error out so early. It might be that the fallback won't be needed.
> Let's postpone this until we're sure fallback is required.

Why? The generic should always be there as otherwise you won't
even pass the self-test.  If we're OOM then we should error out
ASAP.

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


[PATCH v10 14/24] coresight: allow funnel driver to be built as module

2020-08-20 Thread Tingwei Zhang
From: Kim Phillips 

Allow to build coresight-funnel as module, for ease of development.

- combine static and dynamic funnel init into single
  module_init/exit call
- add funnel_remove functions, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Co-developed-by: Mian Yousaf Kaukab 
Signed-off-by: Mian Yousaf Kaukab 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Reported-by: kernel test robot 
Tested-by: Mike Leach 
Reviewed-by: Mathieu Poirier 
---
 .../hwtracing/coresight/coresight-funnel.c| 64 ++-
 1 file changed, 62 insertions(+), 2 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-funnel.c 
b/drivers/hwtracing/coresight/coresight-funnel.c
index 900690a9f7f0..07bc20391fac 100644
--- a/drivers/hwtracing/coresight/coresight-funnel.c
+++ b/drivers/hwtracing/coresight/coresight-funnel.c
@@ -274,6 +274,15 @@ static int funnel_probe(struct device *dev, struct 
resource *res)
return ret;
 }
 
+static int __exit funnel_remove(struct device *dev)
+{
+   struct funnel_drvdata *drvdata = dev_get_drvdata(dev);
+
+   coresight_unregister(drvdata->csdev);
+
+   return 0;
+}
+
 #ifdef CONFIG_PM
 static int funnel_runtime_suspend(struct device *dev)
 {
@@ -319,20 +328,32 @@ static int static_funnel_probe(struct platform_device 
*pdev)
return ret;
 }
 
+static int __exit static_funnel_remove(struct platform_device *pdev)
+{
+   funnel_remove(>dev);
+   pm_runtime_disable(>dev);
+   return 0;
+}
+
 static const struct of_device_id static_funnel_match[] = {
{.compatible = "arm,coresight-static-funnel"},
{}
 };
 
+MODULE_DEVICE_TABLE(of, static_funnel_match);
+
 #ifdef CONFIG_ACPI
 static const struct acpi_device_id static_funnel_ids[] = {
{"ARMHC9FE", 0},
{},
 };
+
+MODULE_DEVICE_TABLE(acpi, static_funnel_ids);
 #endif
 
 static struct platform_driver static_funnel_driver = {
.probe  = static_funnel_probe,
+   .remove  = static_funnel_remove,
.driver = {
.name   = "coresight-static-funnel",
.of_match_table = static_funnel_match,
@@ -341,7 +362,6 @@ static struct platform_driver static_funnel_driver = {
.suppress_bind_attrs = true,
},
 };
-builtin_platform_driver(static_funnel_driver);
 
 static int dynamic_funnel_probe(struct amba_device *adev,
const struct amba_id *id)
@@ -349,6 +369,11 @@ static int dynamic_funnel_probe(struct amba_device *adev,
return funnel_probe(>dev, >res);
 }
 
+static int __exit dynamic_funnel_remove(struct amba_device *adev)
+{
+   return funnel_remove(>dev);
+}
+
 static const struct amba_id dynamic_funnel_ids[] = {
{
.id = 0x000bb908,
@@ -362,6 +387,8 @@ static const struct amba_id dynamic_funnel_ids[] = {
{ 0, 0},
 };
 
+MODULE_DEVICE_TABLE(amba, dynamic_funnel_ids);
+
 static struct amba_driver dynamic_funnel_driver = {
.drv = {
.name   = "coresight-dynamic-funnel",
@@ -370,6 +397,39 @@ static struct amba_driver dynamic_funnel_driver = {
.suppress_bind_attrs = true,
},
.probe  = dynamic_funnel_probe,
+   .remove = dynamic_funnel_remove,
.id_table   = dynamic_funnel_ids,
 };
-builtin_amba_driver(dynamic_funnel_driver);
+
+static int __init funnel_init(void)
+{
+   int ret;
+
+   ret = platform_driver_register(_funnel_driver);
+   if (ret) {
+   pr_info("Error registering platform driver\n");
+   return ret;
+   }
+
+   ret = amba_driver_register(_funnel_driver);
+   if (ret) {
+   pr_info("Error registering amba driver\n");
+   platform_driver_unregister(_funnel_driver);
+   }
+
+   return ret;
+}
+
+static void __exit funnel_exit(void)
+{
+   platform_driver_unregister(_funnel_driver);
+   amba_driver_unregister(_funnel_driver);
+}
+
+module_init(funnel_init);
+module_exit(funnel_exit);
+
+MODULE_AUTHOR("Pratik Patel ");
+MODULE_AUTHOR("Mathieu Poirier ");
+MODULE_DESCRIPTION("Arm CoreSight Funnel Driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 17/24] coresight: cti: Fix remove sysfs link error

2020-08-20 Thread Tingwei Zhang
From: Mike Leach 

CTI code to remove sysfs link to other devices on shutdown, incorrectly
tries to remove a single ended link when these are all double ended. This
implementation leaves elements in the link info structure undefined which
results in a crash in recent tests for driver module unload.

This patch corrects the link removal code.

Fixes: 73274abb6557 ("coresight: cti: Add in sysfs links to other coresight 
devices")
Reported-by: Tingwei Zhang 
Signed-off-by: Mike Leach 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/coresight-cti.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-cti.c 
b/drivers/hwtracing/coresight/coresight-cti.c
index b031c9dbe026..73304374a155 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti.c
@@ -511,12 +511,15 @@ static bool cti_add_sysfs_link(struct cti_drvdata 
*drvdata,
return !link_err;
 }
 
-static void cti_remove_sysfs_link(struct cti_trig_con *tc)
+static void cti_remove_sysfs_link(struct cti_drvdata *drvdata,
+ struct cti_trig_con *tc)
 {
struct coresight_sysfs_link link_info;
 
+   link_info.orig = drvdata->csdev;
link_info.orig_name = tc->con_dev_name;
link_info.target = tc->con_dev;
+   link_info.target_name = dev_name(>csdev->dev);
coresight_remove_sysfs_link(_info);
 }
 
@@ -606,7 +609,7 @@ static void cti_remove_assoc_from_csdev(struct 
coresight_device *csdev)
ctidev = >ctidev;
list_for_each_entry(tc, >trig_cons, node) {
if (tc->con_dev == csdev->ect_dev) {
-   cti_remove_sysfs_link(tc);
+   cti_remove_sysfs_link(ctidrv, tc);
tc->con_dev = NULL;
break;
}
@@ -658,7 +661,7 @@ static void cti_remove_conn_xrefs(struct cti_drvdata 
*drvdata)
if (tc->con_dev) {
coresight_set_assoc_ectdev_mutex(tc->con_dev,
 NULL);
-   cti_remove_sysfs_link(tc);
+   cti_remove_sysfs_link(drvdata, tc);
tc->con_dev = NULL;
}
}
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



Re: [PATCH RESEND 1/9] crypto: caam/jr - add fallback for XTS with more than 8B IV

2020-08-20 Thread Herbert Xu
On Thu, Aug 06, 2020 at 07:35:43PM +0300, Andrei Botila wrote:
>
> +static bool xts_skcipher_ivsize(struct skcipher_request *req)
> +{
> + struct crypto_skcipher *skcipher = crypto_skcipher_reqtfm(req);
> + unsigned int ivsize = crypto_skcipher_ivsize(skcipher);
> + u64 size = 0;
> +
> + if (IS_ALIGNED((unsigned long)req->iv, __alignof__(u64)))
> + size = *(u64 *)(req->iv + (ivsize / 2));
> + else
> + size = get_unaligned((u64 *)(req->iv + (ivsize / 2)));
> +
> + return !!size;
> +}

Just go with the get_unaligned unconditionally.

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


[PATCH v10 15/24] coresight: allow replicator driver to be built as module

2020-08-20 Thread Tingwei Zhang
From: Kim Phillips 

Allow to build coresight-replicator as modules, for ease of development.

- Kconfig becomes a tristate, to allow =m
- combine static and dynamic replicator init into single
  module_init/exit call
- add replicator_remove functions, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Co-developed-by: Mian Yousaf Kaukab 
Signed-off-by: Mian Yousaf Kaukab 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
---
 drivers/hwtracing/coresight/Kconfig   |  5 +-
 .../coresight/coresight-replicator.c  | 65 ++-
 2 files changed, 67 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/Kconfig 
b/drivers/hwtracing/coresight/Kconfig
index fc48ae086746..f31778dd0b5d 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -17,13 +17,16 @@ menuconfig CORESIGHT
 
 if CORESIGHT
 config CORESIGHT_LINKS_AND_SINKS
-   bool "CoreSight Link and Sink drivers"
+   tristate "CoreSight Link and Sink drivers"
help
  This enables support for CoreSight link and sink drivers that are
  responsible for transporting and collecting the trace data
  respectively.  Link and sinks are dynamically aggregated with a trace
  entity at run time to form a complete trace path.
 
+ To compile these drivers as modules, choose M here: the
+ modules will be called coresight-funnel and coresight-replicator.
+
 config CORESIGHT_LINK_AND_SINK_TMC
tristate "Coresight generic TMC driver"
 
diff --git a/drivers/hwtracing/coresight/coresight-replicator.c 
b/drivers/hwtracing/coresight/coresight-replicator.c
index 78acf29c49ca..62afdde0e5ea 100644
--- a/drivers/hwtracing/coresight/coresight-replicator.c
+++ b/drivers/hwtracing/coresight/coresight-replicator.c
@@ -291,6 +291,14 @@ static int replicator_probe(struct device *dev, struct 
resource *res)
return ret;
 }
 
+static int __exit replicator_remove(struct device *dev)
+{
+   struct replicator_drvdata *drvdata = dev_get_drvdata(dev);
+
+   coresight_unregister(drvdata->csdev);
+   return 0;
+}
+
 static int static_replicator_probe(struct platform_device *pdev)
 {
int ret;
@@ -310,6 +318,13 @@ static int static_replicator_probe(struct platform_device 
*pdev)
return ret;
 }
 
+static int __exit static_replicator_remove(struct platform_device *pdev)
+{
+   replicator_remove(>dev);
+   pm_runtime_disable(>dev);
+   return 0;
+}
+
 #ifdef CONFIG_PM
 static int replicator_runtime_suspend(struct device *dev)
 {
@@ -343,24 +358,29 @@ static const struct of_device_id 
static_replicator_match[] = {
{}
 };
 
+MODULE_DEVICE_TABLE(of, static_replicator_match);
+
 #ifdef CONFIG_ACPI
 static const struct acpi_device_id static_replicator_acpi_ids[] = {
{"ARMHC985", 0}, /* ARM CoreSight Static Replicator */
{}
 };
+
+MODULE_DEVICE_TABLE(acpi, static_replicator_acpi_ids);
 #endif
 
 static struct platform_driver static_replicator_driver = {
.probe  = static_replicator_probe,
+   .remove = static_replicator_remove,
.driver = {
.name   = "coresight-static-replicator",
+   .owner  = THIS_MODULE,
.of_match_table = of_match_ptr(static_replicator_match),
.acpi_match_table = ACPI_PTR(static_replicator_acpi_ids),
.pm = _dev_pm_ops,
.suppress_bind_attrs = true,
},
 };
-builtin_platform_driver(static_replicator_driver);
 
 static int dynamic_replicator_probe(struct amba_device *adev,
const struct amba_id *id)
@@ -368,19 +388,60 @@ static int dynamic_replicator_probe(struct amba_device 
*adev,
return replicator_probe(>dev, >res);
 }
 
+static int __exit dynamic_replicator_remove(struct amba_device *adev)
+{
+   return replicator_remove(>dev);
+}
+
 static const struct amba_id dynamic_replicator_ids[] = {
CS_AMBA_ID(0x000bb909),
CS_AMBA_ID(0x000bb9ec), /* Coresight SoC-600 */
{},
 };
 
+MODULE_DEVICE_TABLE(amba, dynamic_replicator_ids);
+
 static struct amba_driver dynamic_replicator_driver = {
.drv = {
.name   = "coresight-dynamic-replicator",
.pm = _dev_pm_ops,
+   .owner  = THIS_MODULE,
.suppress_bind_attrs = true,
},
.probe  = dynamic_replicator_probe,
+   .remove = dynamic_replicator_remove,
.id_table   = dynamic_replicator_ids,
 };
-builtin_amba_driver(dynamic_replicator_driver);
+
+static int __init replicator_init(void)
+{
+   int ret;
+
+   ret = platform_driver_register(_replicator_driver);
+   if (ret) {
+   pr_info("Error 

[PATCH v10 13/24] coresight: tmc: allow tmc to be built as a module

2020-08-20 Thread Tingwei Zhang
From: Kim Phillips 

Allow to build coresight-tmc as a module, for ease of development.

- Kconfig becomes a tristate, to allow =m
- append -core to source file name to allow module to
  be called coresight-tmc by the Makefile
- add an tmc_remove function, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/Kconfig   |  6 -
 drivers/hwtracing/coresight/Makefile  |  6 ++---
 .../{coresight-tmc.c => coresight-tmc-core.c} | 25 ++-
 3 files changed, 32 insertions(+), 5 deletions(-)
 rename drivers/hwtracing/coresight/{coresight-tmc.c => coresight-tmc-core.c} 
(95%)

diff --git a/drivers/hwtracing/coresight/Kconfig 
b/drivers/hwtracing/coresight/Kconfig
index 8fd9887fb03b..fc48ae086746 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -25,7 +25,8 @@ config CORESIGHT_LINKS_AND_SINKS
  entity at run time to form a complete trace path.
 
 config CORESIGHT_LINK_AND_SINK_TMC
-   bool "Coresight generic TMC driver"
+   tristate "Coresight generic TMC driver"
+
depends on CORESIGHT_LINKS_AND_SINKS
help
  This enables support for the Trace Memory Controller driver.
@@ -34,6 +35,9 @@ config CORESIGHT_LINK_AND_SINK_TMC
  complies with the generic implementation of the component without
  special enhancement or added features.
 
+ To compile this driver as a module, choose M here: the
+ module will be called coresight-tmc.
+
 config CORESIGHT_CATU
bool "Coresight Address Translation Unit (CATU) driver"
depends on CORESIGHT_LINK_AND_SINK_TMC
diff --git a/drivers/hwtracing/coresight/Makefile 
b/drivers/hwtracing/coresight/Makefile
index 271dc255454f..f2a568b969c4 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -4,9 +4,9 @@
 #
 obj-$(CONFIG_CORESIGHT) += coresight.o coresight-etm-perf.o \
   coresight-platform.o coresight-sysfs.o
-obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o \
-coresight-tmc-etf.o \
-coresight-tmc-etr.o
+obj-$(CONFIG_CORESIGHT_LINK_AND_SINK_TMC) += coresight-tmc.o
+coresight-tmc-y := coresight-tmc-core.o coresight-tmc-etf.o \
+ coresight-tmc-etr.o
 obj-$(CONFIG_CORESIGHT_SINK_TPIU) += coresight-tpiu.o
 obj-$(CONFIG_CORESIGHT_SINK_ETBV10) += coresight-etb10.o
 obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \
diff --git a/drivers/hwtracing/coresight/coresight-tmc.c 
b/drivers/hwtracing/coresight/coresight-tmc-core.c
similarity index 95%
rename from drivers/hwtracing/coresight/coresight-tmc.c
rename to drivers/hwtracing/coresight/coresight-tmc-core.c
index 7040d583bed9..c268fafb3f32 100644
--- a/drivers/hwtracing/coresight/coresight-tmc.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-core.c
@@ -561,6 +561,21 @@ static void tmc_shutdown(struct amba_device *adev)
spin_unlock_irqrestore(>spinlock, flags);
 }
 
+static int __exit tmc_remove(struct amba_device *adev)
+{
+   struct tmc_drvdata *drvdata = dev_get_drvdata(>dev);
+
+   /*
+* Since misc_open() holds a refcount on the f_ops, which is
+* etb fops in this case, device is there until last file
+* handler to this device is closed.
+*/
+   misc_deregister(>miscdev);
+   coresight_unregister(drvdata->csdev);
+
+   return 0;
+}
+
 static const struct amba_id tmc_ids[] = {
CS_AMBA_ID(0x000bb961),
/* Coresight SoC 600 TMC-ETR/ETS */
@@ -572,6 +587,8 @@ static const struct amba_id tmc_ids[] = {
{ 0, 0},
 };
 
+MODULE_DEVICE_TABLE(amba, tmc_ids);
+
 static struct amba_driver tmc_driver = {
.drv = {
.name   = "coresight-tmc",
@@ -580,6 +597,12 @@ static struct amba_driver tmc_driver = {
},
.probe  = tmc_probe,
.shutdown   = tmc_shutdown,
+   .remove = tmc_remove,
.id_table   = tmc_ids,
 };
-builtin_amba_driver(tmc_driver);
+
+module_amba_driver(tmc_driver);
+
+MODULE_AUTHOR("Pratik Patel ");
+MODULE_DESCRIPTION("Arm CoreSight Trace Memory Controller driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 16/24] coresight: cti: add function to register cti associate ops

2020-08-20 Thread Tingwei Zhang
Add static cti_assoc_ops to coresight core driver. Let cti
driver register the add_assoc and remove_assoc call back.
Avoid coresight core driver to depend on cti driver.

Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reported-by: kernel test robot 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/coresight-cti.c  | 36 +---
 drivers/hwtracing/coresight/coresight-priv.h | 14 
 drivers/hwtracing/coresight/coresight.c  | 21 ++--
 3 files changed, 55 insertions(+), 16 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-cti.c 
b/drivers/hwtracing/coresight/coresight-cti.c
index 3ccc703dc940..b031c9dbe026 100644
--- a/drivers/hwtracing/coresight/coresight-cti.c
+++ b/drivers/hwtracing/coresight/coresight-cti.c
@@ -556,7 +556,7 @@ cti_match_fixup_csdev(struct cti_device *ctidev, const char 
*node_name,
  * This will set the association if CTI declared before the CS device.
  * (called from coresight_register() with coresight_mutex locked).
  */
-void cti_add_assoc_to_csdev(struct coresight_device *csdev)
+static void cti_add_assoc_to_csdev(struct coresight_device *csdev)
 {
struct cti_drvdata *ect_item;
struct cti_device *ctidev;
@@ -589,13 +589,12 @@ void cti_add_assoc_to_csdev(struct coresight_device 
*csdev)
 cti_add_done:
mutex_unlock(_mutex);
 }
-EXPORT_SYMBOL_GPL(cti_add_assoc_to_csdev);
 
 /*
  * Removing the associated devices is easier.
  * A CTI will not have a value for csdev->ect_dev.
  */
-void cti_remove_assoc_from_csdev(struct coresight_device *csdev)
+static void cti_remove_assoc_from_csdev(struct coresight_device *csdev)
 {
struct cti_drvdata *ctidrv;
struct cti_trig_con *tc;
@@ -616,7 +615,15 @@ void cti_remove_assoc_from_csdev(struct coresight_device 
*csdev)
}
mutex_unlock(_mutex);
 }
-EXPORT_SYMBOL_GPL(cti_remove_assoc_from_csdev);
+
+/*
+ * Operations to add and remove associated CTI.
+ * Register to coresight core driver as call back function.
+ */
+static struct cti_assoc_op cti_assoc_ops = {
+   .add = cti_add_assoc_to_csdev,
+   .remove = cti_remove_assoc_from_csdev
+};
 
 /*
  * Update the cross references where the associated device was found
@@ -972,4 +979,23 @@ static struct amba_driver cti_driver = {
.probe  = cti_probe,
.id_table   = cti_ids,
 };
-builtin_amba_driver(cti_driver);
+
+static int __init cti_init(void)
+{
+   int ret;
+
+   ret = amba_driver_register(_driver);
+   if (ret)
+   pr_info("Error registering cti driver\n");
+   coresight_set_cti_ops(_assoc_ops);
+   return ret;
+}
+
+static void __exit cti_exit(void)
+{
+   coresight_remove_cti_ops();
+   amba_driver_unregister(_driver);
+}
+
+module_init(cti_init);
+module_exit(cti_exit);
diff --git a/drivers/hwtracing/coresight/coresight-priv.h 
b/drivers/hwtracing/coresight/coresight-priv.h
index dcb8aeb6af62..6cde6cf42554 100644
--- a/drivers/hwtracing/coresight/coresight-priv.h
+++ b/drivers/hwtracing/coresight/coresight-priv.h
@@ -173,15 +173,13 @@ static inline int etm_readl_cp14(u32 off, unsigned int 
*val) { return 0; }
 static inline int etm_writel_cp14(u32 off, u32 val) { return 0; }
 #endif
 
-#ifdef CONFIG_CORESIGHT_CTI
-extern void cti_add_assoc_to_csdev(struct coresight_device *csdev);
-extern void cti_remove_assoc_from_csdev(struct coresight_device *csdev);
+struct cti_assoc_op {
+   void (*add)(struct coresight_device *csdev);
+   void (*remove)(struct coresight_device *csdev);
+};
 
-#else
-static inline void cti_add_assoc_to_csdev(struct coresight_device *csdev) {}
-static inline void
-cti_remove_assoc_from_csdev(struct coresight_device *csdev) {}
-#endif
+extern void coresight_set_cti_ops(const struct cti_assoc_op *cti_op);
+extern void coresight_remove_cti_ops(void);
 
 /*
  * Macros and inline functions to handle CoreSight UCI data and driver
diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index b040d4421f84..c2174fed263b 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -56,6 +56,20 @@ static struct list_head *stm_path;
 const u32 coresight_barrier_pkt[4] = {0x7fff, 0x7fff, 0x7fff, 
0x7fff};
 EXPORT_SYMBOL_GPL(coresight_barrier_pkt);
 
+static const struct cti_assoc_op *cti_assoc_ops;
+
+void coresight_set_cti_ops(const struct cti_assoc_op *cti_op)
+{
+   cti_assoc_ops = cti_op;
+}
+EXPORT_SYMBOL_GPL(coresight_set_cti_ops);
+
+void coresight_remove_cti_ops(void)
+{
+   cti_assoc_ops = NULL;
+}
+EXPORT_SYMBOL_GPL(coresight_remove_cti_ops);
+
 static int coresight_id_match(struct device *dev, void *data)
 {
int trace_id, i_trace_id;
@@ -1240,7 +1254,8 @@ static void coresight_device_release(struct device *dev)
 {
struct coresight_device *csdev = to_coresight_device(dev);
 
-   cti_remove_assoc_from_csdev(csdev);
+   if (cti_assoc_ops && 

[PATCH v10 08/24] coresight: etm: perf: Fix warning caused by etm_setup_aux failure

2020-08-20 Thread Tingwei Zhang
When coresight_build_path() fails on all the cpus, etm_setup_aux
calls etm_free_aux() to free allocated event_data.
WARN_ON(cpumask_empty(mask) will be triggered since cpu mask is empty.
Check event_data->snk_config is not NULL first to avoid this
warning.

Signed-off-by: Tingwei Zhang 
Reviewed-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/coresight-etm-perf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c 
b/drivers/hwtracing/coresight/coresight-etm-perf.c
index dcb0592418ae..3728c44e5763 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.c
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
@@ -126,10 +126,10 @@ static void free_sink_buffer(struct etm_event_data 
*event_data)
cpumask_t *mask = _data->mask;
struct coresight_device *sink;
 
-   if (WARN_ON(cpumask_empty(mask)))
+   if (!event_data->snk_config)
return;
 
-   if (!event_data->snk_config)
+   if (WARN_ON(cpumask_empty(mask)))
return;
 
cpu = cpumask_first(mask);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 12/24] coresight: tpiu: allow tpiu to be built as a module

2020-08-20 Thread Tingwei Zhang
From: Kim Phillips 

Allow to build coresight-tpiu as a module, for ease of development.

- Kconfig becomes a tristate, to allow =m
- add a tpiu_remove function, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Reviewed-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/Kconfig  |  5 -
 drivers/hwtracing/coresight/coresight-tpiu.c | 20 +++-
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/hwtracing/coresight/Kconfig 
b/drivers/hwtracing/coresight/Kconfig
index 996d84a1edb8..8fd9887fb03b 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -46,7 +46,7 @@ config CORESIGHT_CATU
   mode where the address is not translated.
 
 config CORESIGHT_SINK_TPIU
-   bool "Coresight generic TPIU driver"
+   tristate "Coresight generic TPIU driver"
depends on CORESIGHT_LINKS_AND_SINKS
help
  This enables support for the Trace Port Interface Unit driver,
@@ -56,6 +56,9 @@ config CORESIGHT_SINK_TPIU
  connected to an external host for use case capturing more traces than
  the on-board coresight memory can handle.
 
+ To compile this driver as a module, choose M here: the
+ module will be called coresight-tpiu.
+
 config CORESIGHT_SINK_ETBV10
tristate "Coresight ETBv1.0 driver"
depends on CORESIGHT_LINKS_AND_SINKS
diff --git a/drivers/hwtracing/coresight/coresight-tpiu.c 
b/drivers/hwtracing/coresight/coresight-tpiu.c
index f8583e4032a6..566c57e03596 100644
--- a/drivers/hwtracing/coresight/coresight-tpiu.c
+++ b/drivers/hwtracing/coresight/coresight-tpiu.c
@@ -173,6 +173,15 @@ static int tpiu_probe(struct amba_device *adev, const 
struct amba_id *id)
return PTR_ERR(drvdata->csdev);
 }
 
+static int __exit tpiu_remove(struct amba_device *adev)
+{
+   struct tpiu_drvdata *drvdata = dev_get_drvdata(>dev);
+
+   coresight_unregister(drvdata->csdev);
+
+   return 0;
+}
+
 #ifdef CONFIG_PM
 static int tpiu_runtime_suspend(struct device *dev)
 {
@@ -216,6 +225,8 @@ static const struct amba_id tpiu_ids[] = {
{ 0, 0},
 };
 
+MODULE_DEVICE_TABLE(amba, tpiu_ids);
+
 static struct amba_driver tpiu_driver = {
.drv = {
.name   = "coresight-tpiu",
@@ -224,6 +235,13 @@ static struct amba_driver tpiu_driver = {
.suppress_bind_attrs = true,
},
.probe  = tpiu_probe,
+   .remove = tpiu_remove,
.id_table   = tpiu_ids,
 };
-builtin_amba_driver(tpiu_driver);
+
+module_amba_driver(tpiu_driver);
+
+MODULE_AUTHOR("Pratik Patel ");
+MODULE_AUTHOR("Mathieu Poirier ");
+MODULE_DESCRIPTION("Arm CoreSight TPIU (Trace Port Interface Unit) driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 03/24] coresight: use IS_ENABLED for CONFIGs that may be modules

2020-08-20 Thread Tingwei Zhang
From: Kim Phillips 

Checking for ifdef CONFIG_x fails if CONFIG_x=m.  Use IS_ENABLED
that is true for both built-ins and modules, instead.  Required
when building coresight components as modules.

Cc: Mathieu Poirier 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/coresight-etm-perf.h | 2 +-
 drivers/hwtracing/coresight/coresight-priv.h | 2 +-
 include/linux/coresight.h| 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.h 
b/drivers/hwtracing/coresight/coresight-etm-perf.h
index 015213abe00a..05f89723e282 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.h
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.h
@@ -57,7 +57,7 @@ struct etm_event_data {
struct list_head * __percpu *path;
 };
 
-#ifdef CONFIG_CORESIGHT
+#if IS_ENABLED(CONFIG_CORESIGHT)
 int etm_perf_symlink(struct coresight_device *csdev, bool link);
 int etm_perf_add_symlink_sink(struct coresight_device *csdev);
 void etm_perf_del_symlink_sink(struct coresight_device *csdev);
diff --git a/drivers/hwtracing/coresight/coresight-priv.h 
b/drivers/hwtracing/coresight/coresight-priv.h
index f2dc625ea585..d801a2755432 100644
--- a/drivers/hwtracing/coresight/coresight-priv.h
+++ b/drivers/hwtracing/coresight/coresight-priv.h
@@ -165,7 +165,7 @@ int coresight_make_links(struct coresight_device *orig,
 void coresight_remove_links(struct coresight_device *orig,
struct coresight_connection *conn);
 
-#ifdef CONFIG_CORESIGHT_SOURCE_ETM3X
+#if IS_ENABLED(CONFIG_CORESIGHT_SOURCE_ETM3X)
 extern int etm_readl_cp14(u32 off, unsigned int *val);
 extern int etm_writel_cp14(u32 off, u32 val);
 #else
diff --git a/include/linux/coresight.h b/include/linux/coresight.h
index 58fffdecdbfd..3bb738f9a326 100644
--- a/include/linux/coresight.h
+++ b/include/linux/coresight.h
@@ -324,7 +324,7 @@ struct coresight_ops {
const struct coresight_ops_ect *ect_ops;
 };
 
-#ifdef CONFIG_CORESIGHT
+#if IS_ENABLED(CONFIG_CORESIGHT)
 extern struct coresight_device *
 coresight_register(struct coresight_desc *desc);
 extern void coresight_unregister(struct coresight_device *csdev);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 04/24] coresight: add coresight prefix to barrier_pkt

2020-08-20 Thread Tingwei Zhang
Add coresight prefix to make it specific. It will be a export symbol.

Signed-off-by: Mian Yousaf Kaukab 
Signed-off-by: Tingwei Zhang 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/coresight-etb10.c   | 2 +-
 drivers/hwtracing/coresight/coresight-priv.h| 8 
 drivers/hwtracing/coresight/coresight-tmc-etf.c | 2 +-
 drivers/hwtracing/coresight/coresight.c | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-etb10.c 
b/drivers/hwtracing/coresight/coresight-etb10.c
index 03e3f2590191..04ee9cda988d 100644
--- a/drivers/hwtracing/coresight/coresight-etb10.c
+++ b/drivers/hwtracing/coresight/coresight-etb10.c
@@ -525,7 +525,7 @@ static unsigned long etb_update_buffer(struct 
coresight_device *csdev,
 
cur = buf->cur;
offset = buf->offset;
-   barrier = barrier_pkt;
+   barrier = coresight_barrier_pkt;
 
for (i = 0; i < to_read; i += 4) {
buf_ptr = buf->data_pages[cur] + offset;
diff --git a/drivers/hwtracing/coresight/coresight-priv.h 
b/drivers/hwtracing/coresight/coresight-priv.h
index d801a2755432..dcb8aeb6af62 100644
--- a/drivers/hwtracing/coresight/coresight-priv.h
+++ b/drivers/hwtracing/coresight/coresight-priv.h
@@ -66,8 +66,8 @@ static DEVICE_ATTR_RO(name)
 #define coresight_simple_reg64(type, name, lo_off, hi_off) \
__coresight_simple_func(type, NULL, name, lo_off, hi_off)
 
-extern const u32 barrier_pkt[4];
-#define CORESIGHT_BARRIER_PKT_SIZE (sizeof(barrier_pkt))
+extern const u32 coresight_barrier_pkt[4];
+#define CORESIGHT_BARRIER_PKT_SIZE (sizeof(coresight_barrier_pkt))
 
 enum etm_addr_type {
ETM_ADDR_TYPE_NONE,
@@ -104,10 +104,10 @@ struct cs_buffers {
 static inline void coresight_insert_barrier_packet(void *buf)
 {
if (buf)
-   memcpy(buf, barrier_pkt, CORESIGHT_BARRIER_PKT_SIZE);
+   memcpy(buf, coresight_barrier_pkt,
+   CORESIGHT_BARRIER_PKT_SIZE);
 }
 
-
 static inline void CS_LOCK(void __iomem *addr)
 {
do {
diff --git a/drivers/hwtracing/coresight/coresight-tmc-etf.c 
b/drivers/hwtracing/coresight/coresight-tmc-etf.c
index 6375504ba8b0..44402d413ebb 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-etf.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-etf.c
@@ -519,7 +519,7 @@ static unsigned long tmc_update_etf_buffer(struct 
coresight_device *csdev,
 
cur = buf->cur;
offset = buf->offset;
-   barrier = barrier_pkt;
+   barrier = coresight_barrier_pkt;
 
/* for every byte to read */
for (i = 0; i < to_read; i += 4) {
diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index e9c90f2de34a..d515088cc47d 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -53,7 +53,7 @@ static struct list_head *stm_path;
  * beginning of the data collected in a buffer.  That way the decoder knows 
that
  * it needs to look for another sync sequence.
  */
-const u32 barrier_pkt[4] = {0x7fff, 0x7fff, 0x7fff, 0x7fff};
+const u32 coresight_barrier_pkt[4] = {0x7fff, 0x7fff, 0x7fff, 
0x7fff};
 
 static int coresight_id_match(struct device *dev, void *data)
 {
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 05/24] coresight: export global symbols

2020-08-20 Thread Tingwei Zhang
From: Mian Yousaf Kaukab 

Export symbols used among coresight modules.

Signed-off-by: Mian Yousaf Kaukab 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/coresight-etm-perf.c | 1 +
 drivers/hwtracing/coresight/coresight-sysfs.c| 2 ++
 drivers/hwtracing/coresight/coresight-tmc-etr.c  | 6 ++
 drivers/hwtracing/coresight/coresight.c  | 8 
 4 files changed, 17 insertions(+)

diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c 
b/drivers/hwtracing/coresight/coresight-etm-perf.c
index 1a3169e69bb1..dcb0592418ae 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.c
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
@@ -517,6 +517,7 @@ int etm_perf_symlink(struct coresight_device *csdev, bool 
link)
 
return 0;
 }
+EXPORT_SYMBOL_GPL(etm_perf_symlink);
 
 static ssize_t etm_perf_sink_name_show(struct device *dev,
   struct device_attribute *dattr,
diff --git a/drivers/hwtracing/coresight/coresight-sysfs.c 
b/drivers/hwtracing/coresight/coresight-sysfs.c
index 82afeaf2ccc4..34d2a2d31d00 100644
--- a/drivers/hwtracing/coresight/coresight-sysfs.c
+++ b/drivers/hwtracing/coresight/coresight-sysfs.c
@@ -102,6 +102,7 @@ int coresight_add_sysfs_link(struct coresight_sysfs_link 
*info)
 
return ret;
 }
+EXPORT_SYMBOL_GPL(coresight_add_sysfs_link);
 
 void coresight_remove_sysfs_link(struct coresight_sysfs_link *info)
 {
@@ -122,6 +123,7 @@ void coresight_remove_sysfs_link(struct 
coresight_sysfs_link *info)
info->orig->nr_links--;
info->target->nr_links--;
 }
+EXPORT_SYMBOL_GPL(coresight_remove_sysfs_link);
 
 /*
  * coresight_make_links: Make a link for a connection from a @orig
diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c 
b/drivers/hwtracing/coresight/coresight-tmc-etr.c
index b29c2db94d96..ad991a37e2d2 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-etr.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c
@@ -255,6 +255,7 @@ void tmc_free_sg_table(struct tmc_sg_table *sg_table)
tmc_free_table_pages(sg_table);
tmc_free_data_pages(sg_table);
 }
+EXPORT_SYMBOL_GPL(tmc_free_sg_table);
 
 /*
  * Alloc pages for the table. Since this will be used by the device,
@@ -340,6 +341,7 @@ struct tmc_sg_table *tmc_alloc_sg_table(struct device *dev,
 
return sg_table;
 }
+EXPORT_SYMBOL_GPL(tmc_alloc_sg_table);
 
 /*
  * tmc_sg_table_sync_data_range: Sync the data buffer written
@@ -360,6 +362,7 @@ void tmc_sg_table_sync_data_range(struct tmc_sg_table 
*table,
PAGE_SIZE, DMA_FROM_DEVICE);
}
 }
+EXPORT_SYMBOL_GPL(tmc_sg_table_sync_data_range);
 
 /* tmc_sg_sync_table: Sync the page table */
 void tmc_sg_table_sync_table(struct tmc_sg_table *sg_table)
@@ -372,6 +375,7 @@ void tmc_sg_table_sync_table(struct tmc_sg_table *sg_table)
dma_sync_single_for_device(real_dev, table_pages->daddrs[i],
   PAGE_SIZE, DMA_TO_DEVICE);
 }
+EXPORT_SYMBOL_GPL(tmc_sg_table_sync_table);
 
 /*
  * tmc_sg_table_get_data: Get the buffer pointer for data @offset
@@ -401,6 +405,7 @@ ssize_t tmc_sg_table_get_data(struct tmc_sg_table *sg_table,
*bufpp = page_address(data_pages->pages[pg_idx]) + pg_offset;
return len;
 }
+EXPORT_SYMBOL_GPL(tmc_sg_table_get_data);
 
 #ifdef ETR_SG_DEBUG
 /* Map a dma address to virtual address */
@@ -766,6 +771,7 @@ tmc_etr_get_catu_device(struct tmc_drvdata *drvdata)
 
return NULL;
 }
+EXPORT_SYMBOL_GPL(tmc_etr_get_catu_device);
 
 static inline int tmc_etr_enable_catu(struct tmc_drvdata *drvdata,
  struct etr_buf *etr_buf)
diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index d515088cc47d..cd17aea6b50d 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -54,6 +54,7 @@ static struct list_head *stm_path;
  * it needs to look for another sync sequence.
  */
 const u32 coresight_barrier_pkt[4] = {0x7fff, 0x7fff, 0x7fff, 
0x7fff};
+EXPORT_SYMBOL_GPL(coresight_barrier_pkt);
 
 static int coresight_id_match(struct device *dev, void *data)
 {
@@ -179,6 +180,7 @@ int coresight_claim_device_unlocked(void __iomem *base)
coresight_clear_claim_tags(base);
return -EBUSY;
 }
+EXPORT_SYMBOL_GPL(coresight_claim_device_unlocked);
 
 int coresight_claim_device(void __iomem *base)
 {
@@ -190,6 +192,7 @@ int coresight_claim_device(void __iomem *base)
 
return rc;
 }
+EXPORT_SYMBOL_GPL(coresight_claim_device);
 
 /*
  * coresight_disclaim_device_unlocked : Clear the claim tags for the device.
@@ -208,6 +211,7 @@ void coresight_disclaim_device_unlocked(void __iomem *base)
 */
WARN_ON_ONCE(1);
 }
+EXPORT_SYMBOL_GPL(coresight_disclaim_device_unlocked);
 
 void 

[PATCH v10 09/24] coresight: etm3x: allow etm3x to be built as a module

2020-08-20 Thread Tingwei Zhang
From: Kim Phillips 

Allow to build coresight-etm3x as a module, for ease of development.

- Kconfig becomes a tristate, to allow =m
- append -core to source file name to allow module to
  be called coresight-etm3x by the Makefile
- add an etm_remove function, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Reviewed-by: Mike Leach 
---
 drivers/hwtracing/coresight/Kconfig   |  5 +++-
 drivers/hwtracing/coresight/Makefile  |  3 +-
 ...resight-etm3x.c => coresight-etm3x-core.c} | 28 ++-
 3 files changed, 33 insertions(+), 3 deletions(-)
 rename drivers/hwtracing/coresight/{coresight-etm3x.c => 
coresight-etm3x-core.c} (97%)

diff --git a/drivers/hwtracing/coresight/Kconfig 
b/drivers/hwtracing/coresight/Kconfig
index 6433f835fc97..8fd9fd139cf3 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -65,7 +65,7 @@ config CORESIGHT_SINK_ETBV10
  special enhancement or added features.
 
 config CORESIGHT_SOURCE_ETM3X
-   bool "CoreSight Embedded Trace Macrocell 3.x driver"
+   tristate "CoreSight Embedded Trace Macrocell 3.x driver"
depends on !ARM64
select CORESIGHT_LINKS_AND_SINKS
help
@@ -74,6 +74,9 @@ config CORESIGHT_SOURCE_ETM3X
  This is primarily useful for instruction level tracing.  Depending
  the ETM version data tracing may also be available.
 
+ To compile this driver as a module, choose M here: the
+ module will be called coresight-etm3x.
+
 config CORESIGHT_SOURCE_ETM4X
bool "CoreSight Embedded Trace Macrocell 4.x driver"
depends on ARM64
diff --git a/drivers/hwtracing/coresight/Makefile 
b/drivers/hwtracing/coresight/Makefile
index 19497d1d92bf..d619cfd0abd8 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -11,7 +11,8 @@ obj-$(CONFIG_CORESIGHT_SINK_TPIU) += coresight-tpiu.o
 obj-$(CONFIG_CORESIGHT_SINK_ETBV10) += coresight-etb10.o
 obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \
   coresight-replicator.o
-obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o coresight-etm-cp14.o 
\
+obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
+coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
coresight-etm3x-sysfs.o
 obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
coresight-etm4x-sysfs.o
diff --git a/drivers/hwtracing/coresight/coresight-etm3x.c 
b/drivers/hwtracing/coresight/coresight-etm3x-core.c
similarity index 97%
rename from drivers/hwtracing/coresight/coresight-etm3x.c
rename to drivers/hwtracing/coresight/coresight-etm3x-core.c
index bf22dcfd3327..ba9c86497acb 100644
--- a/drivers/hwtracing/coresight/coresight-etm3x.c
+++ b/drivers/hwtracing/coresight/coresight-etm3x-core.c
@@ -895,6 +895,23 @@ static int etm_probe(struct amba_device *adev, const 
struct amba_id *id)
return ret;
 }
 
+static int __exit etm_remove(struct amba_device *adev)
+{
+   struct etm_drvdata *drvdata = dev_get_drvdata(>dev);
+
+   etm_perf_symlink(drvdata->csdev, false);
+
+   if (--etm_count == 0) {
+   cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
+   if (hp_online)
+   cpuhp_remove_state_nocalls(hp_online);
+   }
+
+   coresight_unregister(drvdata->csdev);
+
+   return 0;
+}
+
 #ifdef CONFIG_PM
 static int etm_runtime_suspend(struct device *dev)
 {
@@ -937,6 +954,8 @@ static const struct amba_id etm_ids[] = {
{ 0, 0},
 };
 
+MODULE_DEVICE_TABLE(amba, etm_ids);
+
 static struct amba_driver etm_driver = {
.drv = {
.name   = "coresight-etm3x",
@@ -945,6 +964,13 @@ static struct amba_driver etm_driver = {
.suppress_bind_attrs = true,
},
.probe  = etm_probe,
+   .remove = etm_remove,
.id_table   = etm_ids,
 };
-builtin_amba_driver(etm_driver);
+
+module_amba_driver(etm_driver);
+
+MODULE_AUTHOR("Pratik Patel ");
+MODULE_AUTHOR("Mathieu Poirier ");
+MODULE_DESCRIPTION("Arm CoreSight Program Flow Trace driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 10/24] coresight: etm4x: allow etm4x to be built as a module

2020-08-20 Thread Tingwei Zhang
From: Kim Phillips 

Allow to build coresight-etm4x as a module, for ease of development.

- Kconfig becomes a tristate, to allow =m
- append -core to source file name to allow module to
  be called coresight-etm4x by the Makefile
- add an etm4_remove function, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot
- delay advertising the per-cpu etmdrvdata
- protect etmdrvdata[] by modifying it on relevant CPU

Cc: Mathieu Poirier 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Suggested-by: Suzuki K Poulose 
---
 drivers/hwtracing/coresight/Kconfig   |  5 +-
 drivers/hwtracing/coresight/Makefile  |  4 +-
 ...resight-etm4x.c => coresight-etm4x-core.c} | 84 ++-
 3 files changed, 69 insertions(+), 24 deletions(-)
 rename drivers/hwtracing/coresight/{coresight-etm4x.c => 
coresight-etm4x-core.c} (96%)

diff --git a/drivers/hwtracing/coresight/Kconfig 
b/drivers/hwtracing/coresight/Kconfig
index 8fd9fd139cf3..d6e107bbd30b 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -78,7 +78,7 @@ config CORESIGHT_SOURCE_ETM3X
  module will be called coresight-etm3x.
 
 config CORESIGHT_SOURCE_ETM4X
-   bool "CoreSight Embedded Trace Macrocell 4.x driver"
+   tristate "CoreSight Embedded Trace Macrocell 4.x driver"
depends on ARM64
select CORESIGHT_LINKS_AND_SINKS
select PID_IN_CONTEXTIDR
@@ -88,6 +88,9 @@ config CORESIGHT_SOURCE_ETM4X
  for instruction level tracing. Depending on the implemented version
  data tracing may also be available.
 
+ To compile this driver as a module, choose M here: the
+ module will be called coresight-etm4x.
+
 config CORESIGHT_STM
tristate "CoreSight System Trace Macrocell driver"
depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) || ARM64
diff --git a/drivers/hwtracing/coresight/Makefile 
b/drivers/hwtracing/coresight/Makefile
index d619cfd0abd8..271dc255454f 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -14,8 +14,8 @@ obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o 
\
 obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
 coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
coresight-etm3x-sysfs.o
-obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
-   coresight-etm4x-sysfs.o
+obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o
+coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o
 obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
 obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
 obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c 
b/drivers/hwtracing/coresight/coresight-etm4x-core.c
similarity index 96%
rename from drivers/hwtracing/coresight/coresight-etm4x.c
rename to drivers/hwtracing/coresight/coresight-etm4x-core.c
index 8b0634ebef77..56aed38cd0fa 100644
--- a/drivers/hwtracing/coresight/coresight-etm4x.c
+++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
@@ -1430,7 +1430,7 @@ static int __init etm4_pm_setup(void)
return ret;
 }
 
-static void __init etm4_pm_clear(void)
+static void etm4_pm_clear(void)
 {
cpu_pm_unregister_notifier(_cpu_pm_nb);
cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
@@ -1487,25 +1487,20 @@ static int etm4_probe(struct amba_device *adev, const 
struct amba_id *id)
if (!desc.name)
return -ENOMEM;
 
-   etmdrvdata[drvdata->cpu] = drvdata;
-
if (smp_call_function_single(drvdata->cpu,
etm4_init_arch_data,  drvdata, 1))
dev_err(dev, "ETM arch init failed\n");
 
-   if (etm4_arch_supported(drvdata->arch) == false) {
-   ret = -EINVAL;
-   goto err_arch_supported;
-   }
+   if (etm4_arch_supported(drvdata->arch) == false)
+   return -EINVAL;
 
etm4_init_trace_id(drvdata);
etm4_set_default(>config);
 
pdata = coresight_get_platform_data(dev);
-   if (IS_ERR(pdata)) {
-   ret = PTR_ERR(pdata);
-   goto err_arch_supported;
-   }
+   if (IS_ERR(pdata))
+   return PTR_ERR(pdata);
+
adev->dev.platform_data = pdata;
 
desc.type = CORESIGHT_DEV_TYPE_SOURCE;
@@ -1515,17 +1510,17 @@ static int etm4_probe(struct amba_device *adev, const 
struct amba_id *id)
desc.dev = dev;
desc.groups = coresight_etmv4_groups;
drvdata->csdev = coresight_register();
-   if (IS_ERR(drvdata->csdev)) {
-   ret = PTR_ERR(drvdata->csdev);
-   goto err_arch_supported;
-   }
+   if 

[PATCH v10 11/24] coresight: etb: allow etb to be built as a module

2020-08-20 Thread Tingwei Zhang
From: Kim Phillips 

Allow to build coresight-etb10 as a module, for ease of development.

- Kconfig becomes a tristate, to allow =m
- add an etb_remove function, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/Kconfig   |  5 +++-
 drivers/hwtracing/coresight/coresight-etb10.c | 26 ++-
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/drivers/hwtracing/coresight/Kconfig 
b/drivers/hwtracing/coresight/Kconfig
index d6e107bbd30b..996d84a1edb8 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -57,13 +57,16 @@ config CORESIGHT_SINK_TPIU
  the on-board coresight memory can handle.
 
 config CORESIGHT_SINK_ETBV10
-   bool "Coresight ETBv1.0 driver"
+   tristate "Coresight ETBv1.0 driver"
depends on CORESIGHT_LINKS_AND_SINKS
help
  This enables support for the Embedded Trace Buffer version 1.0 driver
  that complies with the generic implementation of the component without
  special enhancement or added features.
 
+ To compile this driver as a module, choose M here: the
+ module will be called coresight-etb10.
+
 config CORESIGHT_SOURCE_ETM3X
tristate "CoreSight Embedded Trace Macrocell 3.x driver"
depends on !ARM64
diff --git a/drivers/hwtracing/coresight/coresight-etb10.c 
b/drivers/hwtracing/coresight/coresight-etb10.c
index 04ee9cda988d..248cc82c838e 100644
--- a/drivers/hwtracing/coresight/coresight-etb10.c
+++ b/drivers/hwtracing/coresight/coresight-etb10.c
@@ -801,6 +801,21 @@ static int etb_probe(struct amba_device *adev, const 
struct amba_id *id)
return ret;
 }
 
+static int __exit etb_remove(struct amba_device *adev)
+{
+   struct etb_drvdata *drvdata = dev_get_drvdata(>dev);
+
+   /*
+* Since misc_open() holds a refcount on the f_ops, which is
+* etb fops in this case, device is there until last file
+* handler to this device is closed.
+*/
+   misc_deregister(>miscdev);
+   coresight_unregister(drvdata->csdev);
+
+   return 0;
+}
+
 #ifdef CONFIG_PM
 static int etb_runtime_suspend(struct device *dev)
 {
@@ -835,6 +850,8 @@ static const struct amba_id etb_ids[] = {
{ 0, 0},
 };
 
+MODULE_DEVICE_TABLE(amba, etb_ids);
+
 static struct amba_driver etb_driver = {
.drv = {
.name   = "coresight-etb10",
@@ -844,6 +861,13 @@ static struct amba_driver etb_driver = {
 
},
.probe  = etb_probe,
+   .remove = etb_remove,
.id_table   = etb_ids,
 };
-builtin_amba_driver(etb_driver);
+
+module_amba_driver(etb_driver);
+
+MODULE_AUTHOR("Pratik Patel ");
+MODULE_AUTHOR("Mathieu Poirier ");
+MODULE_DESCRIPTION("Arm CoreSight Embedded Trace Buffer driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 06/24] coresight: add try_get_module() in coresight_grab_device()

2020-08-20 Thread Tingwei Zhang
When coresight device is in an active session, driver module of
that device should not be removed. Use try_get_module() in
coresight_grab_device() to prevent module to be unloaded.
Use get_device()/put_device() to protect device data
in the middle of active session.

Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Suggested-by: Suzuki K Poulose 
---
 drivers/hwtracing/coresight/coresight.c | 60 ++---
 1 file changed, 53 insertions(+), 7 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight.c 
b/drivers/hwtracing/coresight/coresight.c
index cd17aea6b50d..b040d4421f84 100644
--- a/drivers/hwtracing/coresight/coresight.c
+++ b/drivers/hwtracing/coresight/coresight.c
@@ -633,13 +633,45 @@ struct coresight_device *coresight_get_sink_by_id(u32 id)
return dev ? to_coresight_device(dev) : NULL;
 }
 
+/**
+ * coresight_get_ref- Helper function to increase reference count to module
+ * and device.
+ * Return true in successful case and power up the device.
+ * Return false when failed to get reference of module.
+ */
+static inline bool coresight_get_ref(struct coresight_device *csdev)
+{
+   struct device *dev = csdev->dev.parent;
+
+   /* Make sure the driver can't be removed */
+   if (!try_module_get(dev->driver->owner))
+   return false;
+   /* Make sure the device can't go away */
+   get_device(dev);
+   pm_runtime_get_sync(dev);
+   return true;
+}
+
+/**
+ * coresight_put_ref- Helper function to decrease reference count to module
+ * and device. Power off the device.
+ */
+static inline void coresight_put_ref(struct coresight_device *csdev)
+{
+   struct device *dev = csdev->dev.parent;
+
+   pm_runtime_put(dev);
+   put_device(dev);
+   module_put(dev->driver->owner);
+}
+
 /*
  * coresight_grab_device - Power up this device and any of the helper
  * devices connected to it for trace operation. Since the helper devices
  * don't appear on the trace path, they should be handled along with the
  * the master device.
  */
-static void coresight_grab_device(struct coresight_device *csdev)
+static int coresight_grab_device(struct coresight_device *csdev)
 {
int i;
 
@@ -648,9 +680,20 @@ static void coresight_grab_device(struct coresight_device 
*csdev)
 
child  = csdev->pdata->conns[i].child_dev;
if (child && child->type == CORESIGHT_DEV_TYPE_HELPER)
-   pm_runtime_get_sync(child->dev.parent);
+   if (!coresight_get_ref(child))
+   goto err;
+   }
+   if (coresight_get_ref(csdev))
+   return 0;
+err:
+   for (i--; i >= 0; i--) {
+   struct coresight_device *child;
+
+   child  = csdev->pdata->conns[i].child_dev;
+   if (child && child->type == CORESIGHT_DEV_TYPE_HELPER)
+   coresight_put_ref(child);
}
-   pm_runtime_get_sync(csdev->dev.parent);
+   return -ENODEV;
 }
 
 /*
@@ -661,13 +704,13 @@ static void coresight_drop_device(struct coresight_device 
*csdev)
 {
int i;
 
-   pm_runtime_put(csdev->dev.parent);
+   coresight_put_ref(csdev);
for (i = 0; i < csdev->pdata->nr_outport; i++) {
struct coresight_device *child;
 
child  = csdev->pdata->conns[i].child_dev;
if (child && child->type == CORESIGHT_DEV_TYPE_HELPER)
-   pm_runtime_put(child->dev.parent);
+   coresight_put_ref(child);
}
 }
 
@@ -686,7 +729,7 @@ static int _coresight_build_path(struct coresight_device 
*csdev,
 struct coresight_device *sink,
 struct list_head *path)
 {
-   int i;
+   int i, ret;
bool found = false;
struct coresight_node *node;
 
@@ -716,11 +759,14 @@ static int _coresight_build_path(struct coresight_device 
*csdev,
 * is tell the PM runtime core we need this element and add a node
 * for it.
 */
+   ret = coresight_grab_device(csdev);
+   if (ret)
+   return ret;
+
node = kzalloc(sizeof(struct coresight_node), GFP_KERNEL);
if (!node)
return -ENOMEM;
 
-   coresight_grab_device(csdev);
node->csdev = csdev;
list_add(>link, path);
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 07/24] coresight: stm: allow to build coresight-stm as a module

2020-08-20 Thread Tingwei Zhang
- Kconfig becomes a tristate, to allow =m
- add a stm_remove function, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier 
Cc: Leo Yan 
Cc: Alexander Shishkin 
Cc: Randy Dunlap 
Cc: Suzuki K Poulose 
Cc: Greg Kroah-Hartman 
Cc: Russell King 
Signed-off-by: Kim Phillips 
Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/Kconfig |  5 -
 drivers/hwtracing/coresight/coresight-stm.c | 20 +++-
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/hwtracing/coresight/Kconfig 
b/drivers/hwtracing/coresight/Kconfig
index 4663fd1bbffc..6433f835fc97 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -86,7 +86,7 @@ config CORESIGHT_SOURCE_ETM4X
  data tracing may also be available.
 
 config CORESIGHT_STM
-   bool "CoreSight System Trace Macrocell driver"
+   tristate "CoreSight System Trace Macrocell driver"
depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) || ARM64
select CORESIGHT_LINKS_AND_SINKS
select STM
@@ -96,6 +96,9 @@ config CORESIGHT_STM
  logging useful software events or data coming from various entities
  in the system, possibly running different OSs
 
+ To compile this driver as a module, choose M here: the
+ module will be called coresight-stm.
+
 config CORESIGHT_CPU_DEBUG
tristate "CoreSight CPU Debug driver"
depends on ARM || ARM64
diff --git a/drivers/hwtracing/coresight/coresight-stm.c 
b/drivers/hwtracing/coresight/coresight-stm.c
index 2ba819a47cf6..b0ad912651a9 100644
--- a/drivers/hwtracing/coresight/coresight-stm.c
+++ b/drivers/hwtracing/coresight/coresight-stm.c
@@ -951,6 +951,17 @@ static int stm_probe(struct amba_device *adev, const 
struct amba_id *id)
return ret;
 }
 
+static int __exit stm_remove(struct amba_device *adev)
+{
+   struct stm_drvdata *drvdata = dev_get_drvdata(>dev);
+
+   coresight_unregister(drvdata->csdev);
+
+   stm_unregister_device(>stm);
+
+   return 0;
+}
+
 #ifdef CONFIG_PM
 static int stm_runtime_suspend(struct device *dev)
 {
@@ -983,6 +994,8 @@ static const struct amba_id stm_ids[] = {
{ 0, 0},
 };
 
+MODULE_DEVICE_TABLE(amba, stm_ids);
+
 static struct amba_driver stm_driver = {
.drv = {
.name   = "coresight-stm",
@@ -991,7 +1004,12 @@ static struct amba_driver stm_driver = {
.suppress_bind_attrs = true,
},
.probe  = stm_probe,
+   .remove = stm_remove,
.id_table   = stm_ids,
 };
 
-builtin_amba_driver(stm_driver);
+module_amba_driver(stm_driver);
+
+MODULE_AUTHOR("Pratik Patel ");
+MODULE_DESCRIPTION("Arm CoreSight System Trace Macrocell driver");
+MODULE_LICENSE("GPL v2");
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



Re: [PATCH 2/2] kconfig: qconf: replace depreacated QString::sprintf() with QTextStream

2020-08-20 Thread Masahiro Yamada
I will fix the typo in the subject.

"depreacated" -> "deprecated"




-- 
Best Regards
Masahiro Yamada


[PATCH v10 02/24] coresight: cpu_debug: define MODULE_DEVICE_TABLE

2020-08-20 Thread Tingwei Zhang
Define a MODULE_DEVICE_TABLE for cpu_debug so module can
be auto loaded on boot.

Signed-off-by: Tingwei Zhang 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/coresight-cpu-debug.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/hwtracing/coresight/coresight-cpu-debug.c 
b/drivers/hwtracing/coresight/coresight-cpu-debug.c
index 96544b348c27..1d0880b3764a 100644
--- a/drivers/hwtracing/coresight/coresight-cpu-debug.c
+++ b/drivers/hwtracing/coresight/coresight-cpu-debug.c
@@ -665,6 +665,8 @@ static const struct amba_id debug_ids[] = {
{},
 };
 
+MODULE_DEVICE_TABLE(amba, debug_ids);
+
 static struct amba_driver debug_driver = {
.drv = {
.name   = "coresight-cpu-debug",
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v10 00/24] coresight: allow to build coresight as modules

2020-08-20 Thread Tingwei Zhang
Allow to build coresight as modules. This gives developers the feasibility to
test their code without reboot.

This series is based on below two series.

 - "coresight: allow to build components as modules"
   https://lkml.org/lkml/2018/6/5/989
 - "coresight: make drivers modular"
   https://lkml.org/lkml/2020/1/17/468

Change from v9:
Fix warning reported by kernel test robot 
Rebase to coresight-next

Change from v8:
Protect etmdrvdata[] by modifying it on relevant CPU  (Mathieu and Suzuki)
Grab the device before allocating memory for the node (Mathieu)
Add author of coresight core driver (Mathieu)

Change from v7:
Depends on below change for ETM hotplug (Sai)
https://lore.kernel.org/linux-arm-kernel/20200729051310.18436-1-saiprakash.ran...@codeaurora.org/
Add mutex lock to protect etmdrvdata[] (Suzuki)
Add helper function coresight_get_ref() (Suzuki)
Reorg replicator and funnel change. Use two patches to support these
two drivers. (Suzuki)
Add fix tag to "coresight: etm: perf: Fix warning caused by etm_setup_aux
failure" (Suzuki)
Update author of "coresight: cti: Fix bug clearing sysfs links on callback"

Change from v6:
Correct module description for CATU (Mike)
Check ect_ret equals 0 and set ect_enabled flag (Mike)
Add Tested-by and Reviewed-by from Mike

Change from v5:
Add below CTI clean up change from Mike into series
 -https://lists.linaro.org/pipermail/coresight/2020-July/004349.html
Increase module reference count when enabling CTI device (Mike)

Change from v4:
Fix error handling in coresight_grab_devicei() (Greg)
Add coresight: cti: Fix remove sysfs link error from Mike
 -https://lists.linaro.org/pipermail/coresight/2020-July/004275.html
Move cti_remove_conn_xrefs() into cti_remove() (Mike)
Align patch subject to coresight: :  (Mike)

Change from v3:
Rebase to coresight-next (Mike and Mathieu)
Reorder try_get_module() (Suzuki)
Clean up etmdrvdata[] in device remote path (Mike)
Move cti_remove_conn_xrefs to cti_remove (Mike)

Change from v2:
Rebase to 5.8-rc5. Export coresight_add_sysfs_link and
coresight_remove_sysfs_link
Fix one cut and paste error on MODULE_DESCRIPTION of CTI

Change from v1:
Use try_module_get() to avoid module to be unloaded when device is used
in active trace session. (Mathieu P)

Change from above two series.
This series adds the support to dynamically remove module when the device in
that module is enabled and used by some trace path. It disables all trace
paths with that device and release the trace path.

Kim Phillips (8):
  coresight: use IS_ENABLED for CONFIGs that may be modules
  coresight: etm3x: allow etm3x to be built as a module
  coresight: etm4x: allow etm4x to be built as a module
  coresight: etb: allow etb to be built as a module
  coresight: tpiu: allow tpiu to be built as a module
  coresight: tmc: allow tmc to be built as a module
  coresight: allow funnel driver to be built as module
  coresight: allow replicator driver to be built as module

Mian Yousaf Kaukab (2):
  coresight: export global symbols
  coresight: tmc-etr: add function to register catu ops

Mike Leach (2):
  coresight: cti: Fix remove sysfs link error
  coresight: cti: Fix bug clearing sysfs links on callback

Tingwei Zhang (12):
  coresight: cpu_debug: add module name in Kconfig
  coresight: cpu_debug: define MODULE_DEVICE_TABLE
  coresight: add coresight prefix to barrier_pkt
  coresight: add try_get_module() in coresight_grab_device()
  coresight: stm: allow to build coresight-stm as a module
  coresight: etm: perf: Fix warning caused by etm_setup_aux failure
  coresight: cti: add function to register cti associate ops
  coresight: cti: don't disable ect device if it's not enabled
  coresight: cti: increase reference count when enabling cti
  coresight: cti: allow cti to be built as a module
  coresight: catu: allow catu drivers to be built as modules
  coresight: allow the coresight core driver to be built as a module

 drivers/hwtracing/coresight/Kconfig   |  54 --
 drivers/hwtracing/coresight/Makefile  |  22 +--
 drivers/hwtracing/coresight/coresight-catu.c  |  37 -
 drivers/hwtracing/coresight/coresight-catu.h  |   2 -
 .../{coresight.c => coresight-core.c} | 154 +++---
 .../hwtracing/coresight/coresight-cpu-debug.c |   2 +
 .../{coresight-cti.c => coresight-cti-core.c} |  67 ++--
 drivers/hwtracing/coresight/coresight-etb10.c |  28 +++-
 .../hwtracing/coresight/coresight-etm-perf.c  |  13 +-
 .../hwtracing/coresight/coresight-etm-perf.h  |   5 +-
 ...resight-etm3x.c => coresight-etm3x-core.c} |  28 +++-
 ...resight-etm4x.c => coresight-etm4x-core.c} |  84 +++---
 .../hwtracing/coresight/coresight-funnel.c|  64 +++-
 .../hwtracing/coresight/coresight-platform.c  |   1 +
 drivers/hwtracing/coresight/coresight-priv.h  |  24 ++-
 .../coresight/coresight-replicator.c  |  65 +++-
 drivers/hwtracing/coresight/coresight-stm.c   |  20 ++-
 drivers/hwtracing/coresight/coresight-sysfs.c |   2 +
 .../{coresight-tmc.c 

[PATCH v10 01/24] coresight: cpu_debug: add module name in Kconfig

2020-08-20 Thread Tingwei Zhang
Provide name of cpu_debug module in Kconfig help section.

Signed-off-by: Tingwei Zhang 
Tested-by: Mike Leach 
Reviewed-by: Suzuki K Poulose 
Reviewed-by: Mathieu Poirier 
---
 drivers/hwtracing/coresight/Kconfig | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/hwtracing/coresight/Kconfig 
b/drivers/hwtracing/coresight/Kconfig
index 02dbb5ca3bcf..4663fd1bbffc 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -110,6 +110,9 @@ config CORESIGHT_CPU_DEBUG
  properly, please refer 
Documentation/trace/coresight/coresight-cpu-debug.rst
  for detailed description and the example for usage.
 
+ To compile this driver as a module, choose M here: the
+ module will be called coresight-cpu-debug.
+
 config CORESIGHT_CTI
bool "CoreSight Cross Trigger Interface (CTI) driver"
depends on ARM || ARM64
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH] rapidio: fix get device imbalance on error

2020-08-20 Thread George Acosta
Fix the imbalance in mport_cdev_open.
Call put_device in error path to balance the
refcount that increased by the get_device.

Fixes: e8de370188d0 ("rapidio: add mport char device driver")
Signed-off-by: George Acosta 
---
 drivers/rapidio/devices/rio_mport_cdev.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/rapidio/devices/rio_mport_cdev.c 
b/drivers/rapidio/devices/rio_mport_cdev.c
index c07ceec3c6d4..3b68e00eb40f 100644
--- a/drivers/rapidio/devices/rio_mport_cdev.c
+++ b/drivers/rapidio/devices/rio_mport_cdev.c
@@ -1908,6 +1908,7 @@ static int mport_cdev_open(struct inode *inode, struct 
file *filp)
  sizeof(struct rio_event) * MPORT_EVENT_DEPTH,
  GFP_KERNEL);
if (ret < 0) {
+   put_device(>dev);
dev_err(>dev, DRV_NAME ": kfifo_alloc failed\n");
ret = -ENOMEM;
goto err_fifo;
-- 
2.17.1



[PATCH v2] drivers/dma/dma-jz4780: Fix race condition between probe and irq handler

2020-08-20 Thread madhuparnabhowmik10
From: Madhuparna Bhowmik 

In probe, IRQ is requested before zchan->id is initialized which can be
read in the irq handler. Hence, shift request irq after other initializations
complete.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Madhuparna Bhowmik 

---
Changes since v1:
Keep enable clock before request IRQ.
---
 drivers/dma/dma-jz4780.c | 38 +++---
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/dma/dma-jz4780.c b/drivers/dma/dma-jz4780.c
index 448f663da89c..8beed91428bd 100644
--- a/drivers/dma/dma-jz4780.c
+++ b/drivers/dma/dma-jz4780.c
@@ -879,24 +879,11 @@ static int jz4780_dma_probe(struct platform_device *pdev)
return -EINVAL;
}
 
-   ret = platform_get_irq(pdev, 0);
-   if (ret < 0)
-   return ret;
-
-   jzdma->irq = ret;
-
-   ret = request_irq(jzdma->irq, jz4780_dma_irq_handler, 0, dev_name(dev),
- jzdma);
-   if (ret) {
-   dev_err(dev, "failed to request IRQ %u!\n", jzdma->irq);
-   return ret;
-   }
-
jzdma->clk = devm_clk_get(dev, NULL);
if (IS_ERR(jzdma->clk)) {
dev_err(dev, "failed to get clock\n");
ret = PTR_ERR(jzdma->clk);
-   goto err_free_irq;
+   return ret;
}
 
clk_prepare_enable(jzdma->clk);
@@ -949,10 +936,23 @@ static int jz4780_dma_probe(struct platform_device *pdev)
jzchan->vchan.desc_free = jz4780_dma_desc_free;
}
 
+   ret = platform_get_irq(pdev, 0);
+   if (ret < 0)
+   goto err_disable_clk;
+
+   jzdma->irq = ret;
+
+   ret = request_irq(jzdma->irq, jz4780_dma_irq_handler, 0, dev_name(dev),
+ jzdma);
+   if (ret) {
+   dev_err(dev, "failed to request IRQ %u!\n", jzdma->irq);
+   goto err_disable_clk;
+   }
+
ret = dmaenginem_async_device_register(dd);
if (ret) {
dev_err(dev, "failed to register device\n");
-   goto err_disable_clk;
+   goto err_free_irq;
}
 
/* Register with OF DMA helpers. */
@@ -960,17 +960,17 @@ static int jz4780_dma_probe(struct platform_device *pdev)
 jzdma);
if (ret) {
dev_err(dev, "failed to register OF DMA controller\n");
-   goto err_disable_clk;
+   goto err_free_irq;
}
 
dev_info(dev, "JZ4780 DMA controller initialised\n");
return 0;
 
-err_disable_clk:
-   clk_disable_unprepare(jzdma->clk);
-
 err_free_irq:
free_irq(jzdma->irq, jzdma);
+
+err_disable_clk:
+   clk_disable_unprepare(jzdma->clk);
return ret;
 }
 
-- 
2.17.1



Re: [PATCH] hwrng: core - allocate a one page buffer

2020-08-20 Thread Herbert Xu
On Thu, Aug 06, 2020 at 05:28:14PM +0200, Laurent Vivier wrote:
.
> +static size_t rng_max_buffer_size(struct hwrng *rng)
> +{
> + size_t size;
> +
> + size = max_t(size_t, rng->buffer_size, SMP_CACHE_BYTES);
> +
> + /* rng_buffer can store up to PAGE_SIZE */
> + return min(PAGE_SIZE, size);
>  }

Rather than checking this on every read, just do it once at driver
registration time.

> @@ -614,11 +629,11 @@ static int __init hwrng_modinit(void)
>   int ret;
>  
>   /* kmalloc makes this safe for virt_to_page() in virtio_rng.c */
> - rng_buffer = kmalloc(rng_buffer_size(), GFP_KERNEL);
> + rng_buffer = (u8 *)get_zeroed_page(GFP_KERNEL);
>   if (!rng_buffer)
>   return -ENOMEM;

Why a zeroed page? Also please fix the out-of-sync comment.

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


[PATCH] mm/gup_benchmark: update the documentation in Kconfig

2020-08-20 Thread Barry Song
In the beginning, mm/gup_benchmark.c supported get_user_pages_fast()
only, but right now, it supports the benchmarking of a couple of
get_user_pages() related calls like:
* get_user_pages_fast()
* get_user_pages()
* pin_user_pages_fast()
* pin_user_pages()
The documentation is confusing and needs update.

Cc: John Hubbard 
Cc: Keith Busch 
Cc: Ira Weiny 
Cc: Kirill A. Shutemov 
Signed-off-by: Barry Song 
---
 mm/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/Kconfig b/mm/Kconfig
index 6c974888f86f..f7c9374da7b3 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -831,10 +831,10 @@ config PERCPU_STATS
  be used to help understand percpu memory usage.
 
 config GUP_BENCHMARK
-   bool "Enable infrastructure for get_user_pages_fast() benchmarking"
+   bool "Enable infrastructure for get_user_pages() and related calls 
benchmarking"
help
  Provides /sys/kernel/debug/gup_benchmark that helps with testing
- performance of get_user_pages_fast().
+ performance of get_user_pages() and related calls.
 
  See tools/testing/selftests/vm/gup_benchmark.c
 
-- 
2.27.0




Re: [PATCH] btrfs: block-group: Fix free-space bitmap threshould

2020-08-20 Thread Qu Wenruo


On 2020/8/21 上午10:42, Marcos Paulo de Souza wrote:
> From: Marcos Paulo de Souza 
> 
> [BUG]
> After commit 9afc66498a0b ("btrfs: block-group: refactor how we read one
> block group item"), cache->length is being assigned after calling
> btrfs_create_block_group_cache. This causes a problem since
> set_free_space_tree_thresholds is calculate the free-space threshould to
> decide is the free-space tree should convert from extents to bitmaps.
> 
> The current code calls set_free_space_tree_thresholds with cache->length
> being 0, which then makes cache->bitmap_high_thresh being zero. This
> implies the system will always use bitmap instead of extents, which is
> not desired if the block group is not fragmented.
> 
> This behavior can be seen by a test that expects to repair systems
> with FREE_SPACE_EXTENT and FREE_SPACE_BITMAP, but the current code only
> created FREE_SPACE_BITMAP.
> 
> [FIX]
> Call set_free_space_tree_thresholds after setting cache->length.
> 
> Link: https://github.com/kdave/btrfs-progs/issues/251
> Fixes: 9afc66498a0b ("btrfs: block-group: refactor how we read one block 
> group item")
> CC: sta...@vger.kernel.org # 5.8+
> Signed-off-by: Marcos Paulo de Souza 

Reviewed-by: Qu Wenruo 

It would be even nicer if you could add some warning or self-test on
cache->length to prevent such problem from happening again.

Thanks,
Qu
> ---
>  fs/btrfs/block-group.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
> index 44fdfa2eeb2e..01e8ba1da1d3 100644
> --- a/fs/btrfs/block-group.c
> +++ b/fs/btrfs/block-group.c
> @@ -1798,7 +1798,6 @@ static struct btrfs_block_group 
> *btrfs_create_block_group_cache(
>  
>   cache->fs_info = fs_info;
>   cache->full_stripe_len = btrfs_full_stripe_len(fs_info, start);
> - set_free_space_tree_thresholds(cache);
>  
>   cache->discard_index = BTRFS_DISCARD_INDEX_UNUSED;
>  
> @@ -1908,6 +1907,8 @@ static int read_one_block_group(struct btrfs_fs_info 
> *info,
>  
>   read_block_group_item(cache, path, key);
>  
> + set_free_space_tree_thresholds(cache);
> +
>   if (need_clear) {
>   /*
>* When we mount with old space cache, we need to
> @@ -2128,6 +2129,7 @@ int btrfs_make_block_group(struct btrfs_trans_handle 
> *trans, u64 bytes_used,
>   return -ENOMEM;
>  
>   cache->length = size;
> + set_free_space_tree_thresholds(cache);
>   cache->used = bytes_used;
>   cache->flags = type;
>   cache->last_byte_to_unpin = (u64)-1;
> 



signature.asc
Description: OpenPGP digital signature


[PATCH] btrfs: block-group: Fix free-space bitmap threshould

2020-08-20 Thread Marcos Paulo de Souza
From: Marcos Paulo de Souza 

[BUG]
After commit 9afc66498a0b ("btrfs: block-group: refactor how we read one
block group item"), cache->length is being assigned after calling
btrfs_create_block_group_cache. This causes a problem since
set_free_space_tree_thresholds is calculate the free-space threshould to
decide is the free-space tree should convert from extents to bitmaps.

The current code calls set_free_space_tree_thresholds with cache->length
being 0, which then makes cache->bitmap_high_thresh being zero. This
implies the system will always use bitmap instead of extents, which is
not desired if the block group is not fragmented.

This behavior can be seen by a test that expects to repair systems
with FREE_SPACE_EXTENT and FREE_SPACE_BITMAP, but the current code only
created FREE_SPACE_BITMAP.

[FIX]
Call set_free_space_tree_thresholds after setting cache->length.

Link: https://github.com/kdave/btrfs-progs/issues/251
Fixes: 9afc66498a0b ("btrfs: block-group: refactor how we read one block group 
item")
CC: sta...@vger.kernel.org # 5.8+
Signed-off-by: Marcos Paulo de Souza 
---
 fs/btrfs/block-group.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index 44fdfa2eeb2e..01e8ba1da1d3 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -1798,7 +1798,6 @@ static struct btrfs_block_group 
*btrfs_create_block_group_cache(
 
cache->fs_info = fs_info;
cache->full_stripe_len = btrfs_full_stripe_len(fs_info, start);
-   set_free_space_tree_thresholds(cache);
 
cache->discard_index = BTRFS_DISCARD_INDEX_UNUSED;
 
@@ -1908,6 +1907,8 @@ static int read_one_block_group(struct btrfs_fs_info 
*info,
 
read_block_group_item(cache, path, key);
 
+   set_free_space_tree_thresholds(cache);
+
if (need_clear) {
/*
 * When we mount with old space cache, we need to
@@ -2128,6 +2129,7 @@ int btrfs_make_block_group(struct btrfs_trans_handle 
*trans, u64 bytes_used,
return -ENOMEM;
 
cache->length = size;
+   set_free_space_tree_thresholds(cache);
cache->used = bytes_used;
cache->flags = type;
cache->last_byte_to_unpin = (u64)-1;
-- 
2.28.0



[PATCH v2 03/15] regulator: fan53555: Fix W=1 build warning when CONFIG_OF=n

2020-08-20 Thread Jisheng Zhang
Fix below warning when CONFIG_OF=n:

drivers/regulator/fan53555.c:439:34: warning: ‘fan53555_dt_ids’ defined but not 
used [-Wunused-const-variable=]
  439 | static const struct of_device_id fan53555_dt_ids[] = {
  |  ^~~

Signed-off-by: Jisheng Zhang 
---
 drivers/regulator/fan53555.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c
index 00c83492f774..aa426183b6a1 100644
--- a/drivers/regulator/fan53555.c
+++ b/drivers/regulator/fan53555.c
@@ -436,7 +436,7 @@ static struct fan53555_platform_data 
*fan53555_parse_dt(struct device *dev,
return pdata;
 }
 
-static const struct of_device_id fan53555_dt_ids[] = {
+static const struct of_device_id __maybe_unused fan53555_dt_ids[] = {
{
.compatible = "fcs,fan53526",
.data = (void *)FAN53526_VENDOR_FAIRCHILD,
-- 
2.28.0



[PATCH v2 12/15] regulator: sy8106a: Fix W=1 build warning when CONFIG_OF=n

2020-08-20 Thread Jisheng Zhang
Fix below warning when CONFIG_OF=n:

drivers/regulator/sy8106a-regulator.c:126:34: warning: ‘sy8106a_i2c_of_match’ 
defined but not used [-Wunused-const-variable=]
  126 | static const struct of_device_id sy8106a_i2c_of_match[] = {
  |  ^~~~

Signed-off-by: Jisheng Zhang 
---
 drivers/regulator/sy8106a-regulator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/regulator/sy8106a-regulator.c 
b/drivers/regulator/sy8106a-regulator.c
index e739e62b..c119f85259a5 100644
--- a/drivers/regulator/sy8106a-regulator.c
+++ b/drivers/regulator/sy8106a-regulator.c
@@ -123,7 +123,7 @@ static int sy8106a_i2c_probe(struct i2c_client *i2c)
return 0;
 }
 
-static const struct of_device_id sy8106a_i2c_of_match[] = {
+static const struct of_device_id __maybe_unused sy8106a_i2c_of_match[] = {
{ .compatible = "silergy,sy8106a" },
{ },
 };
-- 
2.28.0



[PATCH v2 15/15] regulator: tps65023: Fix W=1 build warning when CONFIG_OF=n

2020-08-20 Thread Jisheng Zhang
Fix below warning when CONFIG_OF=n:

drivers/regulator/tps65023-regulator.c:319:34: warning: ‘tps65023_of_match’ 
defined but not used [-Wunused-const-variable=]
  319 | static const struct of_device_id tps65023_of_match[] = {
  |  ^

Signed-off-by: Jisheng Zhang 
---
 drivers/regulator/tps65023-regulator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/regulator/tps65023-regulator.c 
b/drivers/regulator/tps65023-regulator.c
index 795d459ff3cf..f25806531c7e 100644
--- a/drivers/regulator/tps65023-regulator.c
+++ b/drivers/regulator/tps65023-regulator.c
@@ -316,7 +316,7 @@ static int tps_65023_probe(struct i2c_client *client,
return 0;
 }
 
-static const struct of_device_id tps65023_of_match[] = {
+static const struct of_device_id __maybe_unused tps65023_of_match[] = {
{ .compatible = "ti,tps65020", .data = _drv_data},
{ .compatible = "ti,tps65021", .data = _drv_data},
{ .compatible = "ti,tps65023", .data = _drv_data},
-- 
2.28.0



[PATCH v2 06/15] regulator: ltc3676: Fix W=1 build warning when CONFIG_OF=n

2020-08-20 Thread Jisheng Zhang
Fix below warning when CONFIG_OF=n:

drivers/regulator/ltc3676.c:371:34: warning: ‘ltc3676_of_match’ defined but not 
used [-Wunused-const-variable=]
  371 | static const struct of_device_id ltc3676_of_match[] = {
  |  ^~~~

Signed-off-by: Jisheng Zhang 
---
 drivers/regulator/ltc3676.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/regulator/ltc3676.c b/drivers/regulator/ltc3676.c
index 093b3e4a6303..557727b54f0e 100644
--- a/drivers/regulator/ltc3676.c
+++ b/drivers/regulator/ltc3676.c
@@ -368,7 +368,7 @@ static const struct i2c_device_id ltc3676_i2c_id[] = {
 };
 MODULE_DEVICE_TABLE(i2c, ltc3676_i2c_id);
 
-static const struct of_device_id ltc3676_of_match[] = {
+static const struct of_device_id __maybe_unused ltc3676_of_match[] = {
{ .compatible = "lltc,ltc3676" },
{ },
 };
-- 
2.28.0



[PATCH v2 09/15] regulator: pwm: Fix W=1 build warning when CONFIG_OF=n

2020-08-20 Thread Jisheng Zhang
Fix below warning when CONFIG_OF=n:

drivers/regulator/pwm-regulator.c:393:34: warning: ‘pwm_of_match’ defined but 
not used [-Wunused-const-variable=]
  393 | static const struct of_device_id pwm_of_match[] = {
  |  ^~~~

Signed-off-by: Jisheng Zhang 
---
 drivers/regulator/pwm-regulator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/regulator/pwm-regulator.c 
b/drivers/regulator/pwm-regulator.c
index 3234b118b53e..d250e60f1625 100644
--- a/drivers/regulator/pwm-regulator.c
+++ b/drivers/regulator/pwm-regulator.c
@@ -390,7 +390,7 @@ static int pwm_regulator_probe(struct platform_device *pdev)
return 0;
 }
 
-static const struct of_device_id pwm_of_match[] = {
+static const struct of_device_id __maybe_unused pwm_of_match[] = {
{ .compatible = "pwm-regulator" },
{ },
 };
-- 
2.28.0



[PATCH v2 01/15] regulator: 88pg86x: Fix W=1 build warning when CONFIG_OF=n

2020-08-20 Thread Jisheng Zhang
Fix below warning when CONFIG_OF=n:

drivers/regulator/88pg86x.c:87:34: warning: ‘pg86x_dt_ids’ defined but not used 
[-Wunused-const-variable=]
87 | static const struct of_device_id pg86x_dt_ids [] = {
   |  ^~~~

Signed-off-by: Jisheng Zhang 
---
 drivers/regulator/88pg86x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/regulator/88pg86x.c b/drivers/regulator/88pg86x.c
index 71cfa2c5de5e..e995e7379a04 100644
--- a/drivers/regulator/88pg86x.c
+++ b/drivers/regulator/88pg86x.c
@@ -84,7 +84,7 @@ static int pg86x_i2c_probe(struct i2c_client *i2c)
return 0;
 }
 
-static const struct of_device_id pg86x_dt_ids [] = {
+static const struct of_device_id __maybe_unused pg86x_dt_ids[] = {
{ .compatible = "marvell,88pg867" },
{ .compatible = "marvell,88pg868" },
{ }
-- 
2.28.0



  1   2   3   4   5   6   7   8   9   10   >