Re: [PATCH net-next 5/8] net: phy: mscc: 1588 block initialization

2020-05-27 Thread Antoine Tenart
Hello Jakub,

Quoting Jakub Kicinski (2020-05-27 19:35:13)
> 
> This doesn't build on my system :S

I'll have a look at this and fix it for v2.

Thanks for reporting it!
Antoine

> 
> In file included from ../drivers/net/phy/mscc/mscc_ptp.c:18:
> ../include/linux/unaligned/be_byteshift.h:41:19: error: redefinition of 
> ‘get_unaligned_be16’
>41 | static inline u16 get_unaligned_be16(const void *p)
>   |   ^~
> In file included from ../arch/x86/include/asm/unaligned.h:9,
>  from ../include/linux/etherdevice.h:24,
>  from ../include/linux/if_vlan.h:11,
>  from ../include/linux/filter.h:22,
>  from ../include/net/sock.h:59,
>  from ../include/net/inet_sock.h:22,
>  from ../include/linux/udp.h:16,
>  from ../drivers/net/phy/mscc/mscc_ptp.c:17:
> ../include/linux/unaligned/access_ok.h:23:28: note: previous definition of 
> ‘get_unaligned_be16’ was here
>23 | static __always_inline u16 get_unaligned_be16(const void *p)
>   |^~
> In file included from ../drivers/net/phy/mscc/mscc_ptp.c:18:
> ../include/linux/unaligned/be_byteshift.h:46:19: error: redefinition of 
> ‘get_unaligned_be32’
>46 | static inline u32 get_unaligned_be32(const void *p)
>   |   ^~
> In file included from ../arch/x86/include/asm/unaligned.h:9,
>  from ../include/linux/etherdevice.h:24,
>  from ../include/linux/if_vlan.h:11,
>  from ../include/linux/filter.h:22,
>  from ../include/net/sock.h:59,
>  from ../include/net/inet_sock.h:22,
>  from ../include/linux/udp.h:16,
>  from ../drivers/net/phy/mscc/mscc_ptp.c:17:
> ../include/linux/unaligned/access_ok.h:28:28: note: previous definition of 
> ‘get_unaligned_be32’ was here
>28 | static __always_inline u32 get_unaligned_be32(const void *p)
>   |^~
> In file included from ../drivers/net/phy/mscc/mscc_ptp.c:18:
> ../include/linux/unaligned/be_byteshift.h:51:19: error: redefinition of 
> ‘get_unaligned_be64’
>51 | static inline u64 get_unaligned_be64(const void *p)
>   |   ^~
> In file included from ../arch/x86/include/asm/unaligned.h:9,
>  from ../include/linux/etherdevice.h:24,
>  from ../include/linux/if_vlan.h:11,
>  from ../include/linux/filter.h:22,
>  from ../include/net/sock.h:59,
>  from ../include/net/inet_sock.h:22,
>  from ../include/linux/udp.h:16,
>  from ../drivers/net/phy/mscc/mscc_ptp.c:17:
> ../include/linux/unaligned/access_ok.h:33:28: note: previous definition of 
> ‘get_unaligned_be64’ was here
>33 | static __always_inline u64 get_unaligned_be64(const void *p)
>   |^~
> In file included from ../drivers/net/phy/mscc/mscc_ptp.c:18:
> ../include/linux/unaligned/be_byteshift.h:56:20: error: redefinition of 
> ‘put_unaligned_be16’
>56 | static inline void put_unaligned_be16(u16 val, void *p)
>   |^~
> In file included from ../arch/x86/include/asm/unaligned.h:9,
>  from ../include/linux/etherdevice.h:24,
>  from ../include/linux/if_vlan.h:11,
>  from ../include/linux/filter.h:22,
>  from ../include/net/sock.h:59,
>  from ../include/net/inet_sock.h:22,
>  from ../include/linux/udp.h:16,
>  from ../drivers/net/phy/mscc/mscc_ptp.c:17:
> ../include/linux/unaligned/access_ok.h:53:29: note: previous definition of 
> ‘put_unaligned_be16’ was here
>53 | static __always_inline void put_unaligned_be16(u16 val, void *p)
>   | ^~
> In file included from ../drivers/net/phy/mscc/mscc_ptp.c:18:
> ../include/linux/unaligned/be_byteshift.h:61:20: error: redefinition of 
> ‘put_unaligned_be32’
>61 | static inline void put_unaligned_be32(u32 val, void *p)
>   |^~
> In file included from ../arch/x86/include/asm/unaligned.h:9,
>  from ../include/linux/etherdevice.h:24,
>  from ../include/linux/if_vlan.h:11,
>  from ../include/linux/filter.h:22,
>  from ../include/net/sock.h:59,
>  from ../include/net/inet_sock.h:22,
>  from ../include/linux/udp.h:16,
>  from ../drivers/net/phy/mscc/mscc_ptp.c:17:
> ../include/linux/unaligned/access_ok.h:58:29: note: previous definition of 
> ‘put_unaligned_be32’ was here
>58 | static __always_inline void put_unaligned_be32(u32 val, void *p)
>   |

Re: [PATCH] hwrng: ks-sa - fix runtime pm imbalance on error

2020-05-27 Thread Herbert Xu
On Wed, May 20, 2020 at 12:45:56PM -0400, st...@rowland.harvard.edu wrote:
> On Wed, May 20, 2020 at 03:42:17PM +, Sverdlin, Alexander (Nokia - 
> DE/Ulm) wrote:
> > Hello Dinghao,
> > 
> > On Wed, 2020-05-20 at 21:29 +0800, Dinghao Liu wrote:
> > > pm_runtime_get_sync() increments the runtime PM usage counter even
> > > the call returns an error code. Thus a pairing decrement is needed
> > > on the error handling path to keep the counter balanced.
> > 
> > I believe, this is the wrong place for such kind of fix.
> > pm_runtime_get_sync() has obviously a broken semantics with regards to
> > your observation but no other driver does what you propose.
> 
> Look again.  For example, see what usb_autoresume_device() in 
> drivers/usb/core/driver.c does.

However, there seems to be some disagreement as to what to do
when pm_runtime_get_sync fails.  Your driver chooses to call
put_sync while others prefer pm_runtime_put_noidle (e.g., see
drivers/base/power/runtime.c).

This API does seem to be in a bit of a mess.

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


Re: [PATCH] tpm: Revert "tpm: fix invalid locking in NONBLOCKING mode"

2020-05-27 Thread Jarkko Sakkinen
On Wed, May 27, 2020 at 09:40:25PM -0700, Tadeusz Struk wrote:
> On 5/27/20 5:30 PM, Jarkko Sakkinen wrote:
> >> This won't help if the message is read by an async tcti. If the problem 
> >> lies
> >> in the chip get locality code, perhaps this could help to debug the 
> >> root-cause
> >> instead of masking it out in the upper layer code:
> > What is TCTI and async TCTI? Not following.
> 
> TPM Command Transmission Interface (TCTI) as defined by TCG in
> https://trustedcomputinggroup.org/resource/tss-tcti-specification/
> 
> the reason we added the O_NONBLOCK mode was to satisfy the TCG spec for async 
> TCTI.
> 
> Thanks,
> Tadeusz

OK, thanks recalling.

/Jarkko


[PATCH v2] twist: allow converting pr_devel()/pr_debug() into snprintf()

2020-05-27 Thread Tetsuo Handa
syzbot found a NULL pointer dereference bug inside mptcp_recvmsg() due to
ssock == NULL, but this bug manifested inside selinux_socket_recvmsg()
because pr_debug() was no-op [1].

  pr_debug("fallback-read subflow=%p",
   mptcp_subflow_ctx(ssock->sk));
  copied = sock_recvmsg(ssock, msg, flags);

Thus, let's allow fuzzers to always evaluate pr_devel()/pr_debug()
messages, by redirecting no-op pr_devel()/pr_debug() calls to snprintf().

[1] 
https://syzkaller.appspot.com/bug?id=12be9aa373be9d8727cdd172f190de39528a413a

Signed-off-by: Tetsuo Handa 
Cc: Petr Mladek 
Cc: Sergey Senozhatsky 
Cc: Steven Rostedt 
Cc: Ondrej Mosnacek 
Cc: Dmitry Vyukov 
---
 include/linux/dev_printk.h| 16 
 include/linux/dynamic_debug.h | 14 --
 include/linux/printk.h| 10 ++
 lib/Kconfig.twist | 12 
 4 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/include/linux/dev_printk.h b/include/linux/dev_printk.h
index 3028b644b4fb..ed5d5bb3b5b6 100644
--- a/include/linux/dev_printk.h
+++ b/include/linux/dev_printk.h
@@ -121,6 +121,8 @@ void _dev_info(const struct device *dev, const char *fmt, 
...)
 ({ \
if (0)  \
dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
+   else if (IS_BUILTIN(CONFIG_TWIST_ALWAYS_EVALUATE_PRINTK_ARGUMENTS)) \
+   snprintf(NULL, 0, dev_fmt(fmt), ##__VA_ARGS__); \
 })
 #endif
 
@@ -133,12 +135,16 @@ do {  
\
__print_once = true;\
dev_level(dev, fmt, ##__VA_ARGS__); \
}   \
+   else if (IS_BUILTIN(CONFIG_TWIST_ALWAYS_EVALUATE_PRINTK_ARGUMENTS)) \
+   snprintf(NULL, 0, fmt, ##__VA_ARGS__);  \
 } while (0)
 #else
 #define dev_level_once(dev_level, dev, fmt, ...)   \
 do {   \
if (0)  \
dev_level(dev, fmt, ##__VA_ARGS__); \
+   else if (IS_BUILTIN(CONFIG_TWIST_ALWAYS_EVALUATE_PRINTK_ARGUMENTS)) \
+   snprintf(NULL, 0, fmt, ##__VA_ARGS__);  \
 } while (0)
 #endif
 
@@ -166,6 +172,8 @@ do {
\
  DEFAULT_RATELIMIT_BURST); \
if (__ratelimit(&_rs))  \
dev_level(dev, fmt, ##__VA_ARGS__); \
+   else if (IS_BUILTIN(CONFIG_TWIST_ALWAYS_EVALUATE_PRINTK_ARGUMENTS)) \
+   snprintf(NULL, 0, fmt, ##__VA_ARGS__);  \
 } while (0)
 
 #define dev_emerg_ratelimited(dev, fmt, ...)   \
@@ -195,6 +203,8 @@ do {
\
__ratelimit(&_rs))  \
__dynamic_dev_dbg(&descriptor, dev, dev_fmt(fmt),   \
  ##__VA_ARGS__);   \
+   else if (IS_BUILTIN(CONFIG_TWIST_ALWAYS_EVALUATE_PRINTK_ARGUMENTS)) \
+   snprintf(NULL, 0, dev_fmt(fmt), ##__VA_ARGS__); \
 } while (0)
 #elif defined(DEBUG)
 #define dev_dbg_ratelimited(dev, fmt, ...) \
@@ -204,12 +214,16 @@ do {  
\
  DEFAULT_RATELIMIT_BURST); \
if (__ratelimit(&_rs))  \
dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
+   else if (IS_BUILTIN(CONFIG_TWIST_ALWAYS_EVALUATE_PRINTK_ARGUMENTS)) \
+   snprintf(NULL, 0, dev_fmt(fmt), ##__VA_ARGS__); \
 } while (0)
 #else
 #define dev_dbg_ratelimited(dev, fmt, ...) \
 do {   \
if (0)  \
dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
+   else if (IS_BUILTIN(CONFIG_TWIST_ALWAYS_EVALUATE_PRINTK_ARGUMENTS)) \
+   snprintf(NULL, 0, dev_fmt(fmt), ##__VA_ARGS__); \
 } while (0)
 #endif
 
@@ -220,6 +234,8 @@ do {
\
 ({ \
if (0)  \
dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
+   else if (IS_BUILTIN(CONFI

Re: [PATCH 2/2] iommu: calling pci_fixup_iommu in iommu_fwspec_init

2020-05-27 Thread Zhangfei Gao




On 2020/5/27 下午5:01, Greg Kroah-Hartman wrote:

On Tue, May 26, 2020 at 07:49:09PM +0800, Zhangfei Gao wrote:

Calling pci_fixup_iommu in iommu_fwspec_init, which alloc
iommu_fwnode. Some platform devices appear as PCI but are
actually on the AMBA bus, and they need fixup in
drivers/pci/quirks.c handling iommu_fwnode.
So calling pci_fixup_iommu after iommu_fwnode is allocated.

Signed-off-by: Zhangfei Gao 
---
  drivers/iommu/iommu.c | 4 
  1 file changed, 4 insertions(+)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 7b37542..fb84c42 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -2418,6 +2418,10 @@ int iommu_fwspec_init(struct device *dev, struct 
fwnode_handle *iommu_fwnode,
fwspec->iommu_fwnode = iommu_fwnode;
fwspec->ops = ops;
dev_iommu_fwspec_set(dev, fwspec);
+
+   if (dev_is_pci(dev))
+   pci_fixup_device(pci_fixup_iommu, to_pci_dev(dev));

Why can't the caller do this as it "knows" it is a PCI device at that
point in time, right?

Putting fixup here is because
1. iommu_fwspec has been allocated
2. iommu_fwspec_init will be called by of_pci_iommu_init and 
iort_pci_iommu_init, covering both acpi and dt


Thanks


Re: [PATCH] tpm: Revert "tpm: fix invalid locking in NONBLOCKING mode"

2020-05-27 Thread Jarkko Sakkinen
On Thu, May 28, 2020 at 12:59:59AM +, mario.limoncie...@dell.com wrote:
> > > > [EXTERNAL EMAIL]
> > 
> > What is this?
> 
> Something my employer's mail system automatically tags in external email.
> 
> My mistakes in forgetting to remove it on the response.

NP, just asking :-)

> > > > On Tue, 2020-05-26 at 12:38 -0700, James Bottomley wrote:
> > > > > On Tue, 2020-05-26 at 19:23 +, mario.limoncie...@dell.com wrote:
> > > > > > > On Tue, 2020-05-26 at 13:32 -0500, Mario Limonciello wrote:
> > > > > > > > This reverts commit d23d12484307b40eea549b8a858f5fffad913897.
> > > > > > > >
> > > > > > > > This commit has caused regressions for the XPS 9560 containing
> > > > > > > > a Nuvoton TPM.
> > > > > > >
> > > > > > > Presumably this is using the tis driver?
> > > > > >
> > > > > > Correct.
> > > > > >
> > > > > > > > As mentioned by the reporter all TPM2 commands are failing with:
> > > > > > > >   ERROR:tcti:src/tss2-tcti/tcti-
> > > > > > > > device.c:290:tcti_device_receive()
> > > > > > > >   Failed to read response from fd 3, got errno 1: Operation not
> > > > > > > > permitted
> > > > > > > >
> > > > > > > > The reporter bisected this issue back to this commit which was
> > > > > > > > backported to stable as commit 4d6ebc4.
> > > > > > >
> > > > > > > I think the problem is request_locality ... for some inexplicable
> > > > > > > reason a failure there returns -1, which is EPERM to user space.
> > > > > > >
> > > > > > > That seems to be a bug in the async code since everything else
> > > > > > > gives a ESPIPE error if tpm_try_get_ops fails ... at least no-one
> > > > > > > assumes it gives back a sensible return code.
> > > > > > >
> > > > > > > What I think is happening is that with the patch the TPM goes
> > > > > > > through a quick sequence of request, relinquish, request,
> > > > > > > relinquish and it's the third request which is failing (likely
> > > > > > > timing out).  Without the patch, the patch there's only one
> > > > > > > request,relinquish cycle because the ops are held while the async
> > > > > > > work is executed.  I have a vague recollection that there is a
> > > > > > > problem with too many locality request in quick succession, but
> > > > > > > I'll defer to Jason, who I think understands the intricacies of
> > > > > > > localities better than I do.
> > > > > >
> > > > > > Thanks, I don't pretend to understand the nuances of this particular
> > > > > > code, but I was hoping that the request to revert got some attention
> > > > > > since Alex's kernel Bugzilla and message a few months ago to linux
> > > > > > integrity weren't.
> > > > > >
> > > > > > > If that's the problem, the solution looks simple enough: just move
> > > > > > > the ops get down because the priv state is already protected by 
> > > > > > > the
> > > > > > > buffer mutex
> > > > > >
> > > > > > Yeah, if that works for Alex's situation it certainly sounds like a
> > > > > > better solution than reverting this patch as this patch actually 
> > > > > > does
> > > > > > fix a problem reported by Jeffrin originally.
> > > > > >
> > > > > > Could you propose a specific patch that Alex and Jeffrin can perhaps
> > > > > > both try?
> > > > >
> > > > > Um, what's wrong with the one I originally attached and which you 
> > > > > quote
> > > > > below?  It's only compile tested, but I think it will work, if the
> > > > > theory is correct.
> > > >
> > > > Please send a legit patch, thanks.
> > > >
> > > > /Jarkko
> > >
> > > Jarkko,
> > >
> > > After the confirmation from Alex that this patch attached to the end of 
> > > the
> > thread
> > > worked, James did send a proper patch that can be accessed here:
> > > https://lore.kernel.org/linux-
> > integrity/20200527155800.ya43xm2ltuwduwjg@cantor/T/#t
> > >
> > > Thanks,
> > 
> > Hi thanks a lot! I did read the full discussions and agree with the
> > conclusions as I get a patch in proper form.
> > 
> > Please ping next time a bit earlier. It's not that I don't want to deal
> > with the issues quickly as possible. It's probably just that I've forgot
> > something or missed.
> > 
> > /Jarkko
> 
> Thanks!
> 
> I completely forgot about it too, it was mentioned to me right after holidays
> and I forgot to follow up and see that it got sorted.

Yeah, sure, lets try to get a fix landed asap :-)

/Jarkko


Re: [PATCH v30 08/20] x86/sgx: Add functions to allocate and free EPC pages

2020-05-27 Thread Jarkko Sakkinen
On Wed, May 27, 2020 at 06:36:18PM -0700, Sean Christopherson wrote:
> On Thu, May 28, 2020 at 04:23:19AM +0300, Jarkko Sakkinen wrote:
> > On Wed, May 27, 2020 at 10:46:38PM +0200, Borislav Petkov wrote:
> > > On Tue, May 26, 2020 at 09:21:11PM -0700, Sean Christopherson wrote:
> > > > In other words, sgx_alloc_epc_section() is poorly named.  It doesn't
> > > > actually allocate EPC, it allocates kernel structures to map and track 
> > > > EPC.
> > > > sgx_(un)map_epc_section() would be more accurate and would hopefully
> > > > alleviate some of the confusion.
> 
> ...
> 
> > I'm not sure I follow fully Sean's reasoning but the way alloc is used
> > mostly in Linux is to ask through some API the used kernel memory
> > allocator to give memory for some kernel data structures.
> 
> Function names are usually some form of
> 
>   __
> 
> where 'object' is the target of the 'verb'.  So sgx_alloc_epc_section()
> is most likely going to be read as "SGX, allocate an EPC section".  But
> that code doesn't allocate an EPC section, it maps an EPC section, and on
> success, adds the section's pages to the unsanitized list, i.e. what
> effectively becomes the pool of EPC pages.  The allocation part is a side
> effect of how we track EPC pages, it's not the primary purpose of the
> function.
> 
> Maybe sgx_add_epc_section() and sgx_remove_epc_section() would be better
> than map/unmap?
> 
> Eliminating the misnamed sgx_alloc_epc_section() frees up the "alloc" verb
> for use in the actual EPC page allocation paths, i.e. avoids having to
> rename those to "grab".  IMO, "alloc" is the best name as it most closely
> aligns with the nomenclature for regular pages, e.g. "grab" is most often
> used to elevate refcounts.

I'm thinking that you are over-engineering something this :-) Naming is
never perfect.

But I do get the original comment about sgx_alloc_page().

/Jarkko


Re: [PATCH v30 08/20] x86/sgx: Add functions to allocate and free EPC pages

2020-05-27 Thread Jarkko Sakkinen
On Wed, May 27, 2020 at 05:52:17PM -0700, Sean Christopherson wrote:
> On Wed, May 27, 2020 at 10:46:38PM +0200, Borislav Petkov wrote:
> > On Tue, May 26, 2020 at 09:21:11PM -0700, Sean Christopherson wrote:
> > > In other words, sgx_alloc_epc_section() is poorly named.  It doesn't
> > > actually allocate EPC, it allocates kernel structures to map and track 
> > > EPC.
> > > sgx_(un)map_epc_section() would be more accurate and would hopefully
> > > alleviate some of the confusion.
> > 
> > Makes sense.
> > 
> > > I have no objection to renaming __sgx_alloc_try_alloc_page() to something
> > > like sgx_alloc_epc_page_section or whatever, but IMO using get/put will be
> > > horrendously confusing.
> > 
> > Ok. My only issue is that the naming nomenclature sounds strange and
> > confusing as it is. "try" in an "alloc" function is kinda tautological -
> > of course the function will try to do its best. :)
> 
> Heh, so what you're saying is we should add __sgx_really_try_alloc_page()?
> 
> > And there are three functions having "alloc" in the name so I can
> > imagine someone getting very confused when having to stare at that code.
> > 
> > So at least naming them in a way so that it is clear what kind of pages
> > they "allocate" - i.e., what they actually do - would be a step in the
> > right direction...
> 
> Ya, and things will only get more confusing when actual NUMA awareness gets
> thrown into the mix.
> 
> Jarkko, splicing in the NUMA awareness code, what do you think about:
> 
>   sgx_alloc_epc_section -> sgx_map_epc_section
>   sgx_free_epc_section  -> sgx_unmap_epc_section

Here alloc makes sense because memory gets allocated for the data
structures.

>   sgx_alloc_page-> sgx_alloc_epc_page
>   sgx_free_page -> sgx_free_epc_page
> 
>   sgx_try_alloc_page-> sgx_alloc_epc_page_node
>   __sgx_try_alloc_page  -> sgx_alloc_epc_page_section

I'm going with sgx_grab_page() and sgx_try_grab_page().

/Jarkko


Re: [PATCH] mm, memory_failure: only send BUS_MCEERR_AO to early-kill process

2020-05-27 Thread wetp



On 2020/5/28 上午10:22, HORIGUCHI NAOYA(堀口 直也) wrote:

Hi Zhang,

Sorry for my late response.

On Tue, May 26, 2020 at 03:06:41PM +0800, Wetp Zhang wrote:

From: Zhang Yi 

If a process don't need early-kill, it may not care the BUS_MCEERR_AO.
Let the process to be killed when it really access the corrupted memory.

Signed-off-by: Zhang Yi 

Thank you for pointing this. This looks to me a bug (per-process flag
is ignored when system-wide flag is set).


The flag is not problem for me.

In my case, two processes share memory with no any flag setting, both 
will be killed when only one


access the fail memory.


---
  mm/memory-failure.c | 7 ---
  1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index a96364be8ab4..2db13d48865c 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -210,7 +210,7 @@ static int kill_proc(struct to_kill *tk, unsigned long pfn, 
int flags)
  {
struct task_struct *t = tk->tsk;
short addr_lsb = tk->size_shift;
-   int ret;
+   int ret = 0;

pr_err("Memory failure: %#lx: Sending SIGBUS to %s:%d due to hardware memory 
corruption\n",
pfn, t->comm, t->pid);
@@ -225,8 +225,9 @@ static int kill_proc(struct to_kill *tk, unsigned long pfn, 
int flags)
 * This could cause a loop when the user sets SIGBUS
 * to SIG_IGN, but hopefully no one will do that?
 */
-   ret = send_sig_mceerr(BUS_MCEERR_AO, (void __user *)tk->addr,
- addr_lsb, t);  /* synchronous? */
+   if ((t->flags & PF_MCE_PROCESS) && (t->flags & PF_MCE_EARLY))
+   ret = send_sig_mceerr(BUS_MCEERR_AO,
+   (void __user *)tk->addr, addr_lsb, t);

kill_proc() could be called only for processes that are selected by
collect_procs() with task_early_kill().  So I think that we should fix
task_early_kill(), maybe by reordering sysctl_memory_failure_early_kill
check and find_early_kill_thread() check.

 static struct task_struct *task_early_kill(struct task_struct *tsk,
int force_early)
 {
 struct task_struct *t;
 if (!tsk->mm)
 return NULL;
 if (force_early)
 return tsk;


The force_early is rely the flag MF_ACTION_REQUIRED, so it is always 
true when MCE occurs.


This leads always sending SIGBUS to processes even if those are not 
current or no flag setting.


 I think it could keep the non-current processes which has no flag 
setting running.



Besides, base on your recommendation I reorder the force_early check and 
find_early_kill_thread()


check, to send the signal to the right thread.

diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 2db13d48865c..33a87d7b3e61 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c

@@ -399,11 +402,11 @@ static struct task_struct *task_early_kill(struct 
task_struct *tsk,
struct task_struct *t;
if (!tsk->mm)
return NULL;
-   if (force_early)
-   return tsk;
t = find_early_kill_thread(tsk);
if (t)
return t;
+   if (force_early && tsk->mm == current->mm)
+   return tsk;
if (sysctl_memory_failure_early_kill)
return tsk;
return NULL;


 t = find_early_kill_thread(tsk);
 if (t)
 return t;
 if (sysctl_memory_failure_early_kill)
 return tsk;
 return NULL;
 }

One subtleness is to make sure that find_early_kill_thread() should distinguish
default value and explicitly set value, so we might need some modification
on find_early_kill_thread().

Can you try that?

Thanks,
Naoya Horiguchi


[tip: perf/core] perf/x86/rapl: Refactor to share the RAPL code between Intel and AMD CPUs

2020-05-27 Thread tip-bot2 for Stephane Eranian
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 5c95c68949880035b68e5c48fdf4899ec0989631
Gitweb:
https://git.kernel.org/tip/5c95c68949880035b68e5c48fdf4899ec0989631
Author:Stephane Eranian 
AuthorDate:Wed, 27 May 2020 15:46:56 -07:00
Committer: Ingo Molnar 
CommitterDate: Thu, 28 May 2020 07:58:55 +02:00

perf/x86/rapl: Refactor to share the RAPL code between Intel and AMD CPUs

This patch modifies the rapl_model struct to include architecture specific
knowledge in this previously Intel specific structure, and in particular
it adds the MSR for POWER_UNIT and the rapl_msrs array.

No functional changes.

Signed-off-by: Stephane Eranian 
Signed-off-by: Ingo Molnar 
Link: https://lore.kernel.org/r/20200527224659.206129-3-eran...@google.com
---
 arch/x86/events/rapl.c | 29 +++--
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c
index 3e6c01b..f29935e 100644
--- a/arch/x86/events/rapl.c
+++ b/arch/x86/events/rapl.c
@@ -131,7 +131,9 @@ struct rapl_pmus {
 };
 
 struct rapl_model {
+   struct perf_msr *rapl_msrs;
unsigned long   events;
+   unsigned intmsr_power_unit;
boolapply_quirk;
 };
 
@@ -141,7 +143,7 @@ static struct rapl_pmus *rapl_pmus;
 static cpumask_t rapl_cpu_mask;
 static unsigned int rapl_cntr_mask;
 static u64 rapl_timer_ms;
-static struct perf_msr rapl_msrs[];
+static struct perf_msr *rapl_msrs;
 
 static inline struct rapl_pmu *cpu_to_rapl_pmu(unsigned int cpu)
 {
@@ -516,7 +518,7 @@ static bool test_msr(int idx, void *data)
return test_bit(idx, (unsigned long *) data);
 }
 
-static struct perf_msr rapl_msrs[] = {
+static struct perf_msr intel_rapl_msrs[] = {
[PERF_RAPL_PP0]  = { MSR_PP0_ENERGY_STATUS,  
&rapl_events_cores_group, test_msr },
[PERF_RAPL_PKG]  = { MSR_PKG_ENERGY_STATUS,  
&rapl_events_pkg_group,   test_msr },
[PERF_RAPL_RAM]  = { MSR_DRAM_ENERGY_STATUS, 
&rapl_events_ram_group,   test_msr },
@@ -578,13 +580,13 @@ static int rapl_cpu_online(unsigned int cpu)
return 0;
 }
 
-static int rapl_check_hw_unit(bool apply_quirk)
+static int rapl_check_hw_unit(struct rapl_model *rm)
 {
u64 msr_rapl_power_unit_bits;
int i;
 
/* protect rdmsrl() to handle virtualization */
-   if (rdmsrl_safe(MSR_RAPL_POWER_UNIT, &msr_rapl_power_unit_bits))
+   if (rdmsrl_safe(rm->msr_power_unit, &msr_rapl_power_unit_bits))
return -1;
for (i = 0; i < NR_RAPL_DOMAINS; i++)
rapl_hw_unit[i] = (msr_rapl_power_unit_bits >> 8) & 0x1FULL;
@@ -595,7 +597,7 @@ static int rapl_check_hw_unit(bool apply_quirk)
 * "Intel Xeon Processor E5-1600 and E5-2600 v3 Product Families, V2
 * of 2. Datasheet, September 2014, Reference Number: 330784-001 "
 */
-   if (apply_quirk)
+   if (rm->apply_quirk)
rapl_hw_unit[PERF_RAPL_RAM] = 16;
 
/*
@@ -676,6 +678,8 @@ static struct rapl_model model_snb = {
  BIT(PERF_RAPL_PKG) |
  BIT(PERF_RAPL_PP1),
.apply_quirk= false,
+   .msr_power_unit = MSR_RAPL_POWER_UNIT,
+   .rapl_msrs  = intel_rapl_msrs,
 };
 
 static struct rapl_model model_snbep = {
@@ -683,6 +687,8 @@ static struct rapl_model model_snbep = {
  BIT(PERF_RAPL_PKG) |
  BIT(PERF_RAPL_RAM),
.apply_quirk= false,
+   .msr_power_unit = MSR_RAPL_POWER_UNIT,
+   .rapl_msrs  = intel_rapl_msrs,
 };
 
 static struct rapl_model model_hsw = {
@@ -691,6 +697,8 @@ static struct rapl_model model_hsw = {
  BIT(PERF_RAPL_RAM) |
  BIT(PERF_RAPL_PP1),
.apply_quirk= false,
+   .msr_power_unit = MSR_RAPL_POWER_UNIT,
+   .rapl_msrs  = intel_rapl_msrs,
 };
 
 static struct rapl_model model_hsx = {
@@ -698,12 +706,16 @@ static struct rapl_model model_hsx = {
  BIT(PERF_RAPL_PKG) |
  BIT(PERF_RAPL_RAM),
.apply_quirk= true,
+   .msr_power_unit = MSR_RAPL_POWER_UNIT,
+   .rapl_msrs  = intel_rapl_msrs,
 };
 
 static struct rapl_model model_knl = {
.events = BIT(PERF_RAPL_PKG) |
  BIT(PERF_RAPL_RAM),
.apply_quirk= true,
+   .msr_power_unit = MSR_RAPL_POWER_UNIT,
+   .rapl_msrs  = intel_rapl_msrs,
 };
 
 static struct rapl_model model_skl = {
@@ -713,6 +725,8 @@ static struct rapl_model model_skl = {
  BIT(PERF_RAPL_PP1) |
  BIT(PERF_RAPL_PSYS),
.apply_quirk= false,
+   .msr_power_unit = MSR_RAPL_POWER_UNIT,
+   .rapl_msrs  = intel_rapl_msrs,
 };
 
 static const struct x86_cpu_id rapl_model_match[] __initconst = {
@@ -760,10 +774,13 @@ static int __init rapl_pmu_init(void)
   

[tip: perf/core] perf/x86/rapl: Flip logic on default events visibility

2020-05-27 Thread tip-bot2 for Stephane Eranian
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 2a3e3f73a23b4ff2c0065d3a42edc18ad94b7851
Gitweb:
https://git.kernel.org/tip/2a3e3f73a23b4ff2c0065d3a42edc18ad94b7851
Author:Stephane Eranian 
AuthorDate:Wed, 27 May 2020 15:46:57 -07:00
Committer: Ingo Molnar 
CommitterDate: Thu, 28 May 2020 07:58:55 +02:00

perf/x86/rapl: Flip logic on default events visibility

This patch modifies the default visibility of the attribute_group
for each RAPL event. By default if the grp.is_visible field is NULL,
sysfs considers that it must display the attribute group.
If the field is not NULL (callback function), then the return value
of the callback determines the visibility (0 = not visible). The RAPL
attribute groups had the field set to NULL, meaning that unless they
failed the probing from perf_msr_probe(), they would be visible. We want
to avoid having to specify attribute groups that are not supported by the HW
in the rapl_msrs[] array, they don't have an MSR address to begin with.

Therefore, we intialize the visible field of all RAPL attribute groups
to a callback that returns 0. If the RAPL msr goes through probing
and succeeds the is_visible field will be set back to NULL (visible).
If the probing fails the field is set to a callback that return 0 (not visible).

Signed-off-by: Stephane Eranian 
Signed-off-by: Ingo Molnar 
Link: https://lore.kernel.org/r/20200527224659.206129-4-eran...@google.com
---
 arch/x86/events/rapl.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c
index f29935e..8d17af4 100644
--- a/arch/x86/events/rapl.c
+++ b/arch/x86/events/rapl.c
@@ -460,9 +460,16 @@ static struct attribute *rapl_events_cores[] = {
NULL,
 };
 
+static umode_t
+rapl_not_visible(struct kobject *kobj, struct attribute *attr, int i)
+{
+   return 0;
+}
+
 static struct attribute_group rapl_events_cores_group = {
.name  = "events",
.attrs = rapl_events_cores,
+   .is_visible = rapl_not_visible,
 };
 
 static struct attribute *rapl_events_pkg[] = {
@@ -475,6 +482,7 @@ static struct attribute *rapl_events_pkg[] = {
 static struct attribute_group rapl_events_pkg_group = {
.name  = "events",
.attrs = rapl_events_pkg,
+   .is_visible = rapl_not_visible,
 };
 
 static struct attribute *rapl_events_ram[] = {
@@ -487,6 +495,7 @@ static struct attribute *rapl_events_ram[] = {
 static struct attribute_group rapl_events_ram_group = {
.name  = "events",
.attrs = rapl_events_ram,
+   .is_visible = rapl_not_visible,
 };
 
 static struct attribute *rapl_events_gpu[] = {
@@ -499,6 +508,7 @@ static struct attribute *rapl_events_gpu[] = {
 static struct attribute_group rapl_events_gpu_group = {
.name  = "events",
.attrs = rapl_events_gpu,
+   .is_visible = rapl_not_visible,
 };
 
 static struct attribute *rapl_events_psys[] = {
@@ -511,6 +521,7 @@ static struct attribute *rapl_events_psys[] = {
 static struct attribute_group rapl_events_psys_group = {
.name  = "events",
.attrs = rapl_events_psys,
+   .is_visible = rapl_not_visible,
 };
 
 static bool test_msr(int idx, void *data)


[tip: perf/core] perf/x86/rapl: Move RAPL support to common x86 code

2020-05-27 Thread tip-bot2 for Stephane Eranian
The following commit has been merged into the perf/core branch of tip:

Commit-ID: fd3ae1e1587d64ef8cc8e361903d33625458073e
Gitweb:
https://git.kernel.org/tip/fd3ae1e1587d64ef8cc8e361903d33625458073e
Author:Stephane Eranian 
AuthorDate:Wed, 27 May 2020 15:46:55 -07:00
Committer: Ingo Molnar 
CommitterDate: Thu, 28 May 2020 07:58:55 +02:00

perf/x86/rapl: Move RAPL support to common x86 code

To prepare for support of both Intel and AMD RAPL.

As per the AMD PPR, Fam17h support Package RAPL counters to monitor power usage.
The RAPL counter operates as with Intel RAPL, and as such it is beneficial
to share the code.

No change in functionality.

Signed-off-by: Stephane Eranian 
Signed-off-by: Ingo Molnar 
Link: https://lore.kernel.org/r/20200527224659.206129-2-eran...@google.com
---
 arch/x86/events/Kconfig|   6 +-
 arch/x86/events/Makefile   |   1 +-
 arch/x86/events/intel/Makefile |   2 +-
 arch/x86/events/intel/rapl.c   | 802 +
 arch/x86/events/rapl.c | 805 -
 5 files changed, 809 insertions(+), 807 deletions(-)
 delete mode 100644 arch/x86/events/intel/rapl.c
 create mode 100644 arch/x86/events/rapl.c

diff --git a/arch/x86/events/Kconfig b/arch/x86/events/Kconfig
index 9a7a144..4a809c6 100644
--- a/arch/x86/events/Kconfig
+++ b/arch/x86/events/Kconfig
@@ -10,11 +10,11 @@ config PERF_EVENTS_INTEL_UNCORE
available on NehalemEX and more modern processors.
 
 config PERF_EVENTS_INTEL_RAPL
-   tristate "Intel rapl performance events"
-   depends on PERF_EVENTS && CPU_SUP_INTEL && PCI
+   tristate "Intel/AMD rapl performance events"
+   depends on PERF_EVENTS && (CPU_SUP_INTEL || CPU_SUP_AMD) && PCI
default y
---help---
-   Include support for Intel rapl performance events for power
+   Include support for Intel and AMD rapl performance events for power
monitoring on modern processors.
 
 config PERF_EVENTS_INTEL_CSTATE
diff --git a/arch/x86/events/Makefile b/arch/x86/events/Makefile
index 6f1d1fd..12c42eb 100644
--- a/arch/x86/events/Makefile
+++ b/arch/x86/events/Makefile
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-y  += core.o probe.o
+obj-$(PERF_EVENTS_INTEL_RAPL)  += rapl.o
 obj-y  += amd/
 obj-$(CONFIG_X86_LOCAL_APIC)+= msr.o
 obj-$(CONFIG_CPU_SUP_INTEL)+= intel/
diff --git a/arch/x86/events/intel/Makefile b/arch/x86/events/intel/Makefile
index 3468b0c..e67a588 100644
--- a/arch/x86/events/intel/Makefile
+++ b/arch/x86/events/intel/Makefile
@@ -2,8 +2,6 @@
 obj-$(CONFIG_CPU_SUP_INTEL)+= core.o bts.o
 obj-$(CONFIG_CPU_SUP_INTEL)+= ds.o knc.o
 obj-$(CONFIG_CPU_SUP_INTEL)+= lbr.o p4.o p6.o pt.o
-obj-$(CONFIG_PERF_EVENTS_INTEL_RAPL)   += intel-rapl-perf.o
-intel-rapl-perf-objs   := rapl.o
 obj-$(CONFIG_PERF_EVENTS_INTEL_UNCORE) += intel-uncore.o
 intel-uncore-objs  := uncore.o uncore_nhmex.o uncore_snb.o 
uncore_snbep.o
 obj-$(CONFIG_PERF_EVENTS_INTEL_CSTATE) += intel-cstate.o
diff --git a/arch/x86/events/intel/rapl.c b/arch/x86/events/intel/rapl.c
deleted file mode 100644
index 9e1e141..000
--- a/arch/x86/events/intel/rapl.c
+++ /dev/null
@@ -1,802 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * Support Intel RAPL energy consumption counters
- * Copyright (C) 2013 Google, Inc., Stephane Eranian
- *
- * Intel RAPL interface is specified in the IA-32 Manual Vol3b
- * section 14.7.1 (September 2013)
- *
- * RAPL provides more controls than just reporting energy consumption
- * however here we only expose the 3 energy consumption free running
- * counters (pp0, pkg, dram).
- *
- * Each of those counters increments in a power unit defined by the
- * RAPL_POWER_UNIT MSR. On SandyBridge, this unit is 1/(2^16) Joules
- * but it can vary.
- *
- * Counter to rapl events mappings:
- *
- *  pp0 counter: consumption of all physical cores (power plane 0)
- *   event: rapl_energy_cores
- *perf code: 0x1
- *
- *  pkg counter: consumption of the whole processor package
- *   event: rapl_energy_pkg
- *perf code: 0x2
- *
- * dram counter: consumption of the dram domain (servers only)
- *   event: rapl_energy_dram
- *perf code: 0x3
- *
- * gpu counter: consumption of the builtin-gpu domain (client only)
- *   event: rapl_energy_gpu
- *perf code: 0x4
- *
- *  psys counter: consumption of the builtin-psys domain (client only)
- *   event: rapl_energy_psys
- *perf code: 0x5
- *
- * We manage those counters as free running (read-only). They may be
- * use simultaneously by other tools, such as turbostat.
- *
- * The events only support system-wide mode counting. There is no
- * sampling support because it does not make sense and is not
- * supported by the RAPL hardware.
- *
- * Because we want to avoid floating-point operations 

[tip: perf/core] perf/x86/rapl: Add AMD Fam17h RAPL support

2020-05-27 Thread tip-bot2 for Stephane Eranian
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 5cde265384cad739b162cf08afba6da8857778bd
Gitweb:
https://git.kernel.org/tip/5cde265384cad739b162cf08afba6da8857778bd
Author:Stephane Eranian 
AuthorDate:Wed, 27 May 2020 15:46:59 -07:00
Committer: Ingo Molnar 
CommitterDate: Thu, 28 May 2020 07:58:56 +02:00

perf/x86/rapl: Add AMD Fam17h RAPL support

This patch enables AMD Fam17h RAPL support for the Package level metric.
The support is as per AMD Fam17h Model31h (Zen2) and model 00-ffh (Zen1) PPR.

The same output is available via the energy-pkg pseudo event:

  $ perf stat -a -I 1000 --per-socket -e power/energy-pkg/

Signed-off-by: Stephane Eranian 
Signed-off-by: Ingo Molnar 
Link: https://lore.kernel.org/r/20200527224659.206129-6-eran...@google.com
---
 arch/x86/events/rapl.c   | 18 ++
 arch/x86/include/asm/msr-index.h |  3 +++
 2 files changed, 21 insertions(+)

diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c
index 8d17af4..0f2bf59 100644
--- a/arch/x86/events/rapl.c
+++ b/arch/x86/events/rapl.c
@@ -537,6 +537,16 @@ static struct perf_msr intel_rapl_msrs[] = {
[PERF_RAPL_PSYS] = { MSR_PLATFORM_ENERGY_STATUS, 
&rapl_events_psys_group,  test_msr },
 };
 
+/*
+ * Force to PERF_RAPL_MAX size due to:
+ * - perf_msr_probe(PERF_RAPL_MAX)
+ * - want to use same event codes across both architectures
+ */
+static struct perf_msr amd_rapl_msrs[PERF_RAPL_MAX] = {
+   [PERF_RAPL_PKG]  = { MSR_AMD_PKG_ENERGY_STATUS,  
&rapl_events_pkg_group,   test_msr },
+};
+
+
 static int rapl_cpu_offline(unsigned int cpu)
 {
struct rapl_pmu *pmu = cpu_to_rapl_pmu(cpu);
@@ -740,6 +750,13 @@ static struct rapl_model model_skl = {
.rapl_msrs  = intel_rapl_msrs,
 };
 
+static struct rapl_model model_amd_fam17h = {
+   .events = BIT(PERF_RAPL_PKG),
+   .apply_quirk= false,
+   .msr_power_unit = MSR_AMD_RAPL_POWER_UNIT,
+   .rapl_msrs  = amd_rapl_msrs,
+};
+
 static const struct x86_cpu_id rapl_model_match[] __initconst = {
X86_MATCH_INTEL_FAM6_MODEL(SANDYBRIDGE, &model_snb),
X86_MATCH_INTEL_FAM6_MODEL(SANDYBRIDGE_X,   &model_snbep),
@@ -770,6 +787,7 @@ static const struct x86_cpu_id rapl_model_match[] 
__initconst = {
X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X,   &model_hsx),
X86_MATCH_INTEL_FAM6_MODEL(COMETLAKE_L, &model_skl),
X86_MATCH_INTEL_FAM6_MODEL(COMETLAKE,   &model_skl),
+   X86_MATCH_VENDOR_FAM(AMD, 0x17, &model_amd_fam17h),
{},
 };
 MODULE_DEVICE_TABLE(x86cpu, rapl_model_match);
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index 12c9684..ef452b8 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -301,6 +301,9 @@
 #define MSR_PP1_ENERGY_STATUS  0x0641
 #define MSR_PP1_POLICY 0x0642
 
+#define MSR_AMD_PKG_ENERGY_STATUS  0xc001029b
+#define MSR_AMD_RAPL_POWER_UNIT0xc0010299
+
 /* Config TDP MSRs */
 #define MSR_CONFIG_TDP_NOMINAL 0x0648
 #define MSR_CONFIG_TDP_LEVEL_1 0x0649


[tip: perf/core] perf/x86/rapl: Make perf_probe_msr() more robust and flexible

2020-05-27 Thread tip-bot2 for Stephane Eranian
The following commit has been merged into the perf/core branch of tip:

Commit-ID: 4c953f879460bf65ea3c119354026b126fe8ee57
Gitweb:
https://git.kernel.org/tip/4c953f879460bf65ea3c119354026b126fe8ee57
Author:Stephane Eranian 
AuthorDate:Wed, 27 May 2020 15:46:58 -07:00
Committer: Ingo Molnar 
CommitterDate: Thu, 28 May 2020 07:58:55 +02:00

perf/x86/rapl: Make perf_probe_msr() more robust and flexible

This patch modifies perf_probe_msr() by allowing passing of
struct perf_msr array where some entries are not populated, i.e.,
they have either an msr address of 0 or no attribute_group pointer.
This helps with certain call paths, e.g., RAPL.

In case the grp is NULL, the default sysfs visibility rule
applies which is to make the group visible. Without the patch,
you would get a kernel crash with a NULL group.

Signed-off-by: Stephane Eranian 
Signed-off-by: Ingo Molnar 
Link: https://lore.kernel.org/r/20200527224659.206129-5-eran...@google.com
---
 arch/x86/events/probe.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/arch/x86/events/probe.c b/arch/x86/events/probe.c
index c2ede2f..136a1e8 100644
--- a/arch/x86/events/probe.c
+++ b/arch/x86/events/probe.c
@@ -10,6 +10,11 @@ not_visible(struct kobject *kobj, struct attribute *attr, 
int i)
return 0;
 }
 
+/*
+ * Accepts msr[] array with non populated entries as long as either
+ * msr[i].msr is 0 or msr[i].grp is NULL. Note that the default sysfs
+ * visibility is visible when group->is_visible callback is set.
+ */
 unsigned long
 perf_msr_probe(struct perf_msr *msr, int cnt, bool zero, void *data)
 {
@@ -24,8 +29,16 @@ perf_msr_probe(struct perf_msr *msr, int cnt, bool zero, 
void *data)
if (!msr[bit].no_check) {
struct attribute_group *grp = msr[bit].grp;
 
+   /* skip entry with no group */
+   if (!grp)
+   continue;
+
grp->is_visible = not_visible;
 
+   /* skip unpopulated entry */
+   if (!msr[bit].msr)
+   continue;
+
if (msr[bit].test && !msr[bit].test(bit, data))
continue;
/* Virt sucks; you cannot tell if a R/O MSR is present 
:/ */


Re: [PATCH 0/2] Introduce PCI_FIXUP_IOMMU

2020-05-27 Thread Zhangfei Gao

Hi, Bjorn

On 2020/5/28 上午2:18, Bjorn Helgaas wrote:

On Tue, May 26, 2020 at 07:49:07PM +0800, Zhangfei Gao wrote:

Some platform devices appear as PCI but are actually on the AMBA bus,
and they need fixup in drivers/pci/quirks.c handling iommu_fwnode.
Here introducing PCI_FIXUP_IOMMU, which is called after iommu_fwnode
is allocated, instead of reusing PCI_FIXUP_FINAL since it will slow
down iommu probing as all devices in fixup final list will be
reprocessed, suggested by Joerg, [1]

Is this slowdown significant?  We already iterate over every device
when applying PCI_FIXUP_FINAL quirks, so if we used the existing
PCI_FIXUP_FINAL, we wouldn't be adding a new loop.  We would only be
adding two more iterations to the loop in pci_do_fixups() that tries
to match quirks against the current device.  I doubt that would be a
measurable slowdown.
I do not notice the difference when compared fixup_iommu and fixup_final 
via get_jiffies_64,

since in our platform no other pci fixup is registered.

Here the plan is adding pci_fixup_device in iommu_fwspec_init,
so if using fixup_final the iteration will be done again here.




For example:
Hisilicon platform device need fixup in
drivers/pci/quirks.c handling fwspec->can_stall, which is introduced in [2]

+static void quirk_huawei_pcie_sva(struct pci_dev *pdev)
+{
+struct iommu_fwspec *fwspec;
+
+pdev->eetlp_prefix_path = 1;
+fwspec = dev_iommu_fwspec_get(&pdev->dev);
+if (fwspec)
+fwspec->can_stall = 1;
+}
+
+DECLARE_PCI_FIXUP_IOMMU(PCI_VENDOR_ID_HUAWEI, 0xa250, quirk_huawei_pcie_sva);
+DECLARE_PCI_iFIXUP_IOMMU(PCI_VENDOR_ID_HUAWEI, 0xa251, quirk_huawei_pcie_sva);

[1] https://www.spinics.net/lists/iommu/msg44591.html
[2] https://www.spinics.net/lists/linux-pci/msg94559.html

If you reference these in the commit logs, please use lore.kernel.org
links instead of spinics.

Got it, thanks Bjorn.





Re: [PATCH 02/10] iommu/amd: Unexport get_dev_data()

2020-05-27 Thread Joerg Roedel
On Wed, May 27, 2020 at 11:13:53PM -0700, Christoph Hellwig wrote:
> On Wed, May 27, 2020 at 01:53:05PM +0200, Joerg Roedel wrote:
> > From: Joerg Roedel 
> > 
> > This function is internal to the AMD IOMMU driver and only exported
> > because the amd_iommu_v2 modules calls it. But the reason it is called
> > from there could better be handled by amd_iommu_is_attach_deferred().
> > So unexport get_dev_data() and use amd_iommu_is_attach_deferred()
> > instead.
> 
> Btw, what is the reason amd_iommu_v2 is a separate module?  It is
> very little code, and other drivers seem to just integrate such
> functionality.

The module contains optional functionality that is only needed by the
amd_kfd driver, which itself only does something useful on (newer) AMD
GPUs. So I made it a separate module back in the days to save the memory
when it is not needed. But this caused other problems with the amd_kfd
module, when they got loaded in the wrong order. And the module is often
loaded by distros anyway, as it successfully loads even when no AMD
IOMMU is in the system. The reason for that was to have the symbols
available for drivers which can optionally use AMD IOMMUv2
functionality.

In fact I have already thought about making it built-in, just havn't
done so yet.


Regards,

Joerg


[RFC PATCH v5 10/13] riscv: Add task switch support for vector

2020-05-27 Thread Greentime Hu
From: Guo Ren 

This patch adds task switch support for vector. It supports lazy
save and restore mechanism. It also supports all lengths of vlen.

[greentime...@sifive.com: add support for dynamic vlen, fix
__vstate_clean() and lazy save/restore bug]
[nick.kni...@sifive.com: Rewrite vector.S to support dynamic vlen, xlen and
code refine]
Signed-off-by: Nick Knight 
Signed-off-by: Greentime Hu 
Signed-off-by: Guo Ren 
---
 arch/riscv/include/asm/switch_to.h | 71 +
 arch/riscv/kernel/Makefile |  1 +
 arch/riscv/kernel/process.c| 40 ++
 arch/riscv/kernel/vector.S | 84 ++
 4 files changed, 196 insertions(+)
 create mode 100644 arch/riscv/kernel/vector.S

diff --git a/arch/riscv/include/asm/switch_to.h 
b/arch/riscv/include/asm/switch_to.h
index b9234e7178d0..a047dd75e09d 100644
--- a/arch/riscv/include/asm/switch_to.h
+++ b/arch/riscv/include/asm/switch_to.h
@@ -6,10 +6,12 @@
 #ifndef _ASM_RISCV_SWITCH_TO_H
 #define _ASM_RISCV_SWITCH_TO_H
 
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
 
 #ifdef CONFIG_FPU
 extern void __fstate_save(struct task_struct *save_to);
@@ -63,6 +65,73 @@ extern bool has_fpu;
 #define __switch_to_fpu(__prev, __next) do { } while (0)
 #endif
 
+#ifdef CONFIG_VECTOR
+extern bool has_vector;
+extern unsigned long riscv_vsize;
+extern void __vstate_save(struct __riscv_v_state *save_to, void *datap);
+extern void __vstate_restore(struct __riscv_v_state *restore_from, void 
*datap);
+
+static inline void __vstate_clean(struct pt_regs *regs)
+{
+   regs->status = (regs->status & ~(SR_VS)) | SR_VS_CLEAN;
+}
+
+static inline void vstate_off(struct task_struct *task,
+ struct pt_regs *regs)
+{
+   regs->status = (regs->status & ~SR_VS) | SR_VS_OFF;
+}
+
+static inline void vstate_save(struct task_struct *task,
+  struct pt_regs *regs)
+{
+   if ((regs->status & SR_VS) == SR_VS_DIRTY) {
+   struct __riscv_v_state *vstate = &(task->thread.vstate);
+
+   /* Allocate space for vector registers. */
+   if (!vstate->datap) {
+   vstate->datap = kzalloc(riscv_vsize, GFP_KERNEL);
+   vstate->size = riscv_vsize;
+   }
+   __vstate_save(vstate, vstate->datap);
+   __vstate_clean(regs);
+   }
+}
+
+static inline void vstate_restore(struct task_struct *task,
+ struct pt_regs *regs)
+{
+   if ((regs->status & SR_VS) != SR_VS_OFF) {
+   struct __riscv_v_state *vstate = &(task->thread.vstate);
+
+   /* Allocate space for vector registers. */
+   if (!vstate->datap) {
+   vstate->datap = kzalloc(riscv_vsize, GFP_KERNEL);
+   vstate->size = riscv_vsize;
+   }
+   __vstate_restore(vstate, vstate->datap);
+   __vstate_clean(regs);
+   }
+}
+
+static inline void __switch_to_vector(struct task_struct *prev,
+  struct task_struct *next)
+{
+   struct pt_regs *regs;
+
+   regs = task_pt_regs(prev);
+   if (unlikely(regs->status & SR_SD))
+   vstate_save(prev, regs);
+   vstate_restore(next, task_pt_regs(next));
+}
+
+#else
+#define has_vector false
+#define vstate_save(task, regs) do { } while (0)
+#define vstate_restore(task, regs) do { } while (0)
+#define __switch_to_vector(__prev, __next) do { } while (0)
+#endif
+
 extern struct task_struct *__switch_to(struct task_struct *,
   struct task_struct *);
 
@@ -72,6 +141,8 @@ do { \
struct task_struct *__next = (next);\
if (has_fpu)\
__switch_to_fpu(__prev, __next);\
+   if (has_vector) \
+   __switch_to_vector(__prev, __next); \
((last) = __switch_to(__prev, __next)); \
 } while (0)
 
diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile
index 86c83081044f..dee489a1a526 100644
--- a/arch/riscv/kernel/Makefile
+++ b/arch/riscv/kernel/Makefile
@@ -33,6 +33,7 @@ obj-$(CONFIG_MMU) += vdso.o vdso/
 
 obj-$(CONFIG_RISCV_M_MODE) += clint.o traps_misaligned.o
 obj-$(CONFIG_FPU)  += fpu.o
+obj-$(CONFIG_VECTOR)   += vector.o
 obj-$(CONFIG_SMP)  += smpboot.o
 obj-$(CONFIG_SMP)  += smp.o
 obj-$(CONFIG_SMP)  += cpu_ops.o
diff --git a/arch/riscv/kernel/process.c b/arch/riscv/kernel/process.c
index 610c11e91606..fc8761c04e9f 100644
--- a/arch/riscv/kernel/process.c
+++ b/arch/riscv/kernel/process.c
@@ -76,6 +76,16 @@ void start_thread(struct pt_regs *regs, unsigned long pc,
 */
fstate_restore(current, regs);
}
+
+   if (has_vector) {

[RFC PATCH v5 06/13] riscv: Add vector feature to compile

2020-05-27 Thread Greentime Hu
From: Guo Ren 

This patch adds a new config option which could enable assembler's
vector feature.

Signed-off-by: Guo Ren 
---
 arch/riscv/Kconfig  | 9 +
 arch/riscv/Makefile | 1 +
 2 files changed, 10 insertions(+)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 74f82cf4f781..3b742d949a09 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -305,6 +305,15 @@ config FPU
 
  If you don't know what to do here, say Y.
 
+config VECTOR
+   bool "VECTOR support"
+   default n
+   help
+ Say N here if you want to disable all vector related procedure
+ in the kernel.
+
+ If you don't know what to do here, say Y.
+
 endmenu
 
 menu "Kernel features"
diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index 957d064bead0..7c80c95582e3 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -46,6 +46,7 @@ riscv-march-aflags-$(CONFIG_ARCH_RV32I)   := 
rv32ima
 riscv-march-aflags-$(CONFIG_ARCH_RV64I):= rv64ima
 riscv-march-aflags-$(CONFIG_FPU)   := $(riscv-march-aflags-y)fd
 riscv-march-aflags-$(CONFIG_RISCV_ISA_C)   := $(riscv-march-aflags-y)c
+riscv-march-aflags-$(CONFIG_VECTOR):= $(riscv-march-aflags-y)v
 
 KBUILD_CFLAGS += -march=$(riscv-march-cflags-y)
 KBUILD_AFLAGS += -march=$(riscv-march-aflags-y)
-- 
2.26.2



[RFC PATCH v5 07/13] riscv: Add has_vector/riscv_vsize to save vector features.

2020-05-27 Thread Greentime Hu
From: Guo Ren 

This patch is used to detect vector support status of CPU and use
riscv_vsize to save the size of all the vector registers. It assumes
all harts has the same capabilities in SMP system.

[greentime...@sifive.com: add support for dynamic vlen]
Signed-off-by: Greentime Hu 
Signed-off-by: Guo Ren 
---
 arch/riscv/kernel/cpufeature.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c
index c8527d770c98..5a68a926da68 100644
--- a/arch/riscv/kernel/cpufeature.c
+++ b/arch/riscv/kernel/cpufeature.c
@@ -16,6 +16,10 @@ unsigned long elf_hwcap __read_mostly;
 #ifdef CONFIG_FPU
 bool has_fpu __read_mostly;
 #endif
+#ifdef CONFIG_VECTOR
+bool has_vector __read_mostly;
+unsigned long riscv_vsize __read_mostly;
+#endif
 
 void riscv_fill_hwcap(void)
 {
@@ -73,4 +77,11 @@ void riscv_fill_hwcap(void)
if (elf_hwcap & (COMPAT_HWCAP_ISA_F | COMPAT_HWCAP_ISA_D))
has_fpu = true;
 #endif
+
+#ifdef CONFIG_VECTOR
+   if (elf_hwcap & COMPAT_HWCAP_ISA_V) {
+   has_vector = true;
+   riscv_vsize = csr_read(CSR_VLENB) * 32;
+   }
+#endif
 }
-- 
2.26.2



[RFC PATCH v5 09/13] riscv: Add vector struct and assembler definitions

2020-05-27 Thread Greentime Hu
From: Guo Ren 

Add vector state context struct in struct thread and asm-offsets.c
definitions.

The vector registers will be saved in datap pointer of __riscv_v_state. It
will be dynamically allocated in kernel space. It will be put right after
the __riscv_v_state data structure in user space.

[greentime...@sifive.com: add support for dynamic vlen, add vcsr and remove
vxsat, vxrm because these data can be get in vcsr, add new macros for
_riscv_v_state elements offset and remove unused ones]
Signed-off-by: Greentime Hu 
Signed-off-by: Guo Ren 
---
 arch/riscv/include/asm/processor.h   |  1 +
 arch/riscv/include/uapi/asm/ptrace.h | 13 +
 arch/riscv/kernel/asm-offsets.c  |  8 
 3 files changed, 22 insertions(+)

diff --git a/arch/riscv/include/asm/processor.h 
b/arch/riscv/include/asm/processor.h
index 3ddb798264f1..217273375cfb 100644
--- a/arch/riscv/include/asm/processor.h
+++ b/arch/riscv/include/asm/processor.h
@@ -32,6 +32,7 @@ struct thread_struct {
unsigned long sp;   /* Kernel mode stack */
unsigned long s[12];/* s[0]: frame pointer */
struct __riscv_d_ext_state fstate;
+   struct __riscv_v_state vstate;
 };
 
 #define INIT_THREAD {  \
diff --git a/arch/riscv/include/uapi/asm/ptrace.h 
b/arch/riscv/include/uapi/asm/ptrace.h
index 882547f6bd5c..661b0466b850 100644
--- a/arch/riscv/include/uapi/asm/ptrace.h
+++ b/arch/riscv/include/uapi/asm/ptrace.h
@@ -77,6 +77,19 @@ union __riscv_fp_state {
struct __riscv_q_ext_state q;
 };
 
+struct __riscv_v_state {
+   __u32 magic;
+   __u32 size;
+   unsigned long vstart;
+   unsigned long vl;
+   unsigned long vtype;
+   unsigned long vcsr;
+   void *datap;
+#if __riscv_xlen == 32
+   __u32 __padding;
+#endif
+} __attribute__((aligned(16)));
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* _UAPI_ASM_RISCV_PTRACE_H */
diff --git a/arch/riscv/kernel/asm-offsets.c b/arch/riscv/kernel/asm-offsets.c
index 07cb9c10de4e..6627fde230b2 100644
--- a/arch/riscv/kernel/asm-offsets.c
+++ b/arch/riscv/kernel/asm-offsets.c
@@ -70,6 +70,14 @@ void asm_offsets(void)
OFFSET(TASK_THREAD_F31, task_struct, thread.fstate.f[31]);
OFFSET(TASK_THREAD_FCSR, task_struct, thread.fstate.fcsr);
 
+   OFFSET(RISCV_V_STATE_MAGIC, __riscv_v_state, magic);
+   OFFSET(RISCV_V_STATE_SIZE, __riscv_v_state, size);
+   OFFSET(RISCV_V_STATE_VSTART, __riscv_v_state, vstart);
+   OFFSET(RISCV_V_STATE_VL, __riscv_v_state, vl);
+   OFFSET(RISCV_V_STATE_VTYPE, __riscv_v_state, vtype);
+   OFFSET(RISCV_V_STATE_VCSR, __riscv_v_state, vcsr);
+   OFFSET(RISCV_V_STATE_DATAP, __riscv_v_state, datap);
+
DEFINE(PT_SIZE, sizeof(struct pt_regs));
OFFSET(PT_EPC, pt_regs, epc);
OFFSET(PT_RA, pt_regs, ra);
-- 
2.26.2



[RFC PATCH v5 04/13] riscv: Extending cpufeature.c to detect V-extension

2020-05-27 Thread Greentime Hu
From: Guo Ren 

From: Guo Ren 

Current cpufeature.c doesn't support detecting V-extension, because
"rv64" also contain a 'v' letter and we need to skip it.

Signed-off-by: Guo Ren 
Reviewed-by: Anup Patel 
---
 arch/riscv/include/uapi/asm/hwcap.h | 1 +
 arch/riscv/kernel/cpufeature.c  | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/include/uapi/asm/hwcap.h 
b/arch/riscv/include/uapi/asm/hwcap.h
index dee98ee28318..a913e9a38819 100644
--- a/arch/riscv/include/uapi/asm/hwcap.h
+++ b/arch/riscv/include/uapi/asm/hwcap.h
@@ -21,5 +21,6 @@
 #define COMPAT_HWCAP_ISA_F (1 << ('F' - 'A'))
 #define COMPAT_HWCAP_ISA_D (1 << ('D' - 'A'))
 #define COMPAT_HWCAP_ISA_C (1 << ('C' - 'A'))
+#define COMPAT_HWCAP_ISA_V (1 << ('V' - 'A'))
 
 #endif /* _UAPI_ASM_RISCV_HWCAP_H */
diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c
index a5ad00043104..c8527d770c98 100644
--- a/arch/riscv/kernel/cpufeature.c
+++ b/arch/riscv/kernel/cpufeature.c
@@ -30,6 +30,7 @@ void riscv_fill_hwcap(void)
isa2hwcap['f'] = isa2hwcap['F'] = COMPAT_HWCAP_ISA_F;
isa2hwcap['d'] = isa2hwcap['D'] = COMPAT_HWCAP_ISA_D;
isa2hwcap['c'] = isa2hwcap['C'] = COMPAT_HWCAP_ISA_C;
+   isa2hwcap['v'] = isa2hwcap['V'] = COMPAT_HWCAP_ISA_V;
 
elf_hwcap = 0;
 
@@ -44,7 +45,8 @@ void riscv_fill_hwcap(void)
continue;
}
 
-   for (i = 0; i < strlen(isa); ++i)
+   /* Skip rv64/rv32 to support v/V:vector */
+   for (i = 4; i < strlen(isa); ++i)
this_hwcap |= isa2hwcap[(unsigned char)(isa[i])];
 
/*
-- 
2.26.2



[PATCH v2] media: exynos4-is: Add missed check for pinctrl_lookup_state()

2020-05-27 Thread Chuhong Yuan
fimc_md_get_pinctrl() misses a check for pinctrl_lookup_state().
Add the missed check to fix it.

Fixes: 4163851f7b99 ("[media] s5p-fimc: Use pinctrl API for camera ports 
configuration]") 
Signed-off-by: Chuhong Yuan 
---
Changes in v2:
  - Add fixes tag.

 drivers/media/platform/exynos4-is/media-dev.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/media/platform/exynos4-is/media-dev.c 
b/drivers/media/platform/exynos4-is/media-dev.c
index 9aaf3b8060d5..9c31d950cddf 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -1270,6 +1270,9 @@ static int fimc_md_get_pinctrl(struct fimc_md *fmd)
 
pctl->state_idle = pinctrl_lookup_state(pctl->pinctrl,
PINCTRL_STATE_IDLE);
+   if (IS_ERR(pctl->state_idle))
+   return PTR_ERR(pctl->state_idle);
+
return 0;
 }
 
-- 
2.26.2



[RFC PATCH v5 11/13] riscv: Add ptrace vector support

2020-05-27 Thread Greentime Hu
From: Guo Ren 

This patch adds ptrace support for riscv vector. The vector registers will
be saved in datap pointer of __riscv_v_state. This pointer will be set
right after the __riscv_v_state data structure then it will be put in ubuf
for ptrace system call to get or set. It will check if the datap got from
ubuf is set to the correct address or not when the ptrace system call is
trying to set the vector registers.

[greentime...@sifive.com: add support for dynamic vlen, fix vtype not
saved bug]
Signed-off-by: Greentime Hu 
Signed-off-by: Guo Ren 
---
 arch/riscv/include/uapi/asm/elf.h |   1 +
 arch/riscv/kernel/ptrace.c| 115 ++
 include/uapi/linux/elf.h  |   1 +
 3 files changed, 117 insertions(+)

diff --git a/arch/riscv/include/uapi/asm/elf.h 
b/arch/riscv/include/uapi/asm/elf.h
index d696d6610231..099434d075a7 100644
--- a/arch/riscv/include/uapi/asm/elf.h
+++ b/arch/riscv/include/uapi/asm/elf.h
@@ -23,6 +23,7 @@ typedef struct user_regs_struct elf_gregset_t;
 typedef __u64 elf_fpreg_t;
 typedef union __riscv_fp_state elf_fpregset_t;
 #define ELF_NFPREG (sizeof(struct __riscv_d_ext_state) / sizeof(elf_fpreg_t))
+#define ELF_NVREG  (sizeof(struct __riscv_v_state) / sizeof(elf_greg_t))
 
 #if __riscv_xlen == 64
 #define ELF_RISCV_R_SYM(r_info)ELF64_R_SYM(r_info)
diff --git a/arch/riscv/kernel/ptrace.c b/arch/riscv/kernel/ptrace.c
index 444dc7b0fd78..ff846a53cd8d 100644
--- a/arch/riscv/kernel/ptrace.c
+++ b/arch/riscv/kernel/ptrace.c
@@ -10,6 +10,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -26,6 +27,9 @@ enum riscv_regset {
 #ifdef CONFIG_FPU
REGSET_F,
 #endif
+#ifdef CONFIG_VECTOR
+   REGSET_V,
+#endif
 };
 
 static int riscv_gpr_get(struct task_struct *target,
@@ -92,6 +96,107 @@ static int riscv_fpr_set(struct task_struct *target,
 }
 #endif
 
+#ifdef CONFIG_VECTOR
+static int riscv_vr_get(struct task_struct *target,
+const struct user_regset *regset,
+unsigned int pos, unsigned int count,
+void *kbuf, void __user *ubuf)
+{
+   int ret;
+   struct __riscv_v_state *vstate = &target->thread.vstate;
+   /* Set the datap right after the address of vstate. */
+   void *datap = ubuf + sizeof(struct __riscv_v_state);
+   u32 magic = RVV_MAGIC;
+
+   /* Copy the magic number. */
+   ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &magic, 0,
+ sizeof(u32));
+   if (unlikely(ret))
+   return ret;
+
+   /* Copy rest of vstate except datap. */
+   ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, vstate, 0,
+ RISCV_V_STATE_DATAP);
+   if (unlikely(ret))
+   return ret;
+
+   /* Copy the pointer datap itself. */
+   pos = 0;
+   ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &datap, 0,
+ sizeof(vstate->datap));
+   if (unlikely(ret))
+   return ret;
+
+#if __riscv_xlen == 32
+   /* Skip copy _padding. */
+   size = sizeof(vstate->__padding);
+   count -= size;
+   ubuf += size;
+#endif
+
+   /* Copy all the vector registers. */
+   pos = 0;
+   ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
+ vstate->datap, 0, vstate->size);
+   return ret;
+}
+
+static int riscv_vr_set(struct task_struct *target,
+const struct user_regset *regset,
+unsigned int pos, unsigned int count,
+const void *kbuf, const void __user *ubuf)
+{
+   int ret, size;
+   struct __riscv_v_state *vstate = &target->thread.vstate;
+   const void *datap = ubuf + sizeof(struct __riscv_v_state);
+   const void *datap_addr = ubuf + RISCV_V_STATE_DATAP;
+   long val_datap;
+
+   /* Skip copy magic because kernel doesn't need to use it. */
+   size = sizeof(vstate->magic);
+   pos += size;
+   count -= size;
+   ubuf += size;
+
+   /* Copy rest of the vstate except datap and __padding. */
+   ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, vstate, 0,
+RISCV_V_STATE_DATAP);
+   if (unlikely(ret))
+   return ret;
+
+   /* Check if the datap is correct address of ubuf. */
+   __get_user(val_datap, (long *)datap_addr);
+   if (val_datap != (long)datap)
+   return -EFAULT;
+
+   /* Skip copy datap. */
+   size = sizeof(vstate->datap);
+   count -= size;
+   ubuf += size;
+
+#if __riscv_xlen == 32
+   /* Skip copy _padding. */
+   size = sizeof(vstate->__padding);
+   count -= size;
+   ubuf += size;
+#endif
+
+   /* Copy all the vector registers. */
+   pos = 0;
+   ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, vstate->datap,
+0,

[RFC PATCH v5 13/13] riscv: signal: Report signal frame size to userspace via auxv

2020-05-27 Thread Greentime Hu
From: Vincent Chen 

The vector register belongs to the signal context. They need to be stored
and restored as entering and leaving the signal handler. According to the
V-extension specification, the maximum length of the vector registers can
be 2^(XLEN-1). Hence, if userspace refers to the MINSIGSTKSZ #define
(2KB) to create a sigframe, it may not be enough. To resolve this problem,
this patch refers to the commit 94b07c1f8c39c
("arm64: signal: Report signal frame size to userspace via auxv") to enable
userspace to know the minimum required sigframe size through the auxiliary
vector and use it to allocate enough memory for signal context.

Signed-off-by: Vincent Chen 
---
 arch/riscv/include/asm/elf.h | 17 +
 arch/riscv/include/asm/processor.h   |  2 ++
 arch/riscv/include/uapi/asm/auxvec.h |  2 ++
 arch/riscv/kernel/setup.c|  5 +
 arch/riscv/kernel/signal.c   | 16 
 5 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h
index d83a4efd052b..b6b15fc5f784 100644
--- a/arch/riscv/include/asm/elf.h
+++ b/arch/riscv/include/asm/elf.h
@@ -57,10 +57,19 @@ extern unsigned long elf_hwcap;
 #define ELF_PLATFORM   (NULL)
 
 #ifdef CONFIG_MMU
-#define ARCH_DLINFO\
-do {   \
-   NEW_AUX_ENT(AT_SYSINFO_EHDR,\
-   (elf_addr_t)current->mm->context.vdso); \
+#define ARCH_DLINFO \
+do {\
+   NEW_AUX_ENT(AT_SYSINFO_EHDR, \
+   (elf_addr_t)current->mm->context.vdso);  \
+   /*   \
+* Should always be nonzero unless there's a kernel bug. \
+* If we haven't determined a sensible value to give to  \
+* userspace, omit the entry:\
+*/  \
+   if (likely(signal_minsigstksz))  \
+   NEW_AUX_ENT(AT_MINSIGSTKSZ, signal_minsigstksz); \
+   else \
+   NEW_AUX_ENT(AT_IGNORE, 0);   \
 } while (0)
 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
 struct linux_binprm;
diff --git a/arch/riscv/include/asm/processor.h 
b/arch/riscv/include/asm/processor.h
index 217273375cfb..5be2da702897 100644
--- a/arch/riscv/include/asm/processor.h
+++ b/arch/riscv/include/asm/processor.h
@@ -7,6 +7,7 @@
 #define _ASM_RISCV_PROCESSOR_H
 
 #include 
+#include 
 
 #include 
 
@@ -79,6 +80,7 @@ int riscv_of_processor_hartid(struct device_node *node);
 
 extern void riscv_fill_hwcap(void);
 
+extern unsigned long signal_minsigstksz __ro_after_init;
 #endif /* __ASSEMBLY__ */
 
 #endif /* _ASM_RISCV_PROCESSOR_H */
diff --git a/arch/riscv/include/uapi/asm/auxvec.h 
b/arch/riscv/include/uapi/asm/auxvec.h
index d86cb17bbabe..9745a01e5e61 100644
--- a/arch/riscv/include/uapi/asm/auxvec.h
+++ b/arch/riscv/include/uapi/asm/auxvec.h
@@ -10,4 +10,6 @@
 /* vDSO location */
 #define AT_SYSINFO_EHDR 33
 
+#define AT_MINSIGSTKSZ 51
+
 #endif /* _UAPI_ASM_RISCV_AUXVEC_H */
diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index 145128a7e560..6220e25ea9b0 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -62,6 +63,8 @@ void __init parse_dtb(void)
 #endif
 }
 
+extern void __init minsigstksz_setup(void);
+
 void __init setup_arch(char **cmdline_p)
 {
init_mm.start_code = (unsigned long) _stext;
@@ -95,6 +98,8 @@ void __init setup_arch(char **cmdline_p)
 #endif
 
riscv_fill_hwcap();
+
+   minsigstksz_setup();
 }
 
 static int __init topology_init(void)
diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c
index 9ada6f74bb95..4f81251867e6 100644
--- a/arch/riscv/kernel/signal.c
+++ b/arch/riscv/kernel/signal.c
@@ -404,3 +404,19 @@ asmlinkage __visible void do_notify_resume(struct pt_regs 
*regs,
tracehook_notify_resume(regs);
}
 }
+
+unsigned long __ro_after_init signal_minsigstksz;
+
+/*
+ * Determine the stack space required for guaranteed signal devliery.
+ * This function is used to populate AT_MINSIGSTKSZ at process startup.
+ * cpufeatures setup is assumed to be complete.
+ */
+void __init minsigstksz_setup(void)
+{
+   signal_minsigstksz = sizeof(struct rt_sigframe);
+#ifdef CONFIG_VECTOR
+   if (has_vector)
+   signal_minsigstksz += riscv_vsize;
+#endif
+}
-- 
2.26.2



[PATCH v2] iio: mma8452: Add missed iio_device_unregister() call in mma8452_probe()

2020-05-27 Thread Chuhong Yuan
The function iio_device_register() was called in mma8452_probe().
But the function iio_device_unregister() was not called after
a call of the function mma8452_set_freefall_mode() failed.
Thus add the missed function call for one error case.

Fixes: 1a965d405fc6 ("drivers:iio:accel:mma8452: added cleanup provision in 
case of failure.")
Signed-off-by: Chuhong Yuan 
---
Changes in v2:
  - Add fixes tag.
  - Modify description.

 drivers/iio/accel/mma8452.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index 00e100fc845a..813bca7cfc3e 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -1685,10 +1685,13 @@ static int mma8452_probe(struct i2c_client *client,
 
ret = mma8452_set_freefall_mode(data, false);
if (ret < 0)
-   goto buffer_cleanup;
+   goto unregister_device;
 
return 0;
 
+unregister_device:
+   iio_device_unregister(indio_dev);
+
 buffer_cleanup:
iio_triggered_buffer_cleanup(indio_dev);
 
-- 
2.26.2



[RFC PATCH v5 00/13] riscv: Add vector ISA support

2020-05-27 Thread Greentime Hu
This patchset is based on Guo Ren's v3 patchset to add dynamic vlen vector
support for all different kinds of vector length in riscv. To make this
happened we defined a new __riscv_v_state in sigcontext to save the vector
related registers. In kernel space, the datap pointer in __riscv_v_state
will be allocated dynamically to save vector registers. In user space,
datap will point to the address right after the __riscv_v_state data
structure to save vector registers in stack of signal handler. So does the
implementation in ptrace, they will be saved in ubuf in which we put the
__riscv_v_state data structure and datap pointer points to the address
right after the __riscv_v_state for saving vector registers. This patchset
also fixes several bugs for vector lazy save/restore mechanism and vtype
not saving issue. It also adds new CSR support for vector based on the 0.9
vector spec and clean up some unused macros.

This patchset is rebased to v5.7-rc4 and it is tested by running several
vector programs simultaneously. It also can get the correct ucontext_t in
signal handler and restore correct context after sigreturn. It is also
tested with ptrace() syscall to use PTRACE_GETREGSET/PTRACE_SETREGSET to
get/set the vector registers. I have tested vlen=128 and vlen=256 cases in
virt machine of qemu-system-riscv32 and qemu-system-riscv64 provided by
Zhiwei Lui.

Since the vector spec is under developing, there might still need some
changes. For example the vle.v/vse.v instructions will be replaced with
proper instructions. The reason that I don't replace the instruction in
this patchset is because that the Qemu doesn't fully support 0.9 spec yet.
I have no simulator to test. We may need to discuss the default value of
MINSIGSTKSZ and SIGSTKSZ. They might also need to set a proper number. They
are 2048 and 8096 now. Since the stack in signal will be reserved for
ucontext and the vector registers might be larger and larger someday, these
two macros will need to be defined as a proper value or maybe we should
provide a better mechanism to provide user to get a better default signal
stack size.


 [1] https://github.com/romanheros/qemu/tree/linux-vector-dev
 [2] https://blog.linuxplumbersconf.org/2017/ocw/sessions/4671.html
 [3] https://github.com/riscv/riscv-v-spec/blob/master/v-spec.adoc

---
Changelog V5
 - Using regset_size() correctly in generic ptrace
 - Fix the ptrace porting
 - Fix compile warning

Changelog V4
 - Support dynamic vlen
 - Fix bugs: lazy save/resotre, not saving vtype
 - Update VS bit offset based on latest vector spec
 - Add new vector csr based on latest vector spec
 - Code refine and removed unused macros

Changelog V3
 - Rebase linux-5.6-rc3 and tested with qemu
 - Seperate patches with Anup's advice
 - Give out a ABI puzzle with unlimited vlen

Changelog V2
 - Fixup typo "vecotr, fstate_save->vstate_save".
 - Fixup wrong saved registers' length in vector.S.
 - Seperate unrelated patches from this one.

Greentime Hu (1):
  ptrace: Use regset_size() for dynamic regset

Guo Ren (11):
  riscv: Separate patch for cflags and aflags
  riscv: Rename __switch_to_aux -> fpu
  riscv: Extending cpufeature.c to detect V-extension
  riscv: Add new csr defines related to vector extension
  riscv: Add vector feature to compile
  riscv: Add has_vector/riscv_vsize to save vector features.
  riscv: Reset vector register
  riscv: Add vector struct and assembler definitions
  riscv: Add task switch support for vector
  riscv: Add ptrace vector support
  riscv: Add sigcontext save/restore for vector

Vincent Chen (1):
  riscv: signal: Report signal frame size to userspace via auxv

 arch/riscv/Kconfig   |   9 ++
 arch/riscv/Makefile  |  19 ++--
 arch/riscv/include/asm/csr.h |  16 +++-
 arch/riscv/include/asm/elf.h |  17 +++-
 arch/riscv/include/asm/processor.h   |   3 +
 arch/riscv/include/asm/switch_to.h   |  77 ++-
 arch/riscv/include/uapi/asm/auxvec.h |   2 +
 arch/riscv/include/uapi/asm/elf.h|   1 +
 arch/riscv/include/uapi/asm/hwcap.h  |   1 +
 arch/riscv/include/uapi/asm/ptrace.h |  13 +++
 arch/riscv/include/uapi/asm/sigcontext.h |   2 +
 arch/riscv/kernel/Makefile   |   1 +
 arch/riscv/kernel/asm-offsets.c  |   8 ++
 arch/riscv/kernel/cpufeature.c   |  15 ++-
 arch/riscv/kernel/entry.S|   2 +-
 arch/riscv/kernel/head.S |  49 +-
 arch/riscv/kernel/process.c  |  40 
 arch/riscv/kernel/ptrace.c   | 115 +++
 arch/riscv/kernel/setup.c|   5 +
 arch/riscv/kernel/signal.c   | 108 -
 arch/riscv/kernel/vector.S   |  84 +
 include/uapi/linux/elf.h |   1 +
 kernel/ptrace.c  |   2 +-
 23 files changed, 567 insertions(+), 23 deletions(-)
 create mode 100644 arch/riscv/kernel/vector.S

--

[RFC PATCH v5 08/13] riscv: Reset vector register

2020-05-27 Thread Greentime Hu
From: Guo Ren 

Reset vector registers at boot-time and disable vector instructions
execution for kernel mode.

Signed-off-by: Guo Ren 
---
 arch/riscv/kernel/entry.S |  2 +-
 arch/riscv/kernel/head.S  | 49 +--
 2 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
index 56d071b2c0a1..4e32770c19c8 100644
--- a/arch/riscv/kernel/entry.S
+++ b/arch/riscv/kernel/entry.S
@@ -70,7 +70,7 @@ _save_context:
 * Disable the FPU to detect illegal usage of floating point in kernel
 * space.
 */
-   li t0, SR_SUM | SR_FS
+   li t0, SR_SUM | SR_FS | SR_VS
 
REG_L s0, TASK_TI_USER_SP(tp)
csrrc s1, CSR_STATUS, t0
diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
index 98a406474e7d..1290ef680125 100644
--- a/arch/riscv/kernel/head.S
+++ b/arch/riscv/kernel/head.S
@@ -181,10 +181,10 @@ ENTRY(_start_kernel)
 .option pop
 
/*
-* Disable FPU to detect illegal usage of
+* Disable FPU & VECTOR to detect illegal usage of
 * floating point in kernel space
 */
-   li t0, SR_FS
+   li t0, SR_FS | SR_VS
csrc CSR_STATUS, t0
 
 #ifdef CONFIG_SMP
@@ -341,6 +341,51 @@ ENTRY(reset_regs)
csrwfcsr, 0
/* note that the caller must clear SR_FS */
 #endif /* CONFIG_FPU */
+
+#ifdef CONFIG_VECTOR
+   csrrt0, CSR_MISA
+   li  t1, (COMPAT_HWCAP_ISA_V >> 16)
+   sllit1, t1, 16
+   and t0, t0, t1
+   beqzt0, .Lreset_regs_done
+
+   li  t1, SR_VS
+   csrsCSR_STATUS, t1
+   vmv.v.i v0, 0
+   vmv.v.i v1, 0
+   vmv.v.i v2, 0
+   vmv.v.i v3, 0
+   vmv.v.i v4, 0
+   vmv.v.i v5, 0
+   vmv.v.i v6, 0
+   vmv.v.i v7, 0
+   vmv.v.i v8, 0
+   vmv.v.i v9, 0
+   vmv.v.i v10, 0
+   vmv.v.i v11, 0
+   vmv.v.i v12, 0
+   vmv.v.i v13, 0
+   vmv.v.i v14, 0
+   vmv.v.i v15, 0
+   vmv.v.i v16, 0
+   vmv.v.i v17, 0
+   vmv.v.i v18, 0
+   vmv.v.i v19, 0
+   vmv.v.i v20, 0
+   vmv.v.i v21, 0
+   vmv.v.i v22, 0
+   vmv.v.i v23, 0
+   vmv.v.i v24, 0
+   vmv.v.i v25, 0
+   vmv.v.i v26, 0
+   vmv.v.i v27, 0
+   vmv.v.i v28, 0
+   vmv.v.i v29, 0
+   vmv.v.i v30, 0
+   vmv.v.i v31, 0
+   /* note that the caller must clear SR_VS */
+#endif /* CONFIG_VECTOR */
+
 .Lreset_regs_done:
ret
 END(reset_regs)
-- 
2.26.2



[RFC PATCH v5 12/13] riscv: Add sigcontext save/restore for vector

2020-05-27 Thread Greentime Hu
From: Guo Ren 

This patch adds sigcontext save/restore for vector. The vector registers
will be saved in datap pointer. The datap pointer will be allocaed
dynamically when the task needs in kernel space. The datap pointer will
be set right after the __riscv_v_state data structure to save all the
vector registers in the signal handler stack.

[greentime...@sifive.com: add support for dynamic vlen]
Signed-off-by: Greentime Hu 
Signed-off-by: Guo Ren 
---
 arch/riscv/include/uapi/asm/sigcontext.h |  2 +
 arch/riscv/kernel/signal.c   | 92 +++-
 2 files changed, 91 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/include/uapi/asm/sigcontext.h 
b/arch/riscv/include/uapi/asm/sigcontext.h
index 84f2dfcfdbce..4217f3f1c8ba 100644
--- a/arch/riscv/include/uapi/asm/sigcontext.h
+++ b/arch/riscv/include/uapi/asm/sigcontext.h
@@ -8,6 +8,7 @@
 
 #include 
 
+#define RVV_MAGIC  0x53465457
 /*
  * Signal context structure
  *
@@ -17,6 +18,7 @@
 struct sigcontext {
struct user_regs_struct sc_regs;
union __riscv_fp_state sc_fpregs;
+   struct __riscv_v_state sc_vregs;
 };
 
 #endif /* _UAPI_ASM_RISCV_SIGCONTEXT_H */
diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c
index 17ba190e84a5..9ada6f74bb95 100644
--- a/arch/riscv/kernel/signal.c
+++ b/arch/riscv/kernel/signal.c
@@ -83,6 +83,80 @@ static long save_fp_state(struct pt_regs *regs,
 #define restore_fp_state(task, regs) (0)
 #endif
 
+#ifdef CONFIG_VECTOR
+static long restore_v_state(struct pt_regs *regs, struct sigcontext *sc)
+{
+   long err;
+   struct __riscv_v_state __user *state = &sc->sc_vregs;
+   void *datap;
+   __u32 magic;
+
+   /* Get magic number and check it. */
+   err = __get_user(magic, &state->magic);
+   if (unlikely(err))
+   return err;
+
+   if (magic != RVV_MAGIC)
+   return -EINVAL;
+
+   /* Copy everything of __riscv_v_state except datap. */
+   err = __copy_from_user(¤t->thread.vstate, state,
+  RISCV_V_STATE_DATAP);
+   if (unlikely(err))
+   return err;
+
+   /* Copy the pointer datap itself. */
+   err = __get_user(datap, &state->datap);
+   if (unlikely(err))
+   return err;
+
+
+   /* Copy the whole vector content from user space datap. */
+   err = __copy_from_user(current->thread.vstate.datap, datap,
+  current->thread.vstate.size);
+   if (unlikely(err))
+   return err;
+
+   vstate_restore(current, regs);
+
+   return err;
+}
+
+static long save_v_state(struct pt_regs *regs, struct sigcontext *sc)
+{
+   long err;
+   struct __riscv_v_state __user *state = &sc->sc_vregs;
+   /* Set the datap right after the sigcntext structure. */
+   void *datap = sc + 1;
+
+   vstate_save(current, regs);
+   /* Copy everything of vstate but datap. */
+   err = __copy_to_user(state, ¤t->thread.vstate,
+RISCV_V_STATE_DATAP);
+   if (unlikely(err))
+   return err;
+
+   /* Copy the magic number. */
+   err = __put_user(RVV_MAGIC, &state->magic);
+   if (unlikely(err))
+   return err;
+
+   /* Copy the pointer datap itself. */
+   err = __put_user(datap, &state->datap);
+   if (unlikely(err))
+   return err;
+
+   /* Copy the whole vector content to user space datap. */
+   err = __copy_to_user(datap, current->thread.vstate.datap,
+current->thread.vstate.size);
+
+   return err;
+}
+#else
+#define save_v_state(task, regs) (0)
+#define restore_v_state(task, regs) (0)
+#endif
+
 static long restore_sigcontext(struct pt_regs *regs,
struct sigcontext __user *sc)
 {
@@ -92,6 +166,9 @@ static long restore_sigcontext(struct pt_regs *regs,
/* Restore the floating-point state. */
if (has_fpu)
err |= restore_fp_state(regs, &sc->sc_fpregs);
+   /* Restore the vector state. */
+   if (has_vector)
+   err |= restore_v_state(regs, sc);
return err;
 }
 
@@ -101,13 +178,16 @@ SYSCALL_DEFINE0(rt_sigreturn)
struct rt_sigframe __user *frame;
struct task_struct *task;
sigset_t set;
+   size_t frame_size = sizeof(*frame);
 
/* Always make any pending restarted system calls return -EINTR */
current->restart_block.fn = do_no_restart_syscall;
 
frame = (struct rt_sigframe __user *)regs->sp;
 
-   if (!access_ok(frame, sizeof(*frame)))
+   if (has_vector)
+   frame_size += current->thread.vstate.size;
+   if (!access_ok(frame, frame_size))
goto badframe;
 
if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
@@ -145,6 +225,9 @@ static long setup_sigcontext(struct rt_sigframe __user 
*frame,
/* Save the floating-point state. */
if (has_fpu)
err |= s

[RFC PATCH v5 05/13] riscv: Add new csr defines related to vector extension

2020-05-27 Thread Greentime Hu
From: Guo Ren 

Follow the riscv vector spec to add new csr number.

[greentime...@sifive.com: update the defined value based on new spec and
remove unused ones]
Signed-off-by: Greentime Hu 
Signed-off-by: Guo Ren 
---
 arch/riscv/include/asm/csr.h | 16 ++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h
index 8e18d2c64399..cc13626c4bbe 100644
--- a/arch/riscv/include/asm/csr.h
+++ b/arch/riscv/include/asm/csr.h
@@ -24,6 +24,12 @@
 #define SR_FS_CLEAN_AC(0x4000, UL)
 #define SR_FS_DIRTY_AC(0x6000, UL)
 
+#define SR_VS   _AC(0x0600, UL) /* Vector Status */
+#define SR_VS_OFF   _AC(0x, UL)
+#define SR_VS_INITIAL   _AC(0x0200, UL)
+#define SR_VS_CLEAN _AC(0x0400, UL)
+#define SR_VS_DIRTY _AC(0x0600, UL)
+
 #define SR_XS  _AC(0x00018000, UL) /* Extension Status */
 #define SR_XS_OFF  _AC(0x, UL)
 #define SR_XS_INITIAL  _AC(0x8000, UL)
@@ -31,9 +37,9 @@
 #define SR_XS_DIRTY_AC(0x00018000, UL)
 
 #ifndef CONFIG_64BIT
-#define SR_SD  _AC(0x8000, UL) /* FS/XS dirty */
+#define SR_SD  _AC(0x8000, UL) /* FS/VS/XS dirty */
 #else
-#define SR_SD  _AC(0x8000, UL) /* FS/XS dirty */
+#define SR_SD  _AC(0x8000, UL) /* FS/VS/XS dirty */
 #endif
 
 /* SATP flags */
@@ -114,6 +120,12 @@
 #define CSR_PMPADDR0   0x3b0
 #define CSR_MHARTID0xf14
 
+#define CSR_VSTART 0x8
+#define CSR_VCSR   0xf
+#define CSR_VL 0xc20
+#define CSR_VTYPE  0xc21
+#define CSR_VLENB  0xc22
+
 #ifdef CONFIG_RISCV_M_MODE
 # define CSR_STATUSCSR_MSTATUS
 # define CSR_IECSR_MIE
-- 
2.26.2



[RFC PATCH v5 02/13] riscv: Separate patch for cflags and aflags

2020-05-27 Thread Greentime Hu
From: Guo Ren 

From: Guo Ren 

Use "subst fd" in Makefile is a hack way and it's not convenient
to add new ISA feature. Just separate them into riscv-march-cflags
and riscv-march-aflags.

Signed-off-by: Guo Ren 
---
 arch/riscv/Makefile | 18 --
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index fb6e37db836d..957d064bead0 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -37,12 +37,18 @@ else
 endif
 
 # ISA string setting
-riscv-march-$(CONFIG_ARCH_RV32I)   := rv32ima
-riscv-march-$(CONFIG_ARCH_RV64I)   := rv64ima
-riscv-march-$(CONFIG_FPU)  := $(riscv-march-y)fd
-riscv-march-$(CONFIG_RISCV_ISA_C)  := $(riscv-march-y)c
-KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
-KBUILD_AFLAGS += -march=$(riscv-march-y)
+riscv-march-cflags-$(CONFIG_ARCH_RV32I):= rv32ima
+riscv-march-cflags-$(CONFIG_ARCH_RV64I):= rv64ima
+riscv-march-$(CONFIG_FPU)  := $(riscv-march-y)fd
+riscv-march-cflags-$(CONFIG_RISCV_ISA_C)   := $(riscv-march-cflags-y)c
+
+riscv-march-aflags-$(CONFIG_ARCH_RV32I):= rv32ima
+riscv-march-aflags-$(CONFIG_ARCH_RV64I):= rv64ima
+riscv-march-aflags-$(CONFIG_FPU)   := $(riscv-march-aflags-y)fd
+riscv-march-aflags-$(CONFIG_RISCV_ISA_C)   := $(riscv-march-aflags-y)c
+
+KBUILD_CFLAGS += -march=$(riscv-march-cflags-y)
+KBUILD_AFLAGS += -march=$(riscv-march-aflags-y)
 
 KBUILD_CFLAGS += -mno-save-restore
 KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
-- 
2.26.2



[RFC PATCH v5 03/13] riscv: Rename __switch_to_aux -> fpu

2020-05-27 Thread Greentime Hu
From: Guo Ren 

From: Guo Ren 

The name of __switch_to_aux is not clear and rename it with the
determine function: __switch_to_fpu. Next we could add other regs'
switch.

Signed-off-by: Guo Ren 
Reviewed-by: Anup Patel 
---
 arch/riscv/include/asm/switch_to.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/include/asm/switch_to.h 
b/arch/riscv/include/asm/switch_to.h
index 407bcc96a710..b9234e7178d0 100644
--- a/arch/riscv/include/asm/switch_to.h
+++ b/arch/riscv/include/asm/switch_to.h
@@ -44,7 +44,7 @@ static inline void fstate_restore(struct task_struct *task,
}
 }
 
-static inline void __switch_to_aux(struct task_struct *prev,
+static inline void __switch_to_fpu(struct task_struct *prev,
   struct task_struct *next)
 {
struct pt_regs *regs;
@@ -60,7 +60,7 @@ extern bool has_fpu;
 #define has_fpu false
 #define fstate_save(task, regs) do { } while (0)
 #define fstate_restore(task, regs) do { } while (0)
-#define __switch_to_aux(__prev, __next) do { } while (0)
+#define __switch_to_fpu(__prev, __next) do { } while (0)
 #endif
 
 extern struct task_struct *__switch_to(struct task_struct *,
@@ -71,7 +71,7 @@ do {  \
struct task_struct *__prev = (prev);\
struct task_struct *__next = (next);\
if (has_fpu)\
-   __switch_to_aux(__prev, __next);\
+   __switch_to_fpu(__prev, __next);\
((last) = __switch_to(__prev, __next)); \
 } while (0)
 
-- 
2.26.2



[RFC PATCH v5 01/13] ptrace: Use regset_size() for dynamic regset

2020-05-27 Thread Greentime Hu
This patch uses regset_size() instead of using regset->n and regset->size
directly. In this case, it will call the get_size() ported by arch
dynamically to support dynamic regset size case.

Signed-off-by: Greentime Hu 
---
 kernel/ptrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index 43d6179508d6..946b2c4ec4fa 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -888,7 +888,7 @@ static int ptrace_regset(struct task_struct *task, int req, 
unsigned int type,
 
regset_no = regset - view->regsets;
kiov->iov_len = min(kiov->iov_len,
-   (__kernel_size_t) (regset->n * regset->size));
+   (__kernel_size_t) regset_size(task, regset));
 
if (req == PTRACE_GETREGSET)
return copy_regset_to_user(task, view, regset_no, 0,
-- 
2.26.2



[PATCH v2] iio: amplifiers: ad8366: Add the missed check for devm_gpiod_get()

2020-05-27 Thread Chuhong Yuan
ad8366_probe() forgets to check the return value of devm_gpiod_get().
Add the missed check to fix it.

Fixes: cee211f4e5a0 ("iio: amplifiers: ad8366: Add support for the ADA4961 DGA")
Signed-off-by: Chuhong Yuan 
---
Changes in v2:
  - Add fixes tag.

 drivers/iio/amplifiers/ad8366.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c
index 62167b87caea..b996823c8d51 100644
--- a/drivers/iio/amplifiers/ad8366.c
+++ b/drivers/iio/amplifiers/ad8366.c
@@ -264,6 +264,10 @@ static int ad8366_probe(struct spi_device *spi)
case ID_HMC1119:
st->reset_gpio = devm_gpiod_get(&spi->dev, "reset",
GPIOD_OUT_HIGH);
+   if (IS_ERR(st->reset_gpio)) {
+   ret = PTR_ERR(st->reset_gpio);
+   goto error_disable_reg;
+   }
indio_dev->channels = ada4961_channels;
indio_dev->num_channels = ARRAY_SIZE(ada4961_channels);
break;
-- 
2.26.2



[PATCH net-next v3 1/3] net: dsa: felix: move USXGMII defines to common place

2020-05-27 Thread Michael Walle
The ENETC has the same PCS PHY and thus needs the same definitions. Move
them into the common enetc_mdio.h header which has already the macros
for the SGMII PCS.

Signed-off-by: Michael Walle 
---
 drivers/net/dsa/ocelot/felix_vsc9959.c | 21 -
 include/linux/fsl/enetc_mdio.h | 19 +++
 2 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/drivers/net/dsa/ocelot/felix_vsc9959.c 
b/drivers/net/dsa/ocelot/felix_vsc9959.c
index 1dd9e348152d..986d4d26aa3c 100644
--- a/drivers/net/dsa/ocelot/felix_vsc9959.c
+++ b/drivers/net/dsa/ocelot/felix_vsc9959.c
@@ -16,29 +16,8 @@
 #define VSC9959_VCAP_IS2_CNT   1024
 #define VSC9959_VCAP_IS2_ENTRY_WIDTH   376
 #define VSC9959_VCAP_PORT_CNT  6
-
-/* TODO: should find a better place for these */
-#define USXGMII_BMCR_RESET BIT(15)
-#define USXGMII_BMCR_AN_EN BIT(12)
-#define USXGMII_BMCR_RST_ANBIT(9)
-#define USXGMII_BMSR_LNKS(status)  (((status) & GENMASK(2, 2)) >> 2)
-#define USXGMII_BMSR_AN_CMPL(status)   (((status) & GENMASK(5, 5)) >> 5)
-#define USXGMII_ADVERTISE_LNKS(x)  (((x) << 15) & BIT(15))
-#define USXGMII_ADVERTISE_FDX  BIT(12)
-#define USXGMII_ADVERTISE_SPEED(x) (((x) << 9) & GENMASK(11, 9))
-#define USXGMII_LPA_LNKS(lpa)  ((lpa) >> 15)
-#define USXGMII_LPA_DUPLEX(lpa)(((lpa) & GENMASK(12, 12)) >> 
12)
-#define USXGMII_LPA_SPEED(lpa) (((lpa) & GENMASK(11, 9)) >> 9)
-
 #define VSC9959_TAS_GCL_ENTRY_MAX  63
 
-enum usxgmii_speed {
-   USXGMII_SPEED_10= 0,
-   USXGMII_SPEED_100   = 1,
-   USXGMII_SPEED_1000  = 2,
-   USXGMII_SPEED_2500  = 4,
-};
-
 static const u32 vsc9959_ana_regmap[] = {
REG(ANA_ADVLEARN,   0x0089a0),
REG(ANA_VLANMASK,   0x0089a4),
diff --git a/include/linux/fsl/enetc_mdio.h b/include/linux/fsl/enetc_mdio.h
index 4875dd38af7e..0129366fa47a 100644
--- a/include/linux/fsl/enetc_mdio.h
+++ b/include/linux/fsl/enetc_mdio.h
@@ -27,6 +27,25 @@ enum enetc_pcs_speed {
ENETC_PCS_SPEED_2500= 2,
 };
 
+#define USXGMII_BMCR_RESET BIT(15)
+#define USXGMII_BMCR_AN_EN BIT(12)
+#define USXGMII_BMCR_RST_ANBIT(9)
+#define USXGMII_BMSR_LNKS(status)  (((status) & GENMASK(2, 2)) >> 2)
+#define USXGMII_BMSR_AN_CMPL(status)   (((status) & GENMASK(5, 5)) >> 5)
+#define USXGMII_ADVERTISE_LNKS(x)  (((x) << 15) & BIT(15))
+#define USXGMII_ADVERTISE_FDX  BIT(12)
+#define USXGMII_ADVERTISE_SPEED(x) (((x) << 9) & GENMASK(11, 9))
+#define USXGMII_LPA_LNKS(lpa)  ((lpa) >> 15)
+#define USXGMII_LPA_DUPLEX(lpa)(((lpa) & GENMASK(12, 12)) >> 
12)
+#define USXGMII_LPA_SPEED(lpa) (((lpa) & GENMASK(11, 9)) >> 9)
+
+enum usxgmii_speed {
+   USXGMII_SPEED_10= 0,
+   USXGMII_SPEED_100   = 1,
+   USXGMII_SPEED_1000  = 2,
+   USXGMII_SPEED_2500  = 4,
+};
+
 struct enetc_hw;
 
 struct enetc_mdio_priv {
-- 
2.20.1



[PATCH net-next v3 0/3] net: enetc: remove bootloader dependency

2020-05-27 Thread Michael Walle
These patches were picked from the following series:
https://lore.kernel.org/netdev/1567779344-30965-1-git-send-email-claudiu.man...@nxp.com/
They have never been resent. I've picked them up, addressed Andrews
comments, fixed some more bugs and asked Claudiu if I can keep their SOB
tags; he agreed. I've tested this on our board which happens to have a
bootloader which doesn't do the enetc setup in all cases. Though, only
SGMII mode was tested.

changes since v2:
 - removed SOBs from "net: enetc: Initialize SerDes for SGMII and USXGMII
   protocols" because almost everything has changed.
 - get a phy_device for the internal PCS PHY so we can use the phy_
   functions instead of raw mdiobus writes
 - reuse macros already defined in fsl_mdio.h, move missing bits from
   felix to fsl_mdio.h, because they share the same PCS PHY building
   block
 - added 2500BaseX mode (based on felix init routine)
 - changed xgmii mode to usxgmii mode, because it is actually USXGMII and
   felix does the same.
 - fixed devad, which is 0x1f (MMD_VEND2)

changes since v1:
 - mdiobus id is '"imdio-%s", dev_name(dev)' because the plain dev_name()
   is used by the emdio.
 - use mdiobus_write() instead of imdio->write(imdio, ..), since this is
   already a full featured mdiobus
 - set phy_mask to ~0 to avoid scanning the bus
 - use phy_interface_mode_is_rgmii(phy_mode) to also include the RGMII
   modes with pad delays.
 - move enetc_imdio_init() to enetc_pf.c, there shouldn't be any other
   users, should it?
 - renamed serdes to SerDes
 - printing the error code of mdiobus_register() in the error path
 - call mdiobus_unregister() on _remove()
 - call devm_mdiobus_free() if mdiobus_register() fails, since an
   error is not fatal

Alex Marginean (1):
  net: enetc: Use DT protocol information to set up the ports

Michael Walle (2):
  net: dsa: felix: move USXGMII defines to common place
  net: enetc: Initialize SerDes for SGMII and USXGMII protocols

 drivers/net/dsa/ocelot/felix_vsc9959.c|  21 --
 .../net/ethernet/freescale/enetc/enetc_hw.h   |   3 +
 .../net/ethernet/freescale/enetc/enetc_pf.c   | 191 +++---
 .../net/ethernet/freescale/enetc/enetc_pf.h   |   5 +
 include/linux/fsl/enetc_mdio.h|  19 ++
 5 files changed, 194 insertions(+), 45 deletions(-)

-- 
2.20.1



[PATCH net-next v3 2/3] net: enetc: Initialize SerDes for SGMII and USXGMII protocols

2020-05-27 Thread Michael Walle
ENETC has ethernet MACs capable of SGMII, 2500BaseX and USXGMII. But in
order to use these protocols some SerDes configurations need to be
performed. The SerDes is configurable via an internal PCS PHY which is
connected to an internal MDIO bus at address 0.

This patch basically removes the dependency on bootloader regarding
SerDes initialization.

Signed-off-by: Michael Walle 
---
 .../net/ethernet/freescale/enetc/enetc_hw.h   |   3 +
 .../net/ethernet/freescale/enetc/enetc_pf.c   | 135 ++
 .../net/ethernet/freescale/enetc/enetc_pf.h   |   2 +
 3 files changed, 140 insertions(+)

diff --git a/drivers/net/ethernet/freescale/enetc/enetc_hw.h 
b/drivers/net/ethernet/freescale/enetc/enetc_hw.h
index 6314051bc6c1..e80c2c36dbe9 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_hw.h
+++ b/drivers/net/ethernet/freescale/enetc/enetc_hw.h
@@ -224,6 +224,9 @@ enum enetc_bdr_type {TX, RX};
 #define ENETC_PM0_MAXFRM   0x8014
 #define ENETC_SET_TX_MTU(val)  ((val) << 16)
 #define ENETC_SET_MAXFRM(val)  ((val) & 0x)
+
+#define ENETC_PM_IMDIO_BASE0x8030
+
 #define ENETC_PM0_IF_MODE  0x8300
 #define ENETC_PMO_IFM_RG   BIT(2)
 #define ENETC_PM0_IFM_RLP  (BIT(5) | BIT(11))
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c 
b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
index 824d211ec00f..79499a81c77b 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
@@ -841,6 +841,136 @@ static void enetc_of_put_phy(struct enetc_ndev_priv *priv)
of_node_put(priv->phy_node);
 }
 
+static int enetc_imdio_init(struct enetc_pf *pf, bool is_c45)
+{
+   struct device *dev = &pf->si->pdev->dev;
+   struct enetc_mdio_priv *mdio_priv;
+   struct phy_device *pcs;
+   struct mii_bus *bus;
+   int err;
+
+   bus = devm_mdiobus_alloc_size(dev, sizeof(*mdio_priv));
+   if (!bus)
+   return -ENOMEM;
+
+   bus->name = "Freescale ENETC internal MDIO Bus";
+   bus->read = enetc_mdio_read;
+   bus->write = enetc_mdio_write;
+   bus->parent = dev;
+   bus->phy_mask = ~0;
+   mdio_priv = bus->priv;
+   mdio_priv->hw = &pf->si->hw;
+   mdio_priv->mdio_base = ENETC_PM_IMDIO_BASE;
+   snprintf(bus->id, MII_BUS_ID_SIZE, "%s-imdio", dev_name(dev));
+
+   err = mdiobus_register(bus);
+   if (err) {
+   dev_err(dev, "cannot register internal MDIO bus (%d)\n", err);
+   goto free_mdio_bus;
+   }
+
+   pcs = get_phy_device(bus, 0, is_c45);
+   if (IS_ERR(pcs)) {
+   err = PTR_ERR(pcs);
+   dev_err(dev, "cannot get internal PCS PHY (%d)\n", err);
+   goto unregister_mdiobus;
+   }
+
+   pf->imdio = bus;
+   pf->pcs = pcs;
+
+   return 0;
+
+unregister_mdiobus:
+   mdiobus_unregister(bus);
+free_mdio_bus:
+   devm_mdiobus_free(dev, bus);
+   return err;
+}
+
+static void enetc_imdio_remove(struct enetc_pf *pf)
+{
+   if (pf->pcs)
+   put_device(&pf->pcs->mdio.dev);
+   if (pf->imdio)
+   mdiobus_unregister(pf->imdio);
+}
+
+static void enetc_configure_sgmii(struct phy_device *pcs)
+{
+   /* SGMII spec requires tx_config_Reg[15:0] to be exactly 0x4001
+* for the MAC PCS in order to acknowledge the AN.
+*/
+   phy_write(pcs, MII_ADVERTISE, ADVERTISE_SGMII | ADVERTISE_LPACK);
+
+   phy_write(pcs, ENETC_PCS_IF_MODE,
+ ENETC_PCS_IF_MODE_SGMII_EN |
+ ENETC_PCS_IF_MODE_USE_SGMII_AN);
+
+   /* Adjust link timer for SGMII */
+   phy_write(pcs, ENETC_PCS_LINK_TIMER1, ENETC_PCS_LINK_TIMER1_VAL);
+   phy_write(pcs, ENETC_PCS_LINK_TIMER2, ENETC_PCS_LINK_TIMER2_VAL);
+
+   phy_write(pcs, MII_BMCR, BMCR_ANRESTART | BMCR_ANENABLE);
+}
+
+static void enetc_configure_2500basex(struct phy_device *pcs)
+{
+   phy_write(pcs, ENETC_PCS_IF_MODE,
+ ENETC_PCS_IF_MODE_SGMII_EN |
+ ENETC_PCS_IF_MODE_SGMII_SPEED(ENETC_PCS_SPEED_2500));
+
+   phy_write(pcs, MII_BMCR, BMCR_SPEED1000 | BMCR_FULLDPLX | BMCR_RESET);
+}
+
+static void enetc_configure_usxgmii(struct phy_device *pcs)
+{
+   /* Configure device ability for the USXGMII Replicator */
+   phy_write_mmd(pcs, MDIO_MMD_VEND2, MII_ADVERTISE,
+ ADVERTISE_SGMII |
+ ADVERTISE_LPACK |
+ USXGMII_ADVERTISE_FDX);
+
+   /* Restart PCS AN */
+   phy_write_mmd(pcs, MDIO_MMD_VEND2, MII_BMCR,
+ USXGMII_BMCR_RESET |
+ USXGMII_BMCR_AN_EN |
+ USXGMII_BMCR_RST_AN);
+}
+
+static int enetc_configure_serdes(struct enetc_ndev_priv *priv)
+{
+   bool is_c45 = priv->if_mode == PHY_INTERFACE_MODE_USXGMII;
+   struct enetc_pf *pf = enetc_si_priv(priv->si);
+   int err;
+
+   if (priv->if_mode != PHY_INTERFACE_MODE_SGMII &&
+   priv->if_mode != PHY_IN

[PATCH net-next v3 3/3] net: enetc: Use DT protocol information to set up the ports

2020-05-27 Thread Michael Walle
From: Alex Marginean 

Use DT information rather than in-band information from bootloader to
set up MAC for XGMII. For RGMII use the DT indication in addition to
RGMII defaults in hardware.
However, this implies that PHY connection information needs to be
extracted before netdevice creation, when the ENETC Port MAC is
being configured.

Signed-off-by: Alex Marginean 
Signed-off-by: Claudiu Manoil 
Signed-off-by: Michael Walle 
---
 .../net/ethernet/freescale/enetc/enetc_pf.c   | 57 ++-
 .../net/ethernet/freescale/enetc/enetc_pf.h   |  3 +
 2 files changed, 34 insertions(+), 26 deletions(-)

diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c 
b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
index 79499a81c77b..414a9b1b2813 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
@@ -481,7 +481,8 @@ static void enetc_port_si_configure(struct enetc_si *si)
enetc_port_wr(hw, ENETC_PSIVLANFMR, ENETC_PSIVLANFMR_VS);
 }
 
-static void enetc_configure_port_mac(struct enetc_hw *hw)
+static void enetc_configure_port_mac(struct enetc_hw *hw,
+phy_interface_t phy_mode)
 {
enetc_port_wr(hw, ENETC_PM0_MAXFRM,
  ENETC_SET_MAXFRM(ENETC_RX_MAXFRM_SIZE));
@@ -497,9 +498,11 @@ static void enetc_configure_port_mac(struct enetc_hw *hw)
  ENETC_PM0_CMD_TXP | ENETC_PM0_PROMISC |
  ENETC_PM0_TX_EN | ENETC_PM0_RX_EN);
/* set auto-speed for RGMII */
-   if (enetc_port_rd(hw, ENETC_PM0_IF_MODE) & ENETC_PMO_IFM_RG)
+   if (enetc_port_rd(hw, ENETC_PM0_IF_MODE) & ENETC_PMO_IFM_RG ||
+   phy_interface_mode_is_rgmii(phy_mode))
enetc_port_wr(hw, ENETC_PM0_IF_MODE, ENETC_PM0_IFM_RGAUTO);
-   if (enetc_global_rd(hw, ENETC_G_EPFBLPR(1)) == ENETC_G_EPFBLPR1_XGMII)
+
+   if (phy_mode == PHY_INTERFACE_MODE_USXGMII)
enetc_port_wr(hw, ENETC_PM0_IF_MODE, ENETC_PM0_IFM_XGMII);
 }
 
@@ -523,7 +526,7 @@ static void enetc_configure_port(struct enetc_pf *pf)
 
enetc_configure_port_pmac(hw);
 
-   enetc_configure_port_mac(hw);
+   enetc_configure_port_mac(hw, pf->if_mode);
 
enetc_port_si_configure(pf->si);
 
@@ -783,27 +786,27 @@ static void enetc_mdio_remove(struct enetc_pf *pf)
mdiobus_unregister(pf->mdio);
 }
 
-static int enetc_of_get_phy(struct enetc_ndev_priv *priv)
+static int enetc_of_get_phy(struct enetc_pf *pf)
 {
-   struct enetc_pf *pf = enetc_si_priv(priv->si);
-   struct device_node *np = priv->dev->of_node;
+   struct device *dev = &pf->si->pdev->dev;
+   struct device_node *np = dev->of_node;
struct device_node *mdio_np;
int err;
 
-   priv->phy_node = of_parse_phandle(np, "phy-handle", 0);
-   if (!priv->phy_node) {
+   pf->phy_node = of_parse_phandle(np, "phy-handle", 0);
+   if (!pf->phy_node) {
if (!of_phy_is_fixed_link(np)) {
-   dev_err(priv->dev, "PHY not specified\n");
+   dev_err(dev, "PHY not specified\n");
return -ENODEV;
}
 
err = of_phy_register_fixed_link(np);
if (err < 0) {
-   dev_err(priv->dev, "fixed link registration failed\n");
+   dev_err(dev, "fixed link registration failed\n");
return err;
}
 
-   priv->phy_node = of_node_get(np);
+   pf->phy_node = of_node_get(np);
}
 
mdio_np = of_get_child_by_name(np, "mdio");
@@ -811,15 +814,15 @@ static int enetc_of_get_phy(struct enetc_ndev_priv *priv)
of_node_put(mdio_np);
err = enetc_mdio_probe(pf);
if (err) {
-   of_node_put(priv->phy_node);
+   of_node_put(pf->phy_node);
return err;
}
}
 
-   err = of_get_phy_mode(np, &priv->if_mode);
+   err = of_get_phy_mode(np, &pf->if_mode);
if (err) {
-   dev_err(priv->dev, "missing phy type\n");
-   of_node_put(priv->phy_node);
+   dev_err(dev, "missing phy type\n");
+   of_node_put(pf->phy_node);
if (of_phy_is_fixed_link(np))
of_phy_deregister_fixed_link(np);
else
@@ -831,14 +834,14 @@ static int enetc_of_get_phy(struct enetc_ndev_priv *priv)
return 0;
 }
 
-static void enetc_of_put_phy(struct enetc_ndev_priv *priv)
+static void enetc_of_put_phy(struct enetc_pf *pf)
 {
-   struct device_node *np = priv->dev->of_node;
+   struct device_node *np = pf->si->pdev->dev.of_node;
 
if (np && of_phy_is_fixed_link(np))
of_phy_deregister_fixed_link(np);
-   if (priv->phy_node)
-   of_node_put(priv->phy_node);
+   if (pf->phy_node)
+  

Re: [RFC PATCH] samples:bpf: introduce task detector

2020-05-27 Thread Andrii Nakryiko
On Wed, May 27, 2020 at 7:53 PM 王贇  wrote:
>
> This is a tool to trace the related schedule events of a
> specified task, eg the migration, sched in/out, wakeup and
> sleep/block.
>
> The event was translated into sentence to be more readable,
> by execute command 'task_detector -p 49870' we continually
> tracing the schedule events related to 'top' like:
>
> 
> 923455517688  CPU=23  PID=49870  COMM=top  ENQUEUE
> 923455519633  CPU=23  PID=0  COMM=IDLE PREEMPTED
> 1945ns
> 923455519868  CPU=23  PID=49870  COMM=top  EXECUTE AFTER WAITED 
> 2180ns
> 923468279019  CPU=23  PID=49870  COMM=top  WAIT AFTER EXECUTED  
> 12ms
> 923468279220  CPU=23  PID=128COMM=ksoftirqd/23 PREEMPT
> 923468283051  CPU=23  PID=128COMM=ksoftirqd/23 DEQUEUE AFTER PREEMPTED  
> 3831ns
> 923468283216  CPU=23  PID=49870  COMM=top  EXECUTE AFTER WAITED 
> 4197ns
> 923476280180  CPU=23  PID=49870  COMM=top  WAIT AFTER EXECUTED  
> 7996us
> 923476280350  CPU=23  PID=128COMM=ksoftirqd/23 PREEMPT
> 923476322029  CPU=23  PID=128COMM=ksoftirqd/23 DEQUEUE AFTER PREEMPTED  
> 41us
> 923476322150  CPU=23  PID=49870  COMM=top  EXECUTE AFTER WAITED 
> 41us
> 923479726879  CPU=23  PID=49870  COMM=top  DEQUEUE AFTER EXECUTED   
> 3404us
> 
>
> This could be helpful on debugging the competition on CPU
> resource, to find out who has stolen the CPU and how much
> it stolen.
>
> It can also tracing the syscall by append option -s.
>
> Signed-off-by: Michael Wang 
> ---

I haven't looked through implementation thoroughly yet. But I have few
general remarks.

This looks like a useful and generic tool. I think it will get most
attention and be most useful if it will be part of BCC tools. There is
already a set of generic tools that use libbpf and CO-RE, see [0]. It
feels like this belongs there.

Some of the annoying parts (e.g., syscall name translation) is already
generalized as part of syscount tool PR (to be hopefully merged soon),
so you'll be able to save quite a lot of code with this. There is also
a common build infra that takes care of things like vmlinux.h, which
would provide definitions for all those xxx_args structs that you had
to manually define.

With CO-RE, it also will allow to compile this tool once and run it on
many different kernels without recompilation. Please do take a look
and submit a PR there, it will be a good addition to the toolkit (and
will force you write a bit of README explaining use of this tool as
well ;).

As for the code itself, I haven't gone through it much, but please
convert map definition syntax to BTF-defined one. The one you are
using is a legacy one. Thanks!

  [0] https://github.com/iovisor/bcc/tree/master/libbpf-tools

>  samples/bpf/Makefile |   3 +
>  samples/bpf/task_detector.h  | 382 
> +++
>  samples/bpf/task_detector_kern.c | 329 +
>  samples/bpf/task_detector_user.c | 314 
>  4 files changed, 1028 insertions(+)
>  create mode 100644 samples/bpf/task_detector.h
>  create mode 100644 samples/bpf/task_detector_kern.c
>  create mode 100644 samples/bpf/task_detector_user.c
>

[...]


Re: [PATCH] crypto: cavium/nitrox - Fix 'nitrox_get_first_device()' when ndevlist is fully iterated

2020-05-27 Thread Herbert Xu
On Tue, May 19, 2020 at 10:45:03PM +0200, Christophe JAILLET wrote:
> When a list is completely iterated with 'list_for_each_entry(x, ...)', x is
> not NULL at the end.
> 
> Introduce an intermediate variable and test it instead, in order to
> reliably know if something was found or not.
> 
> Fixes: f2663872f073 ("crypto: cavium - Register the CNN55XX supported crypto 
> algorithms.")
> Signed-off-by: Christophe JAILLET 
> ---
>  drivers/crypto/cavium/nitrox/nitrox_main.c | 9 ++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/crypto/cavium/nitrox/nitrox_main.c 
> b/drivers/crypto/cavium/nitrox/nitrox_main.c
> index 788c6607078b..172cafe7c039 100644
> --- a/drivers/crypto/cavium/nitrox/nitrox_main.c
> +++ b/drivers/crypto/cavium/nitrox/nitrox_main.c
> @@ -278,15 +278,18 @@ static void nitrox_remove_from_devlist(struct 
> nitrox_device *ndev)
>  
>  struct nitrox_device *nitrox_get_first_device(void)
>  {
> - struct nitrox_device *ndev = NULL;
> + struct nitrox_device *ndev;
> + bool found = false;
>  
>   mutex_lock(&devlist_lock);
>   list_for_each_entry(ndev, &ndevlist, list) {
> - if (nitrox_ready(ndev))
> + if (nitrox_ready(ndev)) {
> + found = true;
>   break;
> + }
>   }
>   mutex_unlock(&devlist_lock);
> - if (!ndev)

Instead of adding found, you could fix this by changing the test to

if (&ndev->list == &nevlist)

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


Re: [PATCH] efi/x86: Don't blow away existing initrd

2020-05-27 Thread Ard Biesheuvel
(+ Stephen, Boris)

On Thu, 28 May 2020 at 01:26, Arvind Sankar  wrote:
>
> Commit
>   987053a30016 ("efi/x86: Move command-line initrd loading to efi_main")
> moved the command-line initrd loading into efi_main, with a check to
> ensure that it was attempted only if the EFI stub was booted via
> efi_pe_entry rather than the EFI handover entry.
>
> However, in the case where it was booted via handover entry, and thus an
> initrd may have already been loaded by the bootloader, it then wrote 0
> for the initrd address and size, removing any existing initrd.
>
> Fix this by checking if size is positive before setting the fields in
> the bootparams structure.
>
> Fixes: 987053a30016 ("efi/x86: Move command-line initrd loading to efi_main")
> Reported-by: Dan Williams 
> Tested-by: Dan Williams 
> Signed-off-by: Arvind Sankar 

Reviewed-by: Ard Biesheuvel 

Apologies to all for the breakage, and for not catching this in review.

Ingo, Thomas, Boris: please apply this directly to efi/core asap.

Stephen: gives that this breaks the boot for a lot of people, you
might want to pull this into -next directly.

Thanks,
Ard.


> ---
>  drivers/firmware/efi/libstub/x86-stub.c | 10 ++
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/firmware/efi/libstub/x86-stub.c 
> b/drivers/firmware/efi/libstub/x86-stub.c
> index 072b7cf40475..ceb8e16c8b75 100644
> --- a/drivers/firmware/efi/libstub/x86-stub.c
> +++ b/drivers/firmware/efi/libstub/x86-stub.c
> @@ -774,10 +774,12 @@ unsigned long efi_main(efi_handle_t handle,
> efi_err("Failed to load initrd!\n");
> goto fail;
> }
> -   efi_set_u64_split(addr, &hdr->ramdisk_image,
> - &boot_params->ext_ramdisk_image);
> -   efi_set_u64_split(size, &hdr->ramdisk_size,
> - &boot_params->ext_ramdisk_size);
> +   if (size > 0) {
> +   efi_set_u64_split(addr, &hdr->ramdisk_image,
> + &boot_params->ext_ramdisk_image);
> +   efi_set_u64_split(size, &hdr->ramdisk_size,
> + &boot_params->ext_ramdisk_size);
> +   }
> }
>
> /*
> --
> 2.26.2
>


Re: [PATCH RFCv2 3/9] kvm/arm64: Rename kvm_vcpu_get_hsr() to kvm_vcpu_get_esr()

2020-05-27 Thread Gavin Shan

On 5/27/20 5:20 PM, Marc Zyngier wrote:

On 2020-05-27 03:43, Gavin Shan wrote:

Hi Mark,

On 5/26/20 8:42 PM, Mark Rutland wrote:

On Fri, May 08, 2020 at 01:29:13PM +1000, Gavin Shan wrote:

Since kvm/arm32 was removed, this renames kvm_vcpu_get_hsr() to
kvm_vcpu_get_esr() to it a bit more self-explaining because the
functions returns ESR instead of HSR on aarch64. This shouldn't
cause any functional changes.

Signed-off-by: Gavin Shan 


I think that this would be a nice cleanup on its own, and could be taken
independently of the rest of this series if it were rebased and sent as
a single patch.



Yeah, I'll see how PATCH[3,4,5] can be posted independently
as part of the preparatory work, which is suggested by you
in another reply.

By the way, I assume the cleanup patches are good enough to
target 5.8.rc1/rc2 if you agree.


It's fine to base them on -rc1 or -rc2. They will not be merged
before 5.9 though.

Thanks,

     M.


Sure, Thanks, Marc!



Re: [PATCH RFCv2 7/9] kvm/arm64: Support async page fault

2020-05-27 Thread Gavin Shan

Hi Marc,

On 5/27/20 5:37 PM, Marc Zyngier wrote:

On 2020-05-27 05:05, Gavin Shan wrote:


[...]
 

+struct kvm_vcpu_pv_apf_data {
+    __u32    reason;
+    __u8    pad[60];
+    __u32    enabled;
+};


What's all the padding for?



The padding is ensure the @reason and @enabled in different cache
line. @reason is shared by host/guest, while @enabled is almostly
owned by guest.


So you are assuming that a cache line is at most 64 bytes.
It is actualy implementation defined, and you can probe for it
by looking at the CTR_EL0 register. There are implementations
ranging from 32 to 256 bytes in the wild, and let's not mention
broken big-little implementations here.

[...]



Ok, Thanks for your comments and hints.


+bool kvm_arch_can_inject_async_page_not_present(struct kvm_vcpu *vcpu)
+{
+    u64 vbar, pc;
+    u32 val;
+    int ret;
+
+    if (!(vcpu->arch.apf.control_block & KVM_ASYNC_PF_ENABLED))
+    return false;
+
+    if (vcpu->arch.apf.send_user_only && vcpu_mode_priv(vcpu))
+    return false;
+
+    /* Pending page fault, which ins't acknowledged by guest */
+    ret = kvm_async_pf_read_cache(vcpu, &val);
+    if (ret || val)
+    return false;
+
+    /*
+ * Events can't be injected through data abort because it's
+ * going to clobber ELR_EL1, which might not consued (or saved)
+ * by guest yet.
+ */
+    vbar = vcpu_read_sys_reg(vcpu, VBAR_EL1);
+    pc = *vcpu_pc(vcpu);
+    if (pc >= vbar && pc < (vbar + vcpu->arch.apf.no_fault_inst_range))
+    return false;


Ah, so that's when this `no_fault_inst_range` is for.

As-is this is not sufficient, and we'll need t be extremely careful
here.

The vectors themselves typically only have a small amount of stub code,
and the bulk of the non-reentrant exception entry work happens
elsewhere, in a mixture of assembly and C code that isn't even virtually
contiguous with either the vectors or itself.

It's possible in theory that code in modules (or perhaps in eBPF JIT'd
code) that isn't safe to take a fault from, so even having a contiguous
range controlled by the kernel isn't ideal.

How does this work on x86?



Yeah, here we just provide a mechanism to forbid injecting data abort. The
range is fed by guest through HVC call. So I think it's guest related issue.
You had more comments about this in PATCH[9]. I will explain a bit more there.

x86 basically relies on EFLAGS[IF] flag. The async page fault can be injected
if it's on. Otherwise, it's forbidden. It's workable because exception is
special interrupt to x86 if I'm correct.

   return (vmcs_readl(GUEST_RFLAGS) & X86_EFLAGS_IF) &&
  !(vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) &
    (GUEST_INTR_STATE_STI | GUEST_INTR_STATE_MOV_SS));


I really wish this was relying on an architected exception delivery
mechanism that can be blocked by the guest itself (PSTATE.{I,F,A}).
Trying to guess based on the PC won't fly. But these signals are
pretty hard to multiplex with anything else. Like any form of
non-architected exception injection, I don't see a good path forward
unless we start considering something like SDEI.

     M.


As Paolo mentioned in another reply. There are two types of notifications
sent from host to guest: page_not_present and page_ready. The page_not_present
notification should be delivered synchronously while page_ready can be
delivered asynchronously. He also suggested to reserve a ESR (or DFSC) subclass
for page_not_present. For page_ready, it can be delivered by interrupt, like 
PPI.
x86 is changing the code to deliver page_ready by interrupt, which was done by
exception previously.

when we use interrupt, instead of exception for page_ready. We won't need the
game of guessing PC.

I assume you prefer to use SDEI for page_not_present, correct? In that case,
what's the current status of SDEI? I mean it has been fully or partially
supported, or we need develop it from the scratch :)

Thanks,
Gavin



Re: [PATCH v1 1/1] scsi: ufs: Don't update urgent bkops level when toggle auto bkops

2020-05-27 Thread Stanley Chu
On Wed, 2020-05-27 at 19:24 -0700, Can Guo wrote:
> Urgent bkops level is used to compare against actual bkops status read
> from UFS device. Urgent bkops level is set during initialization and might
> be updated in exception event handler during runtime, but it should not be
> updated to the actual bkops status every time when auto bkops is toggled.
> Otherwise, if urgent bkops level is updated to 0, auto bkops shall always
> be kept enabled.
> 
> Fixes: 24366c2afbb0 ("scsi: ufs: Recheck bkops level if bkops is disabled")
> Signed-off-by: Can Guo 
> ---
>  drivers/scsi/ufs/ufshcd.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index 1827b57..178322e 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -5133,7 +5133,6 @@ static int ufshcd_bkops_ctrl(struct ufs_hba *hba,
>   err = ufshcd_enable_auto_bkops(hba);
>   else
>   err = ufshcd_disable_auto_bkops(hba);
> - hba->urgent_bkops_lvl = curr_status;
>  out:
>   return err;
>  }

Reviewed-by: Stanley Chu 



Re: [PATCH] lightnvm: pblk: Fix reference count leak in pblk_sysfs_init.

2020-05-27 Thread Javier González

On 27.05.2020 16:06, wu000...@umn.edu wrote:

From: Qiushi Wu 

kobject_init_and_add() takes reference even when it fails.
Thus, when kobject_init_and_add() returns an error,
kobject_put() must be called to properly clean up the kobject.

Fixes: a4bd217b4326 ("lightnvm: physical block device (pblk) target")
Signed-off-by: Qiushi Wu 
---
drivers/lightnvm/pblk-sysfs.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/lightnvm/pblk-sysfs.c b/drivers/lightnvm/pblk-sysfs.c
index 6387302b03f2..90f1433b19a2 100644
--- a/drivers/lightnvm/pblk-sysfs.c
+++ b/drivers/lightnvm/pblk-sysfs.c
@@ -711,6 +711,7 @@ int pblk_sysfs_init(struct gendisk *tdisk)
"%s", "pblk");
if (ret) {
pblk_err(pblk, "could not register\n");
+   kobject_put(&pblk->kobj);
return ret;
}

--
2.17.1



Looks good to me.

Reviewed-by: Javier González 


[PATCH v5] KVM: PPC: clean up redundant kvm_run parameters in assembly

2020-05-27 Thread Tianjia Zhang
In the current kvm version, 'kvm_run' has been included in the 'kvm_vcpu'
structure. For historical reasons, many kvm-related function parameters
retain the 'kvm_run' and 'kvm_vcpu' parameters at the same time. This
patch does a unified cleanup of these remaining redundant parameters.

Signed-off-by: Tianjia Zhang 
---
 arch/powerpc/include/asm/kvm_ppc.h|  2 +-
 arch/powerpc/kvm/book3s_interrupts.S  | 22 ++
 arch/powerpc/kvm/book3s_pr.c  |  9 -
 arch/powerpc/kvm/booke.c  |  9 -
 arch/powerpc/kvm/booke_interrupts.S   |  9 -
 arch/powerpc/kvm/bookehv_interrupts.S | 10 +-
 6 files changed, 28 insertions(+), 33 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
b/arch/powerpc/include/asm/kvm_ppc.h
index ccf66b3a4c1d..0a056c64c317 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -59,7 +59,7 @@ enum xlate_readwrite {
 };
 
 extern int kvmppc_vcpu_run(struct kvm_vcpu *vcpu);
-extern int __kvmppc_vcpu_run(struct kvm_run *run, struct kvm_vcpu *vcpu);
+extern int __kvmppc_vcpu_run(struct kvm_vcpu *vcpu);
 extern void kvmppc_handler_highmem(void);
 
 extern void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu);
diff --git a/arch/powerpc/kvm/book3s_interrupts.S 
b/arch/powerpc/kvm/book3s_interrupts.S
index f7ad99d972ce..a3674f6b8d3d 100644
--- a/arch/powerpc/kvm/book3s_interrupts.S
+++ b/arch/powerpc/kvm/book3s_interrupts.S
@@ -55,8 +55,7 @@
  /
 
 /* Registers:
- *  r3: kvm_run pointer
- *  r4: vcpu pointer
+ *  r3: vcpu pointer
  */
 _GLOBAL(__kvmppc_vcpu_run)
 
@@ -68,8 +67,8 @@ kvm_start_entry:
/* Save host state to the stack */
PPC_STLU r1, -SWITCH_FRAME_SIZE(r1)
 
-   /* Save r3 (kvm_run) and r4 (vcpu) */
-   SAVE_2GPRS(3, r1)
+   /* Save r3 (vcpu) */
+   SAVE_GPR(3, r1)
 
/* Save non-volatile registers (r14 - r31) */
SAVE_NVGPRS(r1)
@@ -82,14 +81,13 @@ kvm_start_entry:
PPC_STL r0, _LINK(r1)
 
/* Load non-volatile guest state from the vcpu */
-   VCPU_LOAD_NVGPRS(r4)
+   VCPU_LOAD_NVGPRS(r3)
 
 kvm_start_lightweight:
/* Copy registers into shadow vcpu so we can access them in real mode */
-   mr  r3, r4
bl  FUNC(kvmppc_copy_to_svcpu)
nop
-   REST_GPR(4, r1)
+   REST_GPR(3, r1)
 
 #ifdef CONFIG_PPC_BOOK3S_64
/* Get the dcbz32 flag */
@@ -146,7 +144,7 @@ after_sprg3_load:
 *
 */
 
-   PPC_LL  r3, GPR4(r1)/* vcpu pointer */
+   PPC_LL  r3, GPR3(r1)/* vcpu pointer */
 
/*
 * kvmppc_copy_from_svcpu can clobber volatile registers, save
@@ -190,11 +188,11 @@ after_sprg3_load:
PPC_STL r30, VCPU_GPR(R30)(r7)
PPC_STL r31, VCPU_GPR(R31)(r7)
 
-   /* Pass the exit number as 3rd argument to kvmppc_handle_exit */
-   lwz r5, VCPU_TRAP(r7)
+   /* Pass the exit number as 2nd argument to kvmppc_handle_exit */
+   lwz r4, VCPU_TRAP(r7)
 
-   /* Restore r3 (kvm_run) and r4 (vcpu) */
-   REST_2GPRS(3, r1)
+   /* Restore r3 (vcpu) */
+   REST_GPR(3, r1)
bl  FUNC(kvmppc_handle_exit_pr)
 
/* If RESUME_GUEST, get back in the loop */
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index ef54f917bdaf..01c8fe5abe0d 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -1151,9 +1151,9 @@ static int kvmppc_exit_pr_progint(struct kvm_vcpu *vcpu, 
unsigned int exit_nr)
return r;
 }
 
-int kvmppc_handle_exit_pr(struct kvm_run *run, struct kvm_vcpu *vcpu,
- unsigned int exit_nr)
+int kvmppc_handle_exit_pr(struct kvm_vcpu *vcpu, unsigned int exit_nr)
 {
+   struct kvm_run *run = vcpu->run;
int r = RESUME_HOST;
int s;
 
@@ -1826,7 +1826,6 @@ static void kvmppc_core_vcpu_free_pr(struct kvm_vcpu 
*vcpu)
 
 static int kvmppc_vcpu_run_pr(struct kvm_vcpu *vcpu)
 {
-   struct kvm_run *run = vcpu->run;
int ret;
 #ifdef CONFIG_ALTIVEC
unsigned long uninitialized_var(vrsave);
@@ -1834,7 +1833,7 @@ static int kvmppc_vcpu_run_pr(struct kvm_vcpu *vcpu)
 
/* Check if we can run the vcpu at all */
if (!vcpu->arch.sane) {
-   run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
+   vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
ret = -EINVAL;
goto out;
}
@@ -1861,7 +1860,7 @@ static int kvmppc_vcpu_run_pr(struct kvm_vcpu *vcpu)
 
kvmppc_fix_ee_before_entry();
 
-   ret = __kvmppc_vcpu_run(run, vcpu);
+   ret = __kvmppc_vcpu_run(vcpu);
 
kvmppc_clear_debug(vcpu);
 
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index c0d62a917e20..3e1c9f08e302 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -731,12 +731,11 @@ int kvmppc_core_check_requests(struct kvm_

linux-next: manual merge of the usb tree with the devicetree tree

2020-05-27 Thread Stephen Rothwell
Hi all,

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

  Documentation/devicetree/bindings/usb/qcom,dwc3.yaml

between commit:

  3828026c9ec8 ("dt-bindings: usb: qcom,dwc3: Convert USB DWC3 bindings")

from the devicetree tree and commits:

  cd4b54e2ae1f ("dt-bindings: usb: qcom,dwc3: Convert USB DWC3 bindings")

from the usb tree.

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

-- 
Cheers,
Stephen Rothwell


pgpiLM3HMtySp.pgp
Description: OpenPGP digital signature


Re: [PATCH v2] bluetooth: hci_qca: Fix QCA6390 memdump failure

2020-05-27 Thread Zijun Hu



On 5/28/2020 11:42 AM, Abhishek Pandit-Subedi wrote:
> Hi Zijun,
> 
> On Tue, May 26, 2020 at 8:37 PM Zijun Hu  wrote:
>>
>> QCA6390 memdump VSE sometimes come to bluetooth driver
>> with wrong sequence number as illustrated as follows:
>> frame # in DEC: frame data in HEX
>> 1396: ff fd 01 08 74 05 00 37 8f 14
>> 1397: ff fd 01 08 75 05 00 ff bf 38
>> 1414: ff fd 01 08 86 05 00 fb 5e 4b
>> 1399: ff fd 01 08 77 05 00 f3 44 0a
>> 1400: ff fd 01 08 78 05 00 ca f7 41
>> it is mistook for controller missing packets, so results
>> in page fault after overwriting memdump buffer allocated.
>>
>> it is fixed by ignoring QCA6390 sequence number error
>> and checking buffer space before writing.
>>
>> Signed-off-by: Zijun Hu 
>> ---
>>  drivers/bluetooth/hci_qca.c | 45 
>> ++---
>>  1 file changed, 38 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
>> index e4a6823..388fe01b 100644
>> --- a/drivers/bluetooth/hci_qca.c
>> +++ b/drivers/bluetooth/hci_qca.c
>> @@ -114,6 +114,7 @@ struct qca_memdump_data {
>> char *memdump_buf_tail;
>> u32 current_seq_no;
>> u32 received_dump;
>> +   u32 ram_dump_size;
>>  };
>>
>>  struct qca_memdump_event_hdr {
>> @@ -976,6 +977,8 @@ static void qca_controller_memdump(struct work_struct 
>> *work)
>> char nullBuff[QCA_DUMP_PACKET_SIZE] = { 0 };
>> u16 seq_no;
>> u32 dump_size;
>> +   u32 rx_size;
>> +   enum qca_btsoc_type soc_type = qca_soc_type(hu);
>>
>> while ((skb = skb_dequeue(&qca->rx_memdump_q))) {
>>
>> @@ -1029,6 +1032,7 @@ static void qca_controller_memdump(struct work_struct 
>> *work)
>>
>> skb_pull(skb, sizeof(dump_size));
>> memdump_buf = vmalloc(dump_size);
>> +   qca_memdump->ram_dump_size = dump_size;
>> qca_memdump->memdump_buf_head = memdump_buf;
>> qca_memdump->memdump_buf_tail = memdump_buf;
>> }
>> @@ -1052,25 +1056,52 @@ static void qca_controller_memdump(struct 
>> work_struct *work)
>>  * packets in the buffer.
>>  */
>> while ((seq_no > qca_memdump->current_seq_no + 1) &&
>> +   (soc_type != QCA_QCA6390) &&
> 
> This probably shouldn't be SOC specific.
>
make sense. but this logic block should be skipped for QCA6390
the present logic to fix controller missing packets for the other products
is not suitable for QCA6390. for QCA6390, it doesn't miss packet and sequence
number field of the packet maybe have data error, but serdev driver doesn't 
propagate
these error info detected by UART driver to bluetooth driver. so the sequence 
number
extracted from packet received is not reliable.
 
>> seq_no != QCA_LAST_SEQUENCE_NUM) {
>> bt_dev_err(hu->hdev, "QCA controller missed 
>> packet:%d",
>>qca_memdump->current_seq_no);
>> +   rx_size = qca_memdump->received_dump;
>> +   rx_size += QCA_DUMP_PACKET_SIZE;
>> +   if (rx_size > qca_memdump->ram_dump_size) {
>> +   bt_dev_err(hu->hdev,
>> +   "QCA memdump received %d, no 
>> space for missed packet",
>> +   qca_memdump->received_dump);
>> +   break;
>> +   }
>> memcpy(memdump_buf, nullBuff, QCA_DUMP_PACKET_SIZE);
>> memdump_buf = memdump_buf + QCA_DUMP_PACKET_SIZE;
>> qca_memdump->received_dump += QCA_DUMP_PACKET_SIZE;
>> qca_memdump->current_seq_no++;
>> }
> 
> You can replace this loop with a memset(memdump_buf, 0, (seq_no -
> qca_memdump->current_seq_no) * QCA_DUMP_PACKET_SIZE). This simplifies
> the ram_dump_size check as well because it won't zero fill until the
> end anymore (meaning a single bad seq_no doesn't make the rest of the
> dump incorrect).
>
i don't think so
as explained above, the sequence number is not reliable, so we can't memset 
buffer
area calculated from seqence number. i just dump all the packets we received 
without
any handling for QCA6390.
>>
>> -   memcpy(memdump_buf, (unsigned char *) skb->data, skb->len);
>> -   memdump_buf = memdump_buf + skb->len;
>> -   qca_memdump->memdump_buf_tail = memdump_buf;
>> -   qca_memdump->current_seq_no = seq_no + 1;
>> -   qca_memdump->received_dump += skb->len;
>> +   rx_size = qca_memdump->received_dump + skb->len;
>> +   if (rx_size <= qca_memdump->ram_dump_size) {
>> +   if ((seq_no != QCA_LAST_SEQUENCE_NUM) &&
>> +   (seq_no != 
>> qca_me

Re: [PATCH v3 4/4] kdb: Switch kdb_msg_write() to use safer polling I/O

2020-05-27 Thread Sumit Garg
On Wed, 27 May 2020 at 19:01, Daniel Thompson
 wrote:
>
> On Wed, May 27, 2020 at 11:55:59AM +0530, Sumit Garg wrote:
> > In kgdb NMI context, calling console handlers isn't safe due to locks
> > used in those handlers which could lead to a deadlock. Although, using
> > oops_in_progress increases the chance to bypass locks in most console
> > handlers but it might not be sufficient enough in case a console uses
> > more locks (VT/TTY is good example).
> >
> > Currently when a driver provides both polling I/O and a console then kdb
> > will output using the console. We can increase robustness by using the
> > currently active polling I/O driver (which should be lockless) instead
> > of the corresponding console. For several common cases (e.g. an
> > embedded system with a single serial port that is used both for console
> > output and debugger I/O) this will result in no console handler being
> > used.
>
> Not sure I would have predicted all those changes to kgdboc.c based on
> this patch description. I assume this is to help identify which console
> matches our dbg_io_ops but it would be good to spell this out.
>

Okay, will add the corresponding description.

>
> > Suggested-by: Daniel Thompson 
> > Signed-off-by: Sumit Garg 
> > ---
> >  drivers/tty/serial/kgdboc.c | 17 -
> >  include/linux/kgdb.h|  2 ++
> >  kernel/debug/kdb/kdb_io.c   | 46 
> > +++--
> >  3 files changed, 42 insertions(+), 23 deletions(-)
> >
> > diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
> > index c9f94fa..6199fe1 100644
> > --- a/drivers/tty/serial/kgdboc.c
> > +++ b/drivers/tty/serial/kgdboc.c
> > @@ -35,7 +35,6 @@ static struct kparam_string kps = {
> >  };
> >
> >  static int kgdboc_use_kms;  /* 1 if we use kernel mode switching */
> > -static struct tty_driver *kgdb_tty_driver;
> >  static int   kgdb_tty_line;
> >
> >  #ifdef CONFIG_KDB_KEYBOARD
> > @@ -154,7 +153,7 @@ static int configure_kgdboc(void)
> >   }
> >
> >   kgdboc_io_ops.is_console = 0;
> > - kgdb_tty_driver = NULL;
> > + kgdboc_io_ops.tty_drv = NULL;
> >
> >   kgdboc_use_kms = 0;
> >   if (strncmp(cptr, "kms,", 4) == 0) {
> > @@ -178,7 +177,7 @@ static int configure_kgdboc(void)
> >   }
> >   }
> >
> > - kgdb_tty_driver = p;
> > + kgdboc_io_ops.tty_drv = p;
> >   kgdb_tty_line = tty_line;
> >
> >  do_register:
> > @@ -216,18 +215,18 @@ static int __init init_kgdboc(void)
> >
> >  static int kgdboc_get_char(void)
> >  {
> > - if (!kgdb_tty_driver)
> > + if (!kgdboc_io_ops.tty_drv)
> >   return -1;
> > - return kgdb_tty_driver->ops->poll_get_char(kgdb_tty_driver,
> > - kgdb_tty_line);
> > + return 
> > kgdboc_io_ops.tty_drv->ops->poll_get_char(kgdboc_io_ops.tty_drv,
> > +  kgdb_tty_line);
> >  }
> >
> >  static void kgdboc_put_char(u8 chr)
> >  {
> > - if (!kgdb_tty_driver)
> > + if (!kgdboc_io_ops.tty_drv)
> >   return;
> > - kgdb_tty_driver->ops->poll_put_char(kgdb_tty_driver,
> > - kgdb_tty_line, chr);
> > + kgdboc_io_ops.tty_drv->ops->poll_put_char(kgdboc_io_ops.tty_drv,
> > +   kgdb_tty_line, chr);
> >  }
> >
> >  static int param_set_kgdboc_var(const char *kmessage,
> > diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
> > index b072aeb..05d165d 100644
> > --- a/include/linux/kgdb.h
> > +++ b/include/linux/kgdb.h
> > @@ -275,6 +275,7 @@ struct kgdb_arch {
> >   * for the I/O driver.
> >   * @is_console: 1 if the end device is a console 0 if the I/O device is
> >   * not a console
> > + * @tty_drv: Pointer to polling tty driver.
> >   */
> >  struct kgdb_io {
> >   const char  *name;
> > @@ -285,6 +286,7 @@ struct kgdb_io {
> >   void(*pre_exception) (void);
> >   void(*post_exception) (void);
> >   int is_console;
> > + struct tty_driver   *tty_drv;
>
> Should this be a struct tty_driver or a struct console?
>
> In other words if the lifetime the console structure is the same as the
> tty_driver then isn't it better to capture the console instead
> (easier to compare and works with non-tty devices such as the
> USB debug mode).
>

IIUC, you mean to say we can easily replace "is_console" with "struct
console". This sounds feasible and should be a straightforward
comparison in order to prefer "dbg_io_ops" over console handlers. So I
will switch to use "struct console" instead.

>
> >  };
> >
> >  extern const struct kgdb_archarch_kgdb_ops;
> > diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
> > index f848482..c2efa52 100644
> > --- a/kernel/debug/kdb/kdb_io.c
> > +++ b/kernel/debug/kdb/kdb_io.c
> > @@ -24,6 +24,7 @@
> >  #include 
> >  #inc

[PATCH v2 0/4] Spilt PCIe node to comply with hardware design

2020-05-27 Thread chuanjia.liu
There are two independent PCIe controllers in MT2712/MT7622 platform,
and each of them should contain an independent MSI domain.

In current architecture, MSI domain will be inherited from the root
bridge, and all of the devices will share the same MSI domain.
Hence that, the PCIe devices will not work properly if the irq number
which required is more than 32.

Split the PCIe node for MT2712/MT7622 platform to fix MSI issue and
comply with the hardware design.

change note:
v2: change the allocation of mt2712 PCIe MMIO space due to the allcation
size is not right in v1.

chuanjia.liu (4):
  dt-bindings: PCI: Mediatek: Update PCIe binding
  PCI: mediatek: Use regmap to get shared pcie-cfg base
  arm64: dts: mediatek: Split PCIe node for MT2712/MT7622
  ARM: dts: mediatek: Update mt7629 PCIe node

 .../bindings/pci/mediatek-pcie-cfg.yaml   |  38 +
 .../devicetree/bindings/pci/mediatek-pcie.txt | 144 +++---
 arch/arm/boot/dts/mt7629-rfb.dts  |   3 +-
 arch/arm/boot/dts/mt7629.dtsi |  23 +--
 arch/arm64/boot/dts/mediatek/mt2712e.dtsi |  75 +
 .../dts/mediatek/mt7622-bananapi-bpi-r64.dts  |  16 +-
 arch/arm64/boot/dts/mediatek/mt7622-rfb1.dts  |   6 +-
 arch/arm64/boot/dts/mediatek/mt7622.dtsi  |  68 ++---
 drivers/pci/controller/pcie-mediatek.c|  25 ++-
 9 files changed, 258 insertions(+), 140 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/pci/mediatek-pcie-cfg.yaml

--
2.18.0



Re: [PATCH v30 07/20] x86/sgx: Enumerate and track EPC sections

2020-05-27 Thread Jarkko Sakkinen
On Thu, May 28, 2020 at 09:14:43AM +0300, Jarkko Sakkinen wrote:
> On Thu, May 28, 2020 at 08:35:15AM +0300, Jarkko Sakkinen wrote:
> > On Thu, May 28, 2020 at 08:25:43AM +0300, Jarkko Sakkinen wrote:
> > > On Tue, May 26, 2020 at 08:56:14PM -0700, Sean Christopherson wrote:
> > > > On Mon, May 25, 2020 at 11:23:04AM +0200, Borislav Petkov wrote:
> > > > > On Fri, May 15, 2020 at 03:43:57AM +0300, Jarkko Sakkinen wrote:
> > > > > > +struct sgx_epc_section sgx_epc_sections[SGX_MAX_EPC_SECTIONS];
> > > > > > +int sgx_nr_epc_sections;
> > > > > 
> > > > > We have become very averse against global stuff. What is going to use
> > > > > those, only sgx code I assume...?
> > > > 
> > > > Yes, only SGX code.  The reclaim/swap code needs access to the sections,
> > > > and that code is in a different file, reclaim.c.  I don't have a super
> > > > strong objection to sucking reclaim.c into main.c, but I'm somewhat
> > > > indifferent on code organization as a whole.  Jarkko likely has a 
> > > > stronger
> > > > opinion.
> > > 
> > > I'll change it.
> > > 
> > > It's not quite as easy as just "sucking the file in". All the commits
> > > that touch the file need to be reworked:
> > > 
> > > $ git --no-pager log --format="%H %s" arch/x86/kernel/cpu/sgx/reclaim.c
> > > 5aeca6dabf767e9350ee3188ba25ceb21f3162b4 x86/sgx: Add a page reclaimer
> > > de9b1088959f36ffdaf43a49bfea1c7f9f81cac7 x86/sgx: Linux Enclave Driver
> > > 08d8fcb74fe268059ee58fcc2a0833b244e1f22a x86/sgx: Enumerate and track EPC 
> > > sections
> > 
> > Not that I haven't done this a lot last few years. A proven approach
> > is to do it in two "git rebase -i mainline/master" sweeps:
> > 
> > 1. For each commit, remove reclaim.c entry from the Makefile and import
> >reclaim.c contents to main.c.
> > 2. For each commit, delete reclaim.c.
> > 
> > I've tried quite a few different angles and this what I've converged
> > into. Very hard to hit messy into messy merge conflicts.
> 
> Remembered why the things are the way they are. Also ioctl.c needs these
> symbols and I'd keep that separate from the contents of main.c and
> reclaim.c. There the separation obviously makes sense.
> 
> I'll anyway merge main.c and reclaim.c as one for v31 because they are
> strongly connected.

And more importantly for the reason that it allows to make ksgxswapd_tsk
making the whole thing way more cleaner.

/Jarkko


Re: [PATCH RFCv2 9/9] arm64: Support async page fault

2020-05-27 Thread Gavin Shan

Hi Paolo,

On 5/27/20 4:48 PM, Paolo Bonzini wrote:

I definitely appreciate the work, but this is repeating most of the
mistakes done in the x86 implementation.  In particular:

- the page ready signal can be done as an interrupt, rather than an
exception.  This is because "page ready" can be handled asynchronously,
in contrast to "page not present" which must be done on the same
instruction that triggers it.  You can refer to the recent series from
Vitaly Kuznetsov that switched "page ready" to an interrupt.



Yeah, page ready can be handled asynchronously. I think it would be
nice for x86/arm64 to share same design. x86 has 256 vectors and it
seems 0xec is picked for the purpose. However, arm64 doesn't have so
many (interrupt/exception) vectors and PPI might be appropriate for
the purpose if I'm correct, because it has same INTD for all CPUs.
From this point, it's similar to x86's vector. There are 16 PPIs, which
are in range of 16 to 31, and we might reserve one for this. According
to GICv3/v4 spec, 22 - 30 have been assigned.


- the page not present is reusing the memory abort exception, and
there's really no reason to do so.  I think it would be best if ARM
could reserve one ESR exception code for the hypervisor.  Mark, any
ideas how to proceed here?



Well, a subclass of ESR exception code, whose DFSC (Data Fault Status
Code) is 0x34, was taken for the purpose in RFCv1. The code is IMPDEF
one and Mark suggested not to do so. I agree the page not present needs a
separately subclass of exception. With that, there will be less conflicts
and complexity. However, the question is which subclass or DFSC code I should
used for the purpose.


- for x86 we're also thinking of initiating the page fault from the
exception handler, rather than doing so from the hypervisor before
injecting the exception.  If ARM leads the way here, we would do our
best to share code when x86 does the same.



Sorry, Paolo, I don't follow your idea here. Could you please provide
more details?


- do not bother with using KVM_ASYNC_PF_SEND_ALWAYS, it's a fringe case
that adds a lot of complexity.



Yeah, I don't consider it so far.


Also, please include me on further iterations of the series.



Sure.

Thanks,
Gavin

[...]



Re: [PATCH v30 07/20] x86/sgx: Enumerate and track EPC sections

2020-05-27 Thread Jarkko Sakkinen
On Thu, May 28, 2020 at 08:35:15AM +0300, Jarkko Sakkinen wrote:
> On Thu, May 28, 2020 at 08:25:43AM +0300, Jarkko Sakkinen wrote:
> > On Tue, May 26, 2020 at 08:56:14PM -0700, Sean Christopherson wrote:
> > > On Mon, May 25, 2020 at 11:23:04AM +0200, Borislav Petkov wrote:
> > > > On Fri, May 15, 2020 at 03:43:57AM +0300, Jarkko Sakkinen wrote:
> > > > > +struct sgx_epc_section sgx_epc_sections[SGX_MAX_EPC_SECTIONS];
> > > > > +int sgx_nr_epc_sections;
> > > > 
> > > > We have become very averse against global stuff. What is going to use
> > > > those, only sgx code I assume...?
> > > 
> > > Yes, only SGX code.  The reclaim/swap code needs access to the sections,
> > > and that code is in a different file, reclaim.c.  I don't have a super
> > > strong objection to sucking reclaim.c into main.c, but I'm somewhat
> > > indifferent on code organization as a whole.  Jarkko likely has a stronger
> > > opinion.
> > 
> > I'll change it.
> > 
> > It's not quite as easy as just "sucking the file in". All the commits
> > that touch the file need to be reworked:
> > 
> > $ git --no-pager log --format="%H %s" arch/x86/kernel/cpu/sgx/reclaim.c
> > 5aeca6dabf767e9350ee3188ba25ceb21f3162b4 x86/sgx: Add a page reclaimer
> > de9b1088959f36ffdaf43a49bfea1c7f9f81cac7 x86/sgx: Linux Enclave Driver
> > 08d8fcb74fe268059ee58fcc2a0833b244e1f22a x86/sgx: Enumerate and track EPC 
> > sections
> 
> Not that I haven't done this a lot last few years. A proven approach
> is to do it in two "git rebase -i mainline/master" sweeps:
> 
> 1. For each commit, remove reclaim.c entry from the Makefile and import
>reclaim.c contents to main.c.
> 2. For each commit, delete reclaim.c.
> 
> I've tried quite a few different angles and this what I've converged
> into. Very hard to hit messy into messy merge conflicts.

Remembered why the things are the way they are. Also ioctl.c needs these
symbols and I'd keep that separate from the contents of main.c and
reclaim.c. There the separation obviously makes sense.

I'll anyway merge main.c and reclaim.c as one for v31 because they are
strongly connected.

/Jarkko


Re: [PATCH 02/10] iommu/amd: Unexport get_dev_data()

2020-05-27 Thread Christoph Hellwig
On Wed, May 27, 2020 at 01:53:05PM +0200, Joerg Roedel wrote:
> From: Joerg Roedel 
> 
> This function is internal to the AMD IOMMU driver and only exported
> because the amd_iommu_v2 modules calls it. But the reason it is called
> from there could better be handled by amd_iommu_is_attach_deferred().
> So unexport get_dev_data() and use amd_iommu_is_attach_deferred()
> instead.

Btw, what is the reason amd_iommu_v2 is a separate module?  It is
very little code, and other drivers seem to just integrate such
functionality.



Re: linux-next: build warning after merge of the aspeed tree

2020-05-27 Thread Joel Stanley
On Fri, 22 May 2020 at 08:16, Arnd Bergmann  wrote:
>
> On Fri, May 22, 2020 at 2:16 AM Stephen Rothwell  
> wrote:
> > On Wed, 20 May 2020 07:56:36 + Joel Stanley  wrote:
> > > I've sent the patch so it applies to the dtc tree. It would be good to
> > > see that change propagate over to -next as others have reported this
> > > warning.
> >
> > These warnings now appear in the arm-soc tree.
>
> Right, I also saw them earlier.
>
> Joel, have you sent your patch to David Gibson for integration into
> upstream dtc?
> I don't know who sent the other patch, but as long as one of them
> gets merged, I'd hope we can pull that into kernel as well.

David asked for some extra features (and a typo fix) before he would
merge it. I'll take a look at that now.

The patch is 20200520075134.1048589-1-j...@jms.id.au on
devicetree-compi...@vger.kernel.org, which doesn't appear to be
archived on lore.


Re: [PATCH] tee: fix crypto select

2020-05-27 Thread Vesa Jääskeläinen

Hi Arnd & Jens,

On 2020-05-27 18:07, Jens Wiklander wrote:

Hi Arnd,

On Wed, May 27, 2020 at 3:39 PM Arnd Bergmann  wrote:


When selecting a crypto cipher, we also need to select the
subsystem itself:

WARNING: unmet direct dependencies detected for CRYPTO_SHA1
   Depends on [m]: CRYPTO [=m]
   Selected by [y]:
   - TEE [=y] && (HAVE_ARM_SMCCC [=n] || COMPILE_TEST [=y] || CPU_SUP_AMD [=y])
   Selected by [m]:
   - CRYPTO_DEV_QAT [=m] && CRYPTO [=m] && CRYPTO_HW [=y]
   - CRYPTO_DEV_MEDIATEK [=m] && CRYPTO [=m] && CRYPTO_HW [=y] && (ARM && 
ARCH_MEDIATEK || COMPILE_TEST [=y])
   - CRYPTO_DEV_SAFEXCEL [=m] && CRYPTO [=m] && CRYPTO_HW [=y] && (OF [=y] || PCI [=y] 
|| COMPILE_TEST [=y]) && HAS_IOMEM [=y]
   - CRYPTO_DEV_CCREE [=m] && CRYPTO [=m] && CRYPTO_HW [=y] && OF [=y] && 
HAS_DMA [=y]
   - CRYPTO_DEV_SP_CCP [=y] && CRYPTO [=m] && CRYPTO_HW [=y] && CRYPTO_DEV_CCP [=y] && 
CRYPTO_DEV_CCP_DD [=m] && DMADEVICES [=y]

Fixes: e33bcbab16d1 ("tee: add support for session's client UUID generation")
Signed-off-by: Arnd Bergmann 
---
The regression was introduced in the soc tree, I'd pick this patch
up directly into that unless someone sees a problem


Thanks for taking care of this, please go ahead.

Cheers,
Jens


I am also OK for the change. Sorry that we did not notice this during 
the review.


Feel free to merge it to the original commit or leave as separate commit.

Reviewed-by: Vesa Jääskeläinen 




---
  drivers/tee/Kconfig | 1 +
  1 file changed, 1 insertion(+)

diff --git a/drivers/tee/Kconfig b/drivers/tee/Kconfig
index 806eb87d4da0..e99d840c2511 100644
--- a/drivers/tee/Kconfig
+++ b/drivers/tee/Kconfig
@@ -3,6 +3,7 @@
  config TEE
 tristate "Trusted Execution Environment support"
 depends on HAVE_ARM_SMCCC || COMPILE_TEST || CPU_SUP_AMD
+   select CRYPTO
 select CRYPTO_SHA1
 select DMA_SHARED_BUFFER
 select GENERIC_ALLOCATOR
--
2.26.2



[PATCH] s390: vdso: Use $(LD) instead of $(CC) to link vDSO

2020-05-27 Thread Nathan Chancellor
Currently, the VDSO is being linked through $(CC). This does not match
how the rest of the kernel links objects, which is through the $(LD)
variable.

When clang is built in a default configuration, it first attempts to use
the target triple's default linker, which is just ld. However, the user
can override this through the CLANG_DEFAULT_LINKER cmake define so that
clang uses another linker by default, such as LLVM's own linker, ld.lld.
This can be useful to get more optimized links across various different
projects.

However, this is problematic for the s390 vDSO because ld.lld does not
have any s390 emulatiom support:

https://github.com/llvm/llvm-project/blob/llvmorg-10.0.1-rc1/lld/ELF/Driver.cpp#L132-L150

Thus, if a user is using a toolchain with ld.lld as the default, they
will see an error, even if they have specified ld.bfd through the LD
make variable:

$ make -j"$(nproc)" -s ARCH=s390 CROSS_COMPILE=s390x-linux-gnu- LLVM=1 \
   LD=s390x-linux-gnu-ld \
   defconfig arch/s390/kernel/vdso64/
ld.lld: error: unknown emulation: elf64_s390
clang-11: error: linker command failed with exit code 1 (use -v to see 
invocation)

Normally, '-fuse-ld=bfd' could be used to get around this; however, this
can be fragile, depending on paths and variable naming. The cleaner
solution for the kernel is to take advantage of the fact that $(LD) can
be invoked directly, which bypasses the heuristics of $(CC) and respects
the user's choice. Similar changes have been done for ARM, ARM64, and
MIPS.

Link: https://github.com/ClangBuiltLinux/linux/issues/1041
Signed-off-by: Nathan Chancellor 
---
 arch/s390/kernel/vdso64/Makefile | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/s390/kernel/vdso64/Makefile b/arch/s390/kernel/vdso64/Makefile
index bec19e7e6e1c..b8db1ffbc2b9 100644
--- a/arch/s390/kernel/vdso64/Makefile
+++ b/arch/s390/kernel/vdso64/Makefile
@@ -18,8 +18,8 @@ KBUILD_AFLAGS_64 += -m64 -s
 
 KBUILD_CFLAGS_64 := $(filter-out -m64,$(KBUILD_CFLAGS))
 KBUILD_CFLAGS_64 += -m64 -fPIC -shared -fno-common -fno-builtin
-KBUILD_CFLAGS_64 += -nostdlib -Wl,-soname=linux-vdso64.so.1 \
-   -Wl,--hash-style=both
+ldflags-y := -shared -nostdlib -soname=linux-vdso64.so.1 \
+--hash-style=both -T
 
 $(targets:%=$(obj)/%.dbg): KBUILD_CFLAGS = $(KBUILD_CFLAGS_64)
 $(targets:%=$(obj)/%.dbg): KBUILD_AFLAGS = $(KBUILD_AFLAGS_64)
@@ -37,8 +37,8 @@ KASAN_SANITIZE := n
 $(obj)/vdso64_wrapper.o : $(obj)/vdso64.so
 
 # link rule for the .so file, .lds has to be first
-$(obj)/vdso64.so.dbg: $(src)/vdso64.lds $(obj-vdso64) FORCE
-   $(call if_changed,vdso64ld)
+$(obj)/vdso64.so.dbg: $(obj)/vdso64.lds $(obj-vdso64) FORCE
+   $(call if_changed,ld)
 
 # strip rule for the .so file
 $(obj)/%.so: OBJCOPYFLAGS := -S
@@ -50,8 +50,6 @@ $(obj-vdso64): %.o: %.S FORCE
$(call if_changed_dep,vdso64as)
 
 # actual build commands
-quiet_cmd_vdso64ld = VDSO64L $@
-  cmd_vdso64ld = $(CC) $(c_flags) -Wl,-T $(filter %.lds %.o,$^) -o $@
 quiet_cmd_vdso64as = VDSO64A $@
   cmd_vdso64as = $(CC) $(a_flags) -c -o $@ $<
 

base-commit: 9cb1fd0efd195590b828b9b865421ad345a4a145
-- 
2.27.0.rc0



Re: [PATCH 06/12] PM / devfreq: Add cpu based scaling support to passive_governor

2020-05-27 Thread Chanwoo Choi
Hi Andrew-sh.Cheng,

Thanks for your posting. I like this approach absolutely.
I think that it is necessary. When I developed the embedded product,
I needed this feature always. 

I add the comments on below.


And the following email is not valid. So, I dropped this email
from Cc list.
Saravana Kannan 


On 5/20/20 12:43 PM, Andrew-sh.Cheng wrote:
> From: Saravana Kannan 
> 
> Many CPU architectures have caches that can scale independent of the
> CPUs. Frequency scaling of the caches is necessary to make sure that the
> cache is not a performance bottleneck that leads to poor performance and
> power. The same idea applies for RAM/DDR.
> 
> To achieve this, this patch adds support for cpu based scaling to the
> passive governor. This is accomplished by taking the current frequency
> of each CPU frequency domain and then adjust the frequency of the cache
> (or any devfreq device) based on the frequency of the CPUs. It listens
> to CPU frequency transition notifiers to keep itself up to date on the
> current CPU frequency.
> 
> To decide the frequency of the device, the governor does one of the
> following:
> * Derives the optimal devfreq device opp from required-opps property of
>   the parent cpu opp_table.
> 
> * Scales the device frequency in proportion to the CPU frequency. So, if
>   the CPUs are running at their max frequency, the device runs at its
>   max frequency. If the CPUs are running at their min frequency, the
>   device runs at its min frequency. It is interpolated for frequencies
>   in between.
> 
> Andrew-sh.Cheng change
> dev_pm_opp_xlate_opp to dev_pm_opp_xlate_required_opp devfreq->max_freq
> to devfreq->user_min_freq_req.data.freq.qos->min_freq.target_value
> for kernel-5.7
> 
> Signed-off-by: Saravana Kannan 
> [Sibi: Integrated cpu-freqmap governor into passive_governor]
> Signed-off-by: Sibi Sankar 
> Signed-off-by: Andrew-sh.Cheng 
> ---
>  drivers/devfreq/Kconfig|   2 +
>  drivers/devfreq/governor_passive.c | 278 
> ++---
>  include/linux/devfreq.h|  40 +-
>  3 files changed, 299 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/devfreq/Kconfig b/drivers/devfreq/Kconfig
> index 0b1df12e0f21..d9067950af6a 100644
> --- a/drivers/devfreq/Kconfig
> +++ b/drivers/devfreq/Kconfig
> @@ -73,6 +73,8 @@ config DEVFREQ_GOV_PASSIVE
> device. This governor does not change the frequency by itself
> through sysfs entries. The passive governor recommends that
> devfreq device uses the OPP table to get the frequency/voltage.
> +   Alternatively the governor can also be chosen to scale based on
> +   the online CPUs current frequency.
>  
>  comment "DEVFREQ Drivers"
>  
> diff --git a/drivers/devfreq/governor_passive.c 
> b/drivers/devfreq/governor_passive.c
> index 2d67d6c12dce..7dcda02a5bb7 100644
> --- a/drivers/devfreq/governor_passive.c
> +++ b/drivers/devfreq/governor_passive.c
> @@ -8,11 +8,89 @@
>   */
>  
>  #include 
> +#include 
> +#include 
> +#include 
>  #include 
>  #include 
> +#include 
>  #include "governor.h"
>  
> -static int devfreq_passive_get_target_freq(struct devfreq *devfreq,
> +static unsigned int xlate_cpufreq_to_devfreq(struct devfreq_passive_data 
> *data,

Need to change 'unsigned int' to 'unsigned long'.

> +  unsigned int cpu)
> +{
> + unsigned int cpu_min, cpu_max, dev_min, dev_max, cpu_percent, max_state;

Better to define them separately as following and then need to rename
the variable. Usually, use the 'min_freq' and 'max_freq' word for
the minimum/maximum frequency.

unsigned int cpu_min_freq, cpu_max_freq, cpu_curr_freq, cpu_percent;
unsigned long dev_min_freq, dev_max_freq, dev_max_state,

The devfreq used 'unsigned long'. The cpufreq used 'unsigned long'
and 'unsigned int'. You need to handle them properly.


> + struct devfreq_cpu_state *cpu_state = data->cpu_state[cpu];
> + struct devfreq *devfreq = (struct devfreq *)data->this;
> + unsigned long *freq_table = devfreq->profile->freq_table;

In this function, use 'cpu' work for cpufreq and use 'dev' for devfreq.
So, I think 'dev_freq_table' is proper name instead of 'freq_table'
for the readability.

freq_table -> dev_freq_table

> + struct dev_pm_opp *opp = NULL, *cpu_opp = NULL;

In the get_target_freq_with_devfreq(), use 'p_opp' indicating
the OPP of parent device. For the consistency, I think that
use 'p_opp' instead of 'cpu_opp'. 

> + unsigned long cpu_freq, freq;

Define the 'cpu_freq' on above with cpu_min_freq/cpu_max_freq definition.
cpu_freq -> cpu_curr_freq.

> +
> + if (!cpu_state || cpu_state->first_cpu != cpu ||
> + !cpu_state->opp_table || !devfreq->opp_table)
> + return 0;
> +
> + cpu_freq = cpu_state->freq * 1000;
> + cpu_opp = devfreq_recommended_opp(cpu_state->dev, &cpu_freq, 0);
> + if (IS_ERR(cpu_opp))
> + return 0;
> +
> + opp = dev_pm_opp

[v2] ASoC: AMD: Use mixer control to switch between DMICs

2020-05-27 Thread Akshu Agrawal
Having mixer control to switch between DMICs prevents user to
initiate capture simultaneously on both the DMIcs.
Earlier 2 separate devices, one for each DMIC, gave an option of
using them simultaneously, which is not supported.

Signed-off-by: Akshu Agrawal 
---
v2: Modified "Front Mic" to "DMIC Switch"
 sound/soc/amd/acp3x-rt5682-max9836.c | 43 +++-
 1 file changed, 16 insertions(+), 27 deletions(-)

diff --git a/sound/soc/amd/acp3x-rt5682-max9836.c 
b/sound/soc/amd/acp3x-rt5682-max9836.c
index e499c00e0c66..0d3422b5f1a9 100644
--- a/sound/soc/amd/acp3x-rt5682-max9836.c
+++ b/sound/soc/amd/acp3x-rt5682-max9836.c
@@ -188,25 +188,27 @@ static int acp3x_ec_dmic0_startup(struct 
snd_pcm_substream *substream)
 
machine->cap_i2s_instance = I2S_BT_INSTANCE;
snd_soc_dai_set_bclk_ratio(codec_dai, 64);
-   if (dmic_sel)
-   gpiod_set_value(dmic_sel, 0);
 
return rt5682_clk_enable(substream);
 }
 
-static int acp3x_ec_dmic1_startup(struct snd_pcm_substream *substream)
-{
-   struct snd_soc_pcm_runtime *rtd = substream->private_data;
-   struct snd_soc_card *card = rtd->card;
-   struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
-   struct acp3x_platform_info *machine = snd_soc_card_get_drvdata(card);
+static int dmic_switch;
 
-   machine->cap_i2s_instance = I2S_BT_INSTANCE;
-   snd_soc_dai_set_bclk_ratio(codec_dai, 64);
-   if (dmic_sel)
-   gpiod_set_value(dmic_sel, 1);
+static int dmic_get(struct snd_kcontrol *kcontrol,
+struct snd_ctl_elem_value *ucontrol)
+{
+   ucontrol->value.integer.value[0] = dmic_switch;
+   return 0;
+}
 
-   return rt5682_clk_enable(substream);
+static int dmic_set(struct snd_kcontrol *kcontrol,
+struct snd_ctl_elem_value *ucontrol)
+{
+   if (dmic_sel) {
+   dmic_switch = ucontrol->value.integer.value[0];
+   gpiod_set_value(dmic_sel, !dmic_switch);
+   }
+   return 0;
 }
 
 static void rt5682_shutdown(struct snd_pcm_substream *substream)
@@ -229,11 +231,6 @@ static const struct snd_soc_ops acp3x_ec_cap0_ops = {
.shutdown = rt5682_shutdown,
 };
 
-static const struct snd_soc_ops acp3x_ec_cap1_ops = {
-   .startup = acp3x_ec_dmic1_startup,
-   .shutdown = rt5682_shutdown,
-};
-
 SND_SOC_DAILINK_DEF(acp3x_i2s,
DAILINK_COMP_ARRAY(COMP_CPU("acp3x_i2s_playcap.0")));
 SND_SOC_DAILINK_DEF(acp3x_bt,
@@ -279,15 +276,6 @@ static struct snd_soc_dai_link acp3x_dai_5682_98357[] = {
.ops = &acp3x_ec_cap0_ops,
SND_SOC_DAILINK_REG(acp3x_bt, cros_ec, platform),
},
-   {
-   .name = "acp3x-ec-dmic1-capture",
-   .stream_name = "Capture DMIC1",
-   .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
-   | SND_SOC_DAIFMT_CBS_CFS,
-   .dpcm_capture = 1,
-   .ops = &acp3x_ec_cap1_ops,
-   SND_SOC_DAILINK_REG(acp3x_bt, cros_ec, platform),
-   },
 };
 
 static const struct snd_soc_dapm_widget acp3x_widgets[] = {
@@ -307,6 +295,7 @@ static const struct snd_kcontrol_new acp3x_mc_controls[] = {
SOC_DAPM_PIN_SWITCH("Headphone Jack"),
SOC_DAPM_PIN_SWITCH("Spk"),
SOC_DAPM_PIN_SWITCH("Headset Mic"),
+   SOC_SINGLE_BOOL_EXT("DMIC Switch", 0, dmic_get, dmic_set),
 };
 
 static struct snd_soc_card acp3x_card = {
-- 
2.20.1



I.T. X plan:

2020-05-27 Thread Ywe Cærlyn

* Karmic Koala bootstyle,high res text, no image / initrd.
* Enligthenment, Right Corner Bar/Launch Menu
* Fair Pay, lexically organized commercial directory. 
Com:|Top|Category|Subcategory|1m km2 zone|23.000 km2 
zone|Person|Groupings - no unecessary logins, easy exposure, and 
changing / to | symbolizing fair pay structure, and also making / 
available in filenames, which is a common thing.

* 0.33 ms latency Renoise, suggesting optimized paths for this.
* 72.7 (3x pass) Doom 3 (low jitter config) - will probably be great for 
Direct 3D 12.
* Readied for €-money integration. EU optimally symbolically located for 
this.
* Calibri font for easy cursive Islamic integration, and bold chan 
integration, supporting all developments back to Adams Tablet, source of 
fair job principles. Hail Jagod!


Serene Greetings,
Ywe Cærlyn
https://www.youtube.com/channel/UCR3gmLVjHS5A702wo4bol_Q


Re: [GIT PULL] sh: remove sh5 support

2020-05-27 Thread John Paul Adrian Glaubitz
On 5/28/20 7:46 AM, Christoph Hellwig wrote:
> [adding Linus]
> 
> On Thu, May 07, 2020 at 07:35:52AM -0700, Christoph Hellwig wrote:
>> Any progress on this?  I plan to resend the sh dma-mapping I've been
>> trying to get upstream for a year again, and they would conflict,
>> so I could look into rebasing them first.
> 
> So for years now it has been close to and in the end impossible to
> provoke sh maintainer action.  At the same point hardware is pretty much
> long gone for the real commercial variants, and never took off for the
> open hardware nommu variant.
> 
> Linus, would you ok with a 5.8 pull request to just kill off arch/sh/?

We're maintaining SH in Debian so I'm interested in keeping arch/sh, but
I'm also let down that SH maintainers aren't that active at the moment.

I do know that Yoshinori Sato has a tree where he takes patches and sends
PRs from time to time, but I have no idea what is going on.

Adrian

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - glaub...@debian.org
`. `'   Freie Universitaet Berlin - glaub...@physik.fu-berlin.de
  `-GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913


Re: [PATCH v2] sctp: check assoc before SCTP_ADDR_{MADE_PRIM,ADDED} event

2020-05-27 Thread Xin Long
On Wed, May 27, 2020 at 5:57 PM Jonas Falkevik  wrote:
>
> Make sure SCTP_ADDR_{MADE_PRIM,ADDED} are sent only for associations
> that have been established.
>
> These events are described in rfc6458#section-6.1
> SCTP_PEER_ADDR_CHANGE:
> This tag indicates that an address that is
> part of an existing association has experienced a change of
> state (e.g., a failure or return to service of the reachability
> of an endpoint via a specific transport address).
>
> Signed-off-by: Jonas Falkevik 
Reviewed-by: Xin Long 

> ---
> Changes in v2:
>  - Check asoc state to be at least established.
>Instead of associd being SCTP_FUTURE_ASSOC.
>  - Common check for all peer addr change event
>
>  net/sctp/ulpevent.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/net/sctp/ulpevent.c b/net/sctp/ulpevent.c
> index c82dbdcf13f2..77d5c36a8991 100644
> --- a/net/sctp/ulpevent.c
> +++ b/net/sctp/ulpevent.c
> @@ -343,6 +343,9 @@ void sctp_ulpevent_nofity_peer_addr_change(struct 
> sctp_transport *transport,
> struct sockaddr_storage addr;
> struct sctp_ulpevent *event;
>
> +   if (asoc->state < SCTP_STATE_ESTABLISHED)
> +   return;
> +
> memset(&addr, 0, sizeof(struct sockaddr_storage));
> memcpy(&addr, &transport->ipaddr, 
> transport->af_specific->sockaddr_len);
>
> --
> 2.25.4
>


Re: [PATCH 5.6 086/126] virtio-balloon: Revert "virtio-balloon: Switch back to OOM handler for VIRTIO_BALLOON_F_DEFLATE_ON_OOM"

2020-05-27 Thread Jiri Slaby
On 26. 05. 20, 20:53, Greg Kroah-Hartman wrote:
> From: Michael S. Tsirkin 
> 
> [ Upstream commit 835a6a649d0dd1b1f46759eb60fff2f63ed253a7 ]
> 
> This reverts commit 5a6b4cc5b7a1892a8d7f63d6cbac6e0ae2a9d031.
> 
> It has been queued properly in the akpm tree, this version is just
> creating conflicts.

Should this be applied to stable trees at all?

To me, it occurs to be a revert to avoid conflicts, not to fix something?

> Signed-off-by: Michael S. Tsirkin 
> Signed-off-by: Sasha Levin 

thanks,
-- 
js
suse labs


Re: [PATCH net-next 2/4] vmxnet3: add support to get/set rx flow hash

2020-05-27 Thread Michal Kubecek
On Wed, May 27, 2020 at 07:07:04PM -0700, Ronak Doshi wrote:
> With vmxnet3 version 4, the emulation supports multiqueue(RSS) for
> UDP and ESP traffic. A guest can enable/disable RSS for UDP/ESP over
> IPv4/IPv6 by issuing commands introduced in this patch. ESP ipv6 is
> not yet supported in this patch.
> 
> This patch implements get_rss_hash_opts and set_rss_hash_opts
> methods to allow querying and configuring different Rx flow hash
> configurations.
> 
> Signed-off-by: Ronak Doshi 
> ---
[...]
> diff --git a/drivers/net/vmxnet3/vmxnet3_ethtool.c 
> b/drivers/net/vmxnet3/vmxnet3_ethtool.c
> index 1163eca7aba5..ceedf63020cb 100644
> --- a/drivers/net/vmxnet3/vmxnet3_ethtool.c
> +++ b/drivers/net/vmxnet3/vmxnet3_ethtool.c
> @@ -665,18 +665,236 @@ vmxnet3_set_ringparam(struct net_device *netdev,
>   return err;
>  }
>  
> +static int
> +vmxnet3_get_rss_hash_opts(struct vmxnet3_adapter *adapter,
> +   struct ethtool_rxnfc *info)
> +{
> + enum Vmxnet3_RSSField rss_fields;
> +
> + if (netif_running(adapter->netdev)) {
> + unsigned long flags;
> +
> + spin_lock_irqsave(&adapter->cmd_lock, flags);
> +
> + VMXNET3_WRITE_BAR1_REG(adapter, VMXNET3_REG_CMD,
> +VMXNET3_CMD_GET_RSS_FIELDS);
> + rss_fields = VMXNET3_READ_BAR1_REG(adapter, VMXNET3_REG_CMD);
> + spin_unlock_irqrestore(&adapter->cmd_lock, flags);
> + } else {
> + rss_fields = adapter->rss_fields;
> + }
> +
> + info->data = 0;
> +
> + /* Report default options for RSS on vmxnet3 */
> + switch (info->flow_type) {
> + case TCP_V4_FLOW:
> + if (rss_fields & VMXNET3_RSS_FIELDS_TCPIP4)
> + info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3 |
> +   RXH_IP_SRC | RXH_IP_DST;
> + break;
> + case UDP_V4_FLOW:
> + if (rss_fields & VMXNET3_RSS_FIELDS_UDPIP4)
> + info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3 |
> +   RXH_IP_SRC | RXH_IP_DST;
> + break;

In both cases above (and also in the two for IPv6 below) you set
info->data to either 0 or all four bits, depending on the value of
corresponding flag in rss_fields. But in vmxnet3_set_rss_hash_opt()
you have different mapping:

  - for TCP, you only accept all four bits (no other value) and don't
touch rss_fields at all
  - for UDP, you allow either all four bits (and set the flag) or the
two IP related bits (and clear the flag)

The UDPv4/UDPv6 behaviour of vmxnet3_set_rss_hash_opt() seems to be the
correct one but you should be consistent between get and set handlers.

> + case AH_ESP_V4_FLOW:
> + case AH_V4_FLOW:
> + case ESP_V4_FLOW:
> + if (rss_fields & VMXNET3_RSS_FIELDS_ESPIP4)
> + info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;

If this fallthrough is intentional (it seems to be), it should be
marked.

Michal

> + case SCTP_V4_FLOW:
> + case IPV4_FLOW:
> + info->data |= RXH_IP_SRC | RXH_IP_DST;
> + break;
> + case TCP_V6_FLOW:
> + if (rss_fields & VMXNET3_RSS_FIELDS_TCPIP6)
> + info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3 |
> +   RXH_IP_SRC | RXH_IP_DST;
> + break;
> + case UDP_V6_FLOW:
> + if (rss_fields & VMXNET3_RSS_FIELDS_UDPIP6)
> + info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3 |
> +   RXH_IP_SRC | RXH_IP_DST;
> + break;
> + case AH_ESP_V6_FLOW:
> + case AH_V6_FLOW:
> + case ESP_V6_FLOW:
> + case SCTP_V6_FLOW:
> + case IPV6_FLOW:
> + info->data |= RXH_IP_SRC | RXH_IP_DST;
> + break;
> + default:
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
> +
> +static int
> +vmxnet3_set_rss_hash_opt(struct net_device *netdev,
> +  struct vmxnet3_adapter *adapter,
> +  struct ethtool_rxnfc *nfc)
> +{
> + enum Vmxnet3_RSSField rss_fields = adapter->rss_fields;
> +
> + /* RSS does not support anything other than hashing
> +  * to queues on src and dst IPs and ports
> +  */
> + if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
> +   RXH_L4_B_0_1 | RXH_L4_B_2_3))
> + return -EINVAL;
> +
> + switch (nfc->flow_type) {
> + case TCP_V4_FLOW:
> + case TCP_V6_FLOW:
> + if (!(nfc->data & RXH_IP_SRC) ||
> + !(nfc->data & RXH_IP_DST) ||
> + !(nfc->data & RXH_L4_B_0_1) ||
> + !(nfc->data & RXH_L4_B_2_3))
> + return -EINVAL;
> + break;
> + case UDP_V4_FLOW:
> + if (!(nfc->data & RXH_IP_SRC) ||
> + !(nfc->data & RXH_IP_DST))
> + return -EINVAL;
> + switch (nfc->data & (RXH_L4_B_0_1 | RXH_L

Re: [PATCHv2] media: videobuf2-dma-contig: fix bad kfree in vb2_dma_contig_clear_max_seg_size

2020-05-27 Thread Marek Szyprowski
On 27.05.2020 10:23, Tomi Valkeinen wrote:
> Commit 9495b7e92f716ab2bd6814fab5e97ab4a39adfdd ("driver core: platform:
> Initialize dma_parms for platform devices") in v5.7-rc5 causes
> vb2_dma_contig_clear_max_seg_size() to kfree memory that was not
> allocated by vb2_dma_contig_set_max_seg_size().
>
> The assumption in vb2_dma_contig_set_max_seg_size() seems to be that
> dev->dma_parms is always NULL when the driver is probed, and the case
> where dev->dma_parms has bee initialized by someone else than the driver
> (by calling vb2_dma_contig_set_max_seg_size) will cause a failure.
>
> All the current users of these functions are platform devices, which now
> always have dma_parms set by the driver core. To fix the issue for v5.7,
> make vb2_dma_contig_set_max_seg_size() return an error if dma_parms is
> NULL to be on the safe side, and remove the kfree code from
> vb2_dma_contig_clear_max_seg_size().
>
> For v5.8 we should remove the two functions and move the
> dma_set_max_seg_size() calls into the drivers.
>
> Signed-off-by: Tomi Valkeinen 
> Fixes: 9495b7e92f71 ("driver core: platform: Initialize dma_parms for 
> platform devices")
> Cc: sta...@vger.kernel.org
Acked-by: Marek Szyprowski 
> ---
>
> Changes in v2:
> * vb2_dma_contig_clear_max_seg_size to empty static inline
> * Added cc: stable and fixes tag
>
>   .../common/videobuf2/videobuf2-dma-contig.c   | 20 ++-
>   include/media/videobuf2-dma-contig.h  |  2 +-
>   2 files changed, 3 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c 
> b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> index d3a3ee5b597b..f4b4a7c135eb 100644
> --- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> +++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> @@ -726,9 +726,8 @@ EXPORT_SYMBOL_GPL(vb2_dma_contig_memops);
>   int vb2_dma_contig_set_max_seg_size(struct device *dev, unsigned int size)
>   {
>   if (!dev->dma_parms) {
> - dev->dma_parms = kzalloc(sizeof(*dev->dma_parms), GFP_KERNEL);
> - if (!dev->dma_parms)
> - return -ENOMEM;
> + dev_err(dev, "Failed to set max_seg_size: dma_parms is NULL\n");
> + return -ENODEV;
>   }
>   if (dma_get_max_seg_size(dev) < size)
>   return dma_set_max_seg_size(dev, size);
> @@ -737,21 +736,6 @@ int vb2_dma_contig_set_max_seg_size(struct device *dev, 
> unsigned int size)
>   }
>   EXPORT_SYMBOL_GPL(vb2_dma_contig_set_max_seg_size);
>   
> -/*
> - * vb2_dma_contig_clear_max_seg_size() - release resources for DMA parameters
> - * @dev: device for configuring DMA parameters
> - *
> - * This function releases resources allocated to configure DMA parameters
> - * (see vb2_dma_contig_set_max_seg_size() function). It should be called from
> - * device drivers on driver remove.
> - */
> -void vb2_dma_contig_clear_max_seg_size(struct device *dev)
> -{
> - kfree(dev->dma_parms);
> - dev->dma_parms = NULL;
> -}
> -EXPORT_SYMBOL_GPL(vb2_dma_contig_clear_max_seg_size);
> -
>   MODULE_DESCRIPTION("DMA-contig memory handling routines for videobuf2");
>   MODULE_AUTHOR("Pawel Osciak ");
>   MODULE_LICENSE("GPL");
> diff --git a/include/media/videobuf2-dma-contig.h 
> b/include/media/videobuf2-dma-contig.h
> index 5604818d137e..5be313cbf7d7 100644
> --- a/include/media/videobuf2-dma-contig.h
> +++ b/include/media/videobuf2-dma-contig.h
> @@ -25,7 +25,7 @@ vb2_dma_contig_plane_dma_addr(struct vb2_buffer *vb, 
> unsigned int plane_no)
>   }
>   
>   int vb2_dma_contig_set_max_seg_size(struct device *dev, unsigned int size);
> -void vb2_dma_contig_clear_max_seg_size(struct device *dev);
> +static inline void vb2_dma_contig_clear_max_seg_size(struct device *dev) { }
>   
>   extern const struct vb2_mem_ops vb2_dma_contig_memops;
>   

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland



Re: [GIT PULL] sh: remove sh5 support

2020-05-27 Thread Christoph Hellwig
[adding Linus]

On Thu, May 07, 2020 at 07:35:52AM -0700, Christoph Hellwig wrote:
> Any progress on this?  I plan to resend the sh dma-mapping I've been
> trying to get upstream for a year again, and they would conflict,
> so I could look into rebasing them first.

So for years now it has been close to and in the end impossible to
provoke sh maintainer action.  At the same point hardware is pretty much
long gone for the real commercial variants, and never took off for the
open hardware nommu variant.

Linus, would you ok with a 5.8 pull request to just kill off arch/sh/?

> 
> On Sat, Apr 25, 2020 at 12:19:47AM +0200, Arnd Bergmann wrote:
> > The following changes since commit
> > ae83d0b416db002fe95601e7f97f64b59514d936:
> > 
> >   Linux 5.7-rc2 (2020-04-19 14:35:30 -0700)
> > 
> > are available in the Git repository at:
> > 
> >   git://git.kernel.org:/pub/scm/linux/kernel/git/arnd/playground.git
> > tags/sh5-remove
> > 
> > for you to fetch changes up to 29e36fbee3be4c13ff6881a275c86d5f68acfa23:
> > 
> >   sh: remove sh5 support (2020-04-24 22:20:55 +0200)
> > 
> > 
> > sh: remove sh5 support
> > 
> > At long last, this is the removal of the 64-bit sh5 port
> > that never went into production.
> > 
> > Signed-off-by: Arnd Bergmann 
> > 
> > 
> > 
> > v2: I should have fixed all the missing changes that Geert pointed out,
> > this time sending it as a pull request as the removal patch is
> > too big for the mailing lists, and a 'git format-patch -D' patch
> > is unreliable
> > 
> > Arnd Bergmann (1):
> >   sh: remove sh5 support
> > 
> >  arch/sh/Kconfig   |   62 +-
> >  arch/sh/Kconfig.cpu   |9 -
> >  arch/sh/Kconfig.debug |   13 +-
> >  arch/sh/Makefile  |   29 +-
> >  arch/sh/boot/compressed/Makefile  |   12 +-
> >  arch/sh/boot/compressed/misc.c|8 -
> >  arch/sh/drivers/pci/Makefile  |1 -
> >  arch/sh/drivers/pci/ops-sh5.c |   65 -
> >  arch/sh/drivers/pci/pci-sh5.c |  217 ---
> >  arch/sh/drivers/pci/pci-sh5.h |  108 --
> >  arch/sh/include/asm/barrier.h |4 +-
> >  arch/sh/include/asm/bitops.h  |   26 -
> >  arch/sh/include/asm/bl_bit.h  |   11 +-
> >  arch/sh/include/asm/bl_bit_64.h   |   37 -
> >  arch/sh/include/asm/bugs.h|4 -
> >  arch/sh/include/asm/cache_insns.h |   12 +-
> >  arch/sh/include/asm/cache_insns_64.h  |   20 -
> >  arch/sh/include/asm/checksum.h|6 +-
> >  arch/sh/include/asm/elf.h |   23 -
> >  arch/sh/include/asm/extable.h |4 -
> >  arch/sh/include/asm/fixmap.h  |4 -
> >  arch/sh/include/asm/io.h  |4 -
> >  arch/sh/include/asm/irq.h |3 -
> >  arch/sh/include/asm/mmu_context.h |   12 -
> >  arch/sh/include/asm/mmu_context_64.h  |   75 -
> >  arch/sh/include/asm/module.h  |4 -
> >  arch/sh/include/asm/page.h|   21 +-
> >  arch/sh/include/asm/pgtable.h |   17 -
> >  arch/sh/include/asm/pgtable_64.h  |  307 
> >  arch/sh/include/asm/posix_types.h |6 +-
> >  arch/sh/include/asm/processor.h   |   14 +-
> >  arch/sh/include/asm/processor_64.h|  212 ---
> >  arch/sh/include/asm/ptrace_64.h   |   14 -
> >  arch/sh/include/asm/string.h  |6 +-
> >  arch/sh/include/asm/string_64.h   |   21 -
> >  arch/sh/include/asm/switch_to.h   |   11 +-
> >  arch/sh/include/asm/switch_to_64.h|   32 -
> >  arch/sh/include/asm/syscall.h |6 +-
> >  arch/sh/include/asm/syscall_64.h  |   75 -
> >  arch/sh/include/asm/syscalls.h|9 +-
> >  arch/sh/include/asm/syscalls_64.h |   18 -
> >  arch/sh/include/asm/thread_info.h |4 +-
> >  arch/sh/include/asm/tlb.h |6 +-
> >  arch/sh/include/asm/tlb_64.h  |   68 -
> >  arch/sh/include/asm/traps.h   |4 -
> >  arch/sh/include/asm/traps_64.h|   35 -
> >  arch/sh/include/asm/types.h   |5 -
> >  arch/sh/include/asm/uaccess.h |4 -
> >  arch/sh/include/asm/uaccess_64.h  |   85 -
> >  arch/sh/include/asm/unistd.h  |6 +-
> >  arch/sh/include/asm/user.h|7 -
> >  arch/sh/include/asm/vmlinux.lds.h |8 -
> >  arch/sh/include/cpu-sh5/cpu/addrspace.h   |   12 -
> >  arch/sh/include/cpu-sh5/cpu/cache.h   |   94 -
> >  arch/sh/include/cpu-sh5/cpu/irq.h |  113 --
> >  arch/sh/include/cpu-sh5/cpu/mmu_context.h |   22 -
> >  arch/sh/include/cpu-sh5/cpu/registers.h   |  103 --
> >  arch/sh/include/cpu-sh5/cpu/rtc.h |9 -
> >  arch/sh/include

Re: [PATCH v1 2/2] Add PWM driver for LGM

2020-05-27 Thread Tanwar, Rahul


On 27/5/2020 5:15 pm, Andy Shevchenko wrote:
> On Wed, May 27, 2020 at 02:28:53PM +0800, Tanwar, Rahul wrote:
>> On 22/5/2020 4:56 pm, Uwe Kleine-König wrote:
>>> On Fri, May 22, 2020 at 03:41:59PM +0800, Rahul Tanwar wrote:
> ...
>
>>> I'm a unhappy to have this in the PWM driver. The PWM driver is supposed
>>> to be generic and I think this belongs into a dedicated driver.
>> Well noted about all other review concerns. I will rework the driver in v2.
>> However, i am not very sure about the above point - of having a separate
>> dedicated driver for tach_work because its logic is tightly coupled with
>> this driver.
> Actually I agree with Uwe.
> Here is layering violation, i.e. provider and consumer in the same pot. It's
> not good from design perspective.
>

Just to clarify, the PWM controller in our SoC serves just one purpose which
is to control the fan. Its actually named as PWM Fan Controller. There is no
other generic usage or any other consumer for this PWM driver. So separating
out this part seems redundant to me. Also, if we separate it out as a
dedicated driver, this will endup as a very small daemon which is going to be
very hard to justify while upstreaming..

Regards,
Rahul 


Re: [PATCH 3/3] perf jvmti: Fix demangling Java symbols

2020-05-27 Thread Nick Gasson
On 05/28/20 06:34 AM, Arnaldo Carvalho de Melo wrote:
>> 
>> This is in my tmp.perf/core branch pending a round of testing, after
>> that it'll move to perf/core on its way to 5.8, thanks.
>
> All tests passed, moved to perf/core.
>

Great, thank you!

--
Nick



[PATCH 01/14] cachefiles: switch to kernel_write

2020-05-27 Thread Christoph Hellwig
__kernel_write doesn't take a sb_writers references, which we need here.

Signed-off-by: Christoph Hellwig 
Reviewed-by: David Howells 
---
 fs/cachefiles/rdwr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
index e7726f5f1241c..3080cda9e8245 100644
--- a/fs/cachefiles/rdwr.c
+++ b/fs/cachefiles/rdwr.c
@@ -937,7 +937,7 @@ int cachefiles_write_page(struct fscache_storage *op, 
struct page *page)
}
 
data = kmap(page);
-   ret = __kernel_write(file, data, len, &pos);
+   ret = kernel_write(file, data, len, &pos);
kunmap(page);
fput(file);
if (ret != len)
-- 
2.26.2



[PATCH 10/14] fs: add a __kernel_read helper

2020-05-27 Thread Christoph Hellwig
This is the counterpart to __kernel_write, and skip the rw_verify_area
call compared to kernel_read.

Signed-off-by: Christoph Hellwig 
---
 fs/read_write.c| 21 +
 include/linux/fs.h |  1 +
 2 files changed, 22 insertions(+)

diff --git a/fs/read_write.c b/fs/read_write.c
index 8cfca5f8fc3ce..bd12af8a895c8 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -430,6 +430,27 @@ ssize_t __vfs_read(struct file *file, char __user *buf, 
size_t count,
return -EINVAL;
 }
 
+ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
+{
+   mm_segment_t old_fs = get_fs();
+   ssize_t ret;
+
+   if (!(file->f_mode & FMODE_CAN_READ))
+   return -EINVAL;
+
+   if (count > MAX_RW_COUNT)
+   count =  MAX_RW_COUNT;
+   set_fs(KERNEL_DS);
+   ret = __vfs_read(file, (void __user *)buf, count, pos);
+   set_fs(old_fs);
+   if (ret > 0) {
+   fsnotify_access(file);
+   add_rchar(current, ret);
+   }
+   inc_syscr(current);
+   return ret;
+}
+
 ssize_t kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
 {
mm_segment_t old_fs;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 21f126957c2cf..6441aaa25f8f2 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -3011,6 +3011,7 @@ extern int kernel_read_file_from_path_initns(const char 
*, void **, loff_t *, lo
 extern int kernel_read_file_from_fd(int, void **, loff_t *, loff_t,
enum kernel_read_file_id);
 extern ssize_t kernel_read(struct file *, void *, size_t, loff_t *);
+ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos);
 extern ssize_t kernel_write(struct file *, const void *, size_t, loff_t *);
 extern ssize_t __kernel_write(struct file *, const void *, size_t, loff_t *);
 extern struct file * open_exec(const char *);
-- 
2.26.2



[PATCH 07/14] fs: implement kernel_write using __kernel_write

2020-05-27 Thread Christoph Hellwig
Consolidate the two in-kernel write helpers to make upcoming changes
easier.  The only difference are the missing call to rw_verify_area
in kernel_write, and an access_ok check that doesn't make sense for
kernel buffers to start with.

Signed-off-by: Christoph Hellwig 
---
 fs/read_write.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index f0768313ea010..abb84391cfbc5 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -499,6 +499,7 @@ static ssize_t __vfs_write(struct file *file, const char 
__user *p,
return -EINVAL;
 }
 
+/* caller is responsible for file_start_write/file_end_write */
 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, 
loff_t *pos)
 {
mm_segment_t old_fs;
@@ -528,16 +529,16 @@ ssize_t __kernel_write(struct file *file, const void 
*buf, size_t count, loff_t
 ssize_t kernel_write(struct file *file, const void *buf, size_t count,
loff_t *pos)
 {
-   mm_segment_t old_fs;
-   ssize_t res;
+   ssize_t ret;
 
-   old_fs = get_fs();
-   set_fs(KERNEL_DS);
-   /* The cast to a user pointer is valid due to the set_fs() */
-   res = vfs_write(file, (__force const char __user *)buf, count, pos);
-   set_fs(old_fs);
+   ret = rw_verify_area(WRITE, file, pos, count);
+   if (ret)
+   return ret;
 
-   return res;
+   file_start_write(file);
+   ret =  __kernel_write(file, buf, count, pos);
+   file_end_write(file);
+   return ret;
 }
 EXPORT_SYMBOL(kernel_write);
 
-- 
2.26.2



[PATCH 06/14] fs: remove the call_{read,write}_iter functions

2020-05-27 Thread Christoph Hellwig
Just open coding the methods calls is a lot easier to follow.

Signed-off-by: Christoph Hellwig 
---
 drivers/block/loop.c  |  4 ++--
 drivers/target/target_core_file.c |  4 ++--
 fs/aio.c  |  4 ++--
 fs/io_uring.c |  4 ++--
 fs/read_write.c   | 12 ++--
 fs/splice.c   |  2 +-
 include/linux/fs.h| 12 
 7 files changed, 15 insertions(+), 27 deletions(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index da693e6a834e5..ad167050a4ec4 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -572,9 +572,9 @@ static int lo_rw_aio(struct loop_device *lo, struct 
loop_cmd *cmd,
kthread_associate_blkcg(cmd->css);
 
if (rw == WRITE)
-   ret = call_write_iter(file, &cmd->iocb, &iter);
+   ret = file->f_op->write_iter(&cmd->iocb, &iter);
else
-   ret = call_read_iter(file, &cmd->iocb, &iter);
+   ret = file->f_op->read_iter(&cmd->iocb, &iter);
 
lo_rw_aio_do_completion(cmd);
kthread_associate_blkcg(NULL);
diff --git a/drivers/target/target_core_file.c 
b/drivers/target/target_core_file.c
index 7143d03f0e027..79f0707877917 100644
--- a/drivers/target/target_core_file.c
+++ b/drivers/target/target_core_file.c
@@ -303,9 +303,9 @@ fd_execute_rw_aio(struct se_cmd *cmd, struct scatterlist 
*sgl, u32 sgl_nents,
aio_cmd->iocb.ki_flags |= IOCB_DSYNC;
 
if (is_write)
-   ret = call_write_iter(file, &aio_cmd->iocb, &iter);
+   ret = file->f_op->write_iter(&aio_cmd->iocb, &iter);
else
-   ret = call_read_iter(file, &aio_cmd->iocb, &iter);
+   ret = file->f_op->read_iter(&aio_cmd->iocb, &iter);
 
kfree(bvec);
 
diff --git a/fs/aio.c b/fs/aio.c
index 5f3d3d8149287..1ccc0efdc357d 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1540,7 +1540,7 @@ static int aio_read(struct kiocb *req, const struct iocb 
*iocb,
return ret;
ret = rw_verify_area(READ, file, &req->ki_pos, iov_iter_count(&iter));
if (!ret)
-   aio_rw_done(req, call_read_iter(file, req, &iter));
+   aio_rw_done(req, file->f_op->read_iter(req, &iter));
kfree(iovec);
return ret;
 }
@@ -1580,7 +1580,7 @@ static int aio_write(struct kiocb *req, const struct iocb 
*iocb,
__sb_writers_release(file_inode(file)->i_sb, 
SB_FREEZE_WRITE);
}
req->ki_flags |= IOCB_WRITE;
-   aio_rw_done(req, call_write_iter(file, req, &iter));
+   aio_rw_done(req, file->f_op->write_iter(req, &iter));
}
kfree(iovec);
return ret;
diff --git a/fs/io_uring.c b/fs/io_uring.c
index bb25e3997d418..f4b808231af0b 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2579,7 +2579,7 @@ static int io_read(struct io_kiocb *req, bool 
force_nonblock)
ssize_t ret2;
 
if (req->file->f_op->read_iter)
-   ret2 = call_read_iter(req->file, kiocb, &iter);
+   ret2 = req->file->f_op->read_iter(kiocb, &iter);
else
ret2 = loop_rw_iter(READ, req->file, kiocb, &iter);
 
@@ -2694,7 +2694,7 @@ static int io_write(struct io_kiocb *req, bool 
force_nonblock)
current->signal->rlim[RLIMIT_FSIZE].rlim_cur = 
req->fsize;
 
if (req->file->f_op->write_iter)
-   ret2 = call_write_iter(req->file, kiocb, &iter);
+   ret2 = req->file->f_op->write_iter(kiocb, &iter);
else
ret2 = loop_rw_iter(WRITE, req->file, kiocb, &iter);
 
diff --git a/fs/read_write.c b/fs/read_write.c
index 76be155ad9824..f0768313ea010 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -412,7 +412,7 @@ static ssize_t new_sync_read(struct file *filp, char __user 
*buf, size_t len, lo
kiocb.ki_pos = (ppos ? *ppos : 0);
iov_iter_init(&iter, READ, &iov, 1, len);
 
-   ret = call_read_iter(filp, &kiocb, &iter);
+   ret = filp->f_op->read_iter(&kiocb, &iter);
BUG_ON(ret == -EIOCBQUEUED);
if (ppos)
*ppos = kiocb.ki_pos;
@@ -481,7 +481,7 @@ static ssize_t new_sync_write(struct file *filp, const char 
__user *buf, size_t
kiocb.ki_pos = (ppos ? *ppos : 0);
iov_iter_init(&iter, WRITE, &iov, 1, len);
 
-   ret = call_write_iter(filp, &kiocb, &iter);
+   ret = filp->f_op->write_iter(&kiocb, &iter);
BUG_ON(ret == -EIOCBQUEUED);
if (ret > 0 && ppos)
*ppos = kiocb.ki_pos;
@@ -690,9 +690,9 @@ static ssize_t do_iter_readv_writev(struct file *filp, 
struct iov_iter *iter,
kiocb.ki_pos = (ppos ? *ppos : 0);
 
if (type == READ)
-   ret = call_read_iter(filp, &kiocb, iter);
+   ret = filp->f_op->read_iter(&kiocb, iter);
  

[PATCH 14/14] fs: don't change the address limit for ->read_iter in __kernel_read

2020-05-27 Thread Christoph Hellwig
If we read to a file that implements ->read_iter there is no need
to change the address limit if we send a kvec down.  Implement that
case, and prefer it over using plain ->read with a changed address
limit if available.

Signed-off-by: Christoph Hellwig 
---
 fs/read_write.c | 24 +---
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index 46ddfce17e839..c93acbd8bf5a3 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -421,7 +421,6 @@ static ssize_t new_sync_read(struct file *filp, char __user 
*buf, size_t len, lo
 
 ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
 {
-   mm_segment_t old_fs = get_fs();
ssize_t ret;
 
if (!(file->f_mode & FMODE_CAN_READ))
@@ -429,14 +428,25 @@ ssize_t __kernel_read(struct file *file, void *buf, 
size_t count, loff_t *pos)
 
if (count > MAX_RW_COUNT)
count =  MAX_RW_COUNT;
-   set_fs(KERNEL_DS);
-   if (file->f_op->read)
+   if (file->f_op->read_iter) {
+   struct kvec iov = { .iov_base = buf, .iov_len = count };
+   struct kiocb kiocb;
+   struct iov_iter iter;
+
+   init_sync_kiocb(&kiocb, file);
+   kiocb.ki_pos = *pos;
+   iov_iter_kvec(&iter, READ, &iov, 1, count);
+   ret = file->f_op->read_iter(&kiocb, &iter);
+   *pos = kiocb.ki_pos;
+   } else if (file->f_op->read) {
+   mm_segment_t old_fs = get_fs();
+
+   set_fs(KERNEL_DS);
ret = file->f_op->read(file, (void __user *)buf, count, pos);
-   else if (file->f_op->read_iter)
-   ret = new_sync_read(file, (void __user *)buf, count, pos);
-   else
+   set_fs(old_fs);
+   } else {
ret = -EINVAL;
-   set_fs(old_fs);
+   }
if (ret > 0) {
fsnotify_access(file);
add_rchar(current, ret);
-- 
2.26.2



[PATCH 11/14] integrity/ima: switch to using __kernel_read

2020-05-27 Thread Christoph Hellwig
__kernel_read has a bunch of additional sanity checks, and this moves
the set_fs out of non-core code.

Signed-off-by: Christoph Hellwig 
---
 security/integrity/iint.c | 14 +-
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/security/integrity/iint.c b/security/integrity/iint.c
index e12c4900510f6..1d20003243c3f 100644
--- a/security/integrity/iint.c
+++ b/security/integrity/iint.c
@@ -188,19 +188,7 @@ DEFINE_LSM(integrity) = {
 int integrity_kernel_read(struct file *file, loff_t offset,
  void *addr, unsigned long count)
 {
-   mm_segment_t old_fs;
-   char __user *buf = (char __user *)addr;
-   ssize_t ret;
-
-   if (!(file->f_mode & FMODE_READ))
-   return -EBADF;
-
-   old_fs = get_fs();
-   set_fs(KERNEL_DS);
-   ret = __vfs_read(file, buf, count, &offset);
-   set_fs(old_fs);
-
-   return ret;
+   return __kernel_read(file, addr, count, &offset);
 }
 
 /*
-- 
2.26.2



[PATCH v2] perf jvmti: Remove redundant jitdump line table entries

2020-05-27 Thread Nick Gasson
For each PC/BCI pair in the JVMTI compiler inlining record table, the
jitdump plugin emits debug line table entries for every source line in
the method preceding that BCI. Instead only emit one source line per
PC/BCI pair. Reported by Ian Rogers. This reduces the .dump size for
SPECjbb from ~230MB to ~40MB.

Signed-off-by: Nick Gasson 
---
Changes in v2:
- Split the unrelated DWARF debug fix into a separate patch
- Added a comment about the use of c->methods

 tools/perf/jvmti/libjvmti.c | 78 -
 1 file changed, 33 insertions(+), 45 deletions(-)

diff --git a/tools/perf/jvmti/libjvmti.c b/tools/perf/jvmti/libjvmti.c
index c5d30834a64c..fcca275e5bf9 100644
--- a/tools/perf/jvmti/libjvmti.c
+++ b/tools/perf/jvmti/libjvmti.c
@@ -32,38 +32,41 @@ static void print_error(jvmtiEnv *jvmti, const char *msg, 
jvmtiError ret)
 
 #ifdef HAVE_JVMTI_CMLR
 static jvmtiError
-do_get_line_numbers(jvmtiEnv *jvmti, void *pc, jmethodID m, jint bci,
-   jvmti_line_info_t *tab, jint *nr)
+do_get_line_number(jvmtiEnv *jvmti, void *pc, jmethodID m, jint bci,
+  jvmti_line_info_t *tab)
 {
-   jint i, lines = 0;
-   jint nr_lines = 0;
+   jint i, nr_lines = 0;
jvmtiLineNumberEntry *loc_tab = NULL;
jvmtiError ret;
+   jint src_line = -1;
 
ret = (*jvmti)->GetLineNumberTable(jvmti, m, &nr_lines, &loc_tab);
if (ret == JVMTI_ERROR_ABSENT_INFORMATION || ret == 
JVMTI_ERROR_NATIVE_METHOD) {
/* No debug information for this method */
-   *nr = 0;
-   return JVMTI_ERROR_NONE;
+   return ret;
} else if (ret != JVMTI_ERROR_NONE) {
print_error(jvmti, "GetLineNumberTable", ret);
return ret;
}
 
-   for (i = 0; i < nr_lines; i++) {
-   if (loc_tab[i].start_location < bci) {
-   tab[lines].pc = (unsigned long)pc;
-   tab[lines].line_number = loc_tab[i].line_number;
-   tab[lines].discrim = 0; /* not yet used */
-   tab[lines].methodID = m;
-   lines++;
-   } else {
-   break;
-   }
+   for (i = 0; i < nr_lines && loc_tab[i].start_location <= bci; i++) {
+   src_line = i;
+   }
+
+   if (src_line != -1) {
+   tab->pc = (unsigned long)pc;
+   tab->line_number = loc_tab[src_line].line_number;
+   tab->discrim = 0; /* not yet used */
+   tab->methodID = m;
+
+   ret = JVMTI_ERROR_NONE;
+   } else {
+   ret = JVMTI_ERROR_ABSENT_INFORMATION;
}
+
(*jvmti)->Deallocate(jvmti, (unsigned char *)loc_tab);
-   *nr = lines;
-   return JVMTI_ERROR_NONE;
+
+   return ret;
 }
 
 static jvmtiError
@@ -71,9 +74,8 @@ get_line_numbers(jvmtiEnv *jvmti, const void *compile_info, 
jvmti_line_info_t **
 {
const jvmtiCompiledMethodLoadRecordHeader *hdr;
jvmtiCompiledMethodLoadInlineRecord *rec;
-   jvmtiLineNumberEntry *lne = NULL;
PCStackInfo *c;
-   jint nr, ret;
+   jint ret;
int nr_total = 0;
int i, lines_total = 0;
 
@@ -86,24 +88,7 @@ get_line_numbers(jvmtiEnv *jvmti, const void *compile_info, 
jvmti_line_info_t **
for (hdr = compile_info; hdr != NULL; hdr = hdr->next) {
if (hdr->kind == JVMTI_CMLR_INLINE_INFO) {
rec = (jvmtiCompiledMethodLoadInlineRecord *)hdr;
-   for (i = 0; i < rec->numpcs; i++) {
-   c = rec->pcinfo + i;
-   nr = 0;
-   /*
-* unfortunately, need a tab to get the number 
of lines!
-*/
-   ret = (*jvmti)->GetLineNumberTable(jvmti, 
c->methods[0], &nr, &lne);
-   if (ret == JVMTI_ERROR_NONE) {
-   /* free what was allocated for nothing 
*/
-   (*jvmti)->Deallocate(jvmti, (unsigned 
char *)lne);
-   nr_total += (int)nr;
-   } else if (ret == 
JVMTI_ERROR_ABSENT_INFORMATION ||
-  ret == JVMTI_ERROR_NATIVE_METHOD) {
-   /* No debug information for this method 
*/
-   } else {
-   print_error(jvmti, 
"GetLineNumberTable", ret);
-   }
-   }
+   nr_total += rec->numpcs;
}
}
 
@@ -122,14 +107,17 @@ get_line_numbers(jvmtiEnv *jvmti, const void 
*compile_info, jvmti_line_info_t **
rec = (jvmtiCompiledMethodLoadInlineRecord *)hdr;
for (i

[PATCH 13/14] fs: remove __vfs_read

2020-05-27 Thread Christoph Hellwig
Fold it into the two callers.

Signed-off-by: Christoph Hellwig 
---
 fs/read_write.c| 43 +--
 include/linux/fs.h |  1 -
 2 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index 4e19152a7efe0..46ddfce17e839 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -419,17 +419,6 @@ static ssize_t new_sync_read(struct file *filp, char 
__user *buf, size_t len, lo
return ret;
 }
 
-ssize_t __vfs_read(struct file *file, char __user *buf, size_t count,
-  loff_t *pos)
-{
-   if (file->f_op->read)
-   return file->f_op->read(file, buf, count, pos);
-   else if (file->f_op->read_iter)
-   return new_sync_read(file, buf, count, pos);
-   else
-   return -EINVAL;
-}
-
 ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
 {
mm_segment_t old_fs = get_fs();
@@ -441,7 +430,12 @@ ssize_t __kernel_read(struct file *file, void *buf, size_t 
count, loff_t *pos)
if (count > MAX_RW_COUNT)
count =  MAX_RW_COUNT;
set_fs(KERNEL_DS);
-   ret = __vfs_read(file, (void __user *)buf, count, pos);
+   if (file->f_op->read)
+   ret = file->f_op->read(file, (void __user *)buf, count, pos);
+   else if (file->f_op->read_iter)
+   ret = new_sync_read(file, (void __user *)buf, count, pos);
+   else
+   ret = -EINVAL;
set_fs(old_fs);
if (ret > 0) {
fsnotify_access(file);
@@ -474,17 +468,22 @@ ssize_t vfs_read(struct file *file, char __user *buf, 
size_t count, loff_t *pos)
return -EFAULT;
 
ret = rw_verify_area(READ, file, pos, count);
-   if (!ret) {
-   if (count > MAX_RW_COUNT)
-   count =  MAX_RW_COUNT;
-   ret = __vfs_read(file, buf, count, pos);
-   if (ret > 0) {
-   fsnotify_access(file);
-   add_rchar(current, ret);
-   }
-   inc_syscr(current);
-   }
+   if (ret)
+   return ret;
+   if (count > MAX_RW_COUNT)
+   count =  MAX_RW_COUNT;
 
+   if (file->f_op->read)
+   ret = file->f_op->read(file, buf, count, pos);
+   else if (file->f_op->read_iter)
+   ret = new_sync_read(file, buf, count, pos);
+   else
+   ret = -EINVAL;
+   if (ret > 0) {
+   fsnotify_access(file);
+   add_rchar(current, ret);
+   }
+   inc_syscr(current);
return ret;
 }
 
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 6441aaa25f8f2..4c10a07a36178 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1905,7 +1905,6 @@ ssize_t rw_copy_check_uvector(int type, const struct 
iovec __user * uvector,
  struct iovec *fast_pointer,
  struct iovec **ret_pointer);
 
-extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
 extern ssize_t vfs_readv(struct file *, const struct iovec __user *,
-- 
2.26.2



[PATCH 12/14] fs: implement kernel_read using __kernel_read

2020-05-27 Thread Christoph Hellwig
Consolidate the two in-kernel read helpers to make upcoming changes
easier.  The only difference are the missing call to rw_verify_area
in kernel_read, and an access_ok check that doesn't make sense for
kernel buffers to start with.

Signed-off-by: Christoph Hellwig 
---
 fs/read_write.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index bd12af8a895c8..4e19152a7efe0 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -453,15 +453,12 @@ ssize_t __kernel_read(struct file *file, void *buf, 
size_t count, loff_t *pos)
 
 ssize_t kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
 {
-   mm_segment_t old_fs;
-   ssize_t result;
+   ssize_t ret;
 
-   old_fs = get_fs();
-   set_fs(KERNEL_DS);
-   /* The cast to a user pointer is valid due to the set_fs() */
-   result = vfs_read(file, (void __user *)buf, count, pos);
-   set_fs(old_fs);
-   return result;
+   ret = rw_verify_area(READ, file, pos, count);
+   if (ret)
+   return ret;
+   return __kernel_read(file, buf, count, pos);
 }
 EXPORT_SYMBOL(kernel_read);
 
-- 
2.26.2



[PATCH 05/14] fs: check FMODE_WRITE in __kernel_write

2020-05-27 Thread Christoph Hellwig
We still need to check if the fѕ is open write, even for the low-level
helper.

Signed-off-by: Christoph Hellwig 
---
 fs/read_write.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/read_write.c b/fs/read_write.c
index 2c601d853ff3d..76be155ad9824 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -505,6 +505,8 @@ ssize_t __kernel_write(struct file *file, const void *buf, 
size_t count, loff_t
const char __user *p;
ssize_t ret;
 
+   if (!(file->f_mode & FMODE_WRITE))
+   return -EBADF;
if (!(file->f_mode & FMODE_CAN_WRITE))
return -EINVAL;
 
-- 
2.26.2



[PATCH 03/14] bpfilter: switch to kernel_write

2020-05-27 Thread Christoph Hellwig
While pipes don't really need sb_writers projection, __kernel_write is an
interface better kept private, and the additional rw_verify_area does not
hurt here.

Signed-off-by: Christoph Hellwig 
---
 net/bpfilter/bpfilter_kern.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/bpfilter/bpfilter_kern.c b/net/bpfilter/bpfilter_kern.c
index c0f0990f30b60..1905e01c3aa9a 100644
--- a/net/bpfilter/bpfilter_kern.c
+++ b/net/bpfilter/bpfilter_kern.c
@@ -50,7 +50,7 @@ static int __bpfilter_process_sockopt(struct sock *sk, int 
optname,
req.len = optlen;
if (!bpfilter_ops.info.pid)
goto out;
-   n = __kernel_write(bpfilter_ops.info.pipe_to_umh, &req, sizeof(req),
+   n = kernel_write(bpfilter_ops.info.pipe_to_umh, &req, sizeof(req),
   &pos);
if (n != sizeof(req)) {
pr_err("write fail %zd\n", n);
-- 
2.26.2



[PATCH 09/14] fs: don't change the address limit for ->write_iter in __kernel_write

2020-05-27 Thread Christoph Hellwig
If we write to a file that implements ->write_iter there is no need
to change the address limit if we send a kvec down.  Implement that
case, and prefer it over using plain ->write with a changed address
limit if available.

Signed-off-by: Christoph Hellwig 
---
 fs/read_write.c | 34 ++
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index 3bcb084f160de..8cfca5f8fc3ce 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -489,10 +489,9 @@ static ssize_t new_sync_write(struct file *filp, const 
char __user *buf, size_t
 }
 
 /* caller is responsible for file_start_write/file_end_write */
-ssize_t __kernel_write(struct file *file, const void *buf, size_t count, 
loff_t *pos)
+ssize_t __kernel_write(struct file *file, const void *buf, size_t count,
+   loff_t *pos)
 {
-   mm_segment_t old_fs;
-   const char __user *p;
ssize_t ret;
 
if (!(file->f_mode & FMODE_WRITE))
@@ -500,18 +499,29 @@ ssize_t __kernel_write(struct file *file, const void 
*buf, size_t count, loff_t
if (!(file->f_mode & FMODE_CAN_WRITE))
return -EINVAL;
 
-   old_fs = get_fs();
-   set_fs(KERNEL_DS);
-   p = (__force const char __user *)buf;
if (count > MAX_RW_COUNT)
count =  MAX_RW_COUNT;
-   if (file->f_op->write)
-   ret = file->f_op->write(file, p, count, pos);
-   else if (file->f_op->write_iter)
-   ret = new_sync_write(file, p, count, pos);
-   else
+   if (file->f_op->write_iter) {
+   struct kvec iov = { .iov_base = (void *)buf, .iov_len = count };
+   struct kiocb kiocb;
+   struct iov_iter iter;
+
+   init_sync_kiocb(&kiocb, file);
+   kiocb.ki_pos = *pos;
+   iov_iter_kvec(&iter, WRITE, &iov, 1, count);
+   ret = file->f_op->write_iter(&kiocb, &iter);
+   if (ret > 0)
+   *pos = kiocb.ki_pos;
+   } else if (file->f_op->write) {
+   mm_segment_t old_fs = get_fs();
+
+   set_fs(KERNEL_DS);
+   ret = file->f_op->write(file, (__force const char __user *)buf,
+   count, pos);
+   set_fs(old_fs);
+   } else {
ret = -EINVAL;
-   set_fs(old_fs);
+   }
if (ret > 0) {
fsnotify_modify(file);
add_wchar(current, ret);
-- 
2.26.2



[PATCH 08/14] fs: remove __vfs_write

2020-05-27 Thread Christoph Hellwig
Fold it into the two callers.

Signed-off-by: Christoph Hellwig 
---
 fs/read_write.c | 46 ++
 1 file changed, 22 insertions(+), 24 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index abb84391cfbc5..3bcb084f160de 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -488,17 +488,6 @@ static ssize_t new_sync_write(struct file *filp, const 
char __user *buf, size_t
return ret;
 }
 
-static ssize_t __vfs_write(struct file *file, const char __user *p,
-  size_t count, loff_t *pos)
-{
-   if (file->f_op->write)
-   return file->f_op->write(file, p, count, pos);
-   else if (file->f_op->write_iter)
-   return new_sync_write(file, p, count, pos);
-   else
-   return -EINVAL;
-}
-
 /* caller is responsible for file_start_write/file_end_write */
 ssize_t __kernel_write(struct file *file, const void *buf, size_t count, 
loff_t *pos)
 {
@@ -516,7 +505,12 @@ ssize_t __kernel_write(struct file *file, const void *buf, 
size_t count, loff_t
p = (__force const char __user *)buf;
if (count > MAX_RW_COUNT)
count =  MAX_RW_COUNT;
-   ret = __vfs_write(file, p, count, pos);
+   if (file->f_op->write)
+   ret = file->f_op->write(file, p, count, pos);
+   else if (file->f_op->write_iter)
+   ret = new_sync_write(file, p, count, pos);
+   else
+   ret = -EINVAL;
set_fs(old_fs);
if (ret > 0) {
fsnotify_modify(file);
@@ -554,19 +548,23 @@ ssize_t vfs_write(struct file *file, const char __user 
*buf, size_t count, loff_
return -EFAULT;
 
ret = rw_verify_area(WRITE, file, pos, count);
-   if (!ret) {
-   if (count > MAX_RW_COUNT)
-   count =  MAX_RW_COUNT;
-   file_start_write(file);
-   ret = __vfs_write(file, buf, count, pos);
-   if (ret > 0) {
-   fsnotify_modify(file);
-   add_wchar(current, ret);
-   }
-   inc_syscw(current);
-   file_end_write(file);
+   if (ret)
+   return ret;
+   if (count > MAX_RW_COUNT)
+   count =  MAX_RW_COUNT;
+   file_start_write(file);
+   if (file->f_op->write)
+   ret = file->f_op->write(file, buf, count, pos);
+   else if (file->f_op->write_iter)
+   ret = new_sync_write(file, buf, count, pos);
+   else
+   ret = -EINVAL;
+   if (ret > 0) {
+   fsnotify_modify(file);
+   add_wchar(current, ret);
}
-
+   inc_syscw(current);
+   file_end_write(file);
return ret;
 }
 
-- 
2.26.2



[PATCH 04/14] fs: unexport __kernel_write

2020-05-27 Thread Christoph Hellwig
This is a very special interface that skips sb_writes protection, and not
used by modules anymore.

Signed-off-by: Christoph Hellwig 
---
 fs/read_write.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index bbfa9b12b15eb..2c601d853ff3d 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -522,7 +522,6 @@ ssize_t __kernel_write(struct file *file, const void *buf, 
size_t count, loff_t
inc_syscw(current);
return ret;
 }
-EXPORT_SYMBOL(__kernel_write);
 
 ssize_t kernel_write(struct file *file, const void *buf, size_t count,
loff_t *pos)
-- 
2.26.2



clean up kernel_{read,write} & friends v2

2020-05-27 Thread Christoph Hellwig
Hi Al,

this series fixes a few issues and cleans up the helpers that read from
or write to kernel space buffers, and ensures that we don't change the
address limit if we are using the ->read_iter and ->write_iter methods
that don't need the changed address limit.

Changes since v2:
 - picked up a few ACKs

Changes since v1:
 - __kernel_write must not take sb_writers
 - unexport __kernel_write


[PATCH 02/14] autofs: switch to kernel_write

2020-05-27 Thread Christoph Hellwig
While pipes don't really need sb_writers projection, __kernel_write is an
interface better kept private, and the additional rw_verify_area does not
hurt here.

Signed-off-by: Christoph Hellwig 
Acked-by: Ian Kent 
---
 fs/autofs/waitq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/autofs/waitq.c b/fs/autofs/waitq.c
index b04c528b19d34..74c886f7c51cb 100644
--- a/fs/autofs/waitq.c
+++ b/fs/autofs/waitq.c
@@ -53,7 +53,7 @@ static int autofs_write(struct autofs_sb_info *sbi,
 
mutex_lock(&sbi->pipe_mutex);
while (bytes) {
-   wr = __kernel_write(file, data, bytes, &file->f_pos);
+   wr = kernel_write(file, data, bytes, &file->f_pos);
if (wr <= 0)
break;
data += wr;
-- 
2.26.2



[tip:WIP.core/rcu] BUILD SUCCESS 07325d4a90d2d84de45cc07b134fd0f023dbb971

2020-05-27 Thread kbuild test robot
tree/branch: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git  
WIP.core/rcu
branch HEAD: 07325d4a90d2d84de45cc07b134fd0f023dbb971  rcu: Provide 
rcu_irq_exit_check_preempt()

elapsed time: 2186m

configs tested: 97
configs skipped: 1

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

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

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


[PATCH v4] bluetooth: hci_qca: Fix qca6390 enable failure after warm reboot

2020-05-27 Thread Zijun Hu
Warm reboot can not restore qca6390 controller baudrate
to default due to lack of controllable BT_EN pin or power
supply, so fails to download firmware after warm reboot.

Fixed by sending EDL_SOC_RESET VSC to reset controller
within added device shutdown implementation.

Signed-off-by: Zijun Hu 
---
 drivers/bluetooth/hci_qca.c | 33 +
 1 file changed, 33 insertions(+)

diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
index e4a6823..8e03bfe 100644
--- a/drivers/bluetooth/hci_qca.c
+++ b/drivers/bluetooth/hci_qca.c
@@ -1975,6 +1975,38 @@ static void qca_serdev_remove(struct serdev_device 
*serdev)
hci_uart_unregister_device(&qcadev->serdev_hu);
 }
 
+static void qca_serdev_shutdown(struct device *dev)
+{
+   int ret;
+   int timeout = msecs_to_jiffies(CMD_TRANS_TIMEOUT_MS);
+   struct serdev_device *serdev = to_serdev_device(dev);
+   struct qca_serdev *qcadev = serdev_device_get_drvdata(serdev);
+   const u8 ibs_wake_cmd[] = { 0xFD };
+   const u8 edl_reset_soc_cmd[] = { 0x01, 0x00, 0xFC, 0x01, 0x05 };
+
+   if (qcadev->btsoc_type == QCA_QCA6390) {
+   serdev_device_write_flush(serdev);
+   ret = serdev_device_write_buf(serdev,
+   ibs_wake_cmd, sizeof(ibs_wake_cmd));
+   if (ret < 0) {
+   BT_ERR("QCA send IBS_WAKE_IND error: %d", ret);
+   return;
+   }
+   serdev_device_wait_until_sent(serdev, timeout);
+   usleep_range(8000, 1);
+
+   serdev_device_write_flush(serdev);
+   ret = serdev_device_write_buf(serdev,
+   edl_reset_soc_cmd, sizeof(edl_reset_soc_cmd));
+   if (ret < 0) {
+   BT_ERR("QCA send EDL_RESET_REQ error: %d", ret);
+   return;
+   }
+   serdev_device_wait_until_sent(serdev, timeout);
+   usleep_range(8000, 1);
+   }
+}
+
 static int __maybe_unused qca_suspend(struct device *dev)
 {
struct hci_dev *hdev = container_of(dev, struct hci_dev, dev);
@@ -2100,6 +2132,7 @@ static struct serdev_device_driver qca_serdev_driver = {
.name = "hci_uart_qca",
.of_match_table = of_match_ptr(qca_bluetooth_of_match),
.acpi_match_table = ACPI_PTR(qca_bluetooth_acpi_match),
+   .shutdown = qca_serdev_shutdown,
.pm = &qca_pm_ops,
},
 };
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a 
Linux Foundation Collaborative Project



Re: [Nouveau] [PATCH] nouveau: add fbdev dependency

2020-05-27 Thread Dave Airlie
On Thu, 28 May 2020 at 00:36, Arnd Bergmann  wrote:
>
> On Wed, May 27, 2020 at 4:05 PM Ilia Mirkin  wrote:
> >
> > Isn't this already fixed by
> >
> > https://cgit.freedesktop.org/drm/drm/commit/?id=7dbbdd37f2ae7dd4175ba3f86f4335c463b18403
>
> Ok, I see that fixes the link error, but I when I created my fix, that did
> not seem like the correct solution because it reverts part of the original
> patch without reverting the rest of it. Unfortunately there was no
> changelog text in the first patch to explain why this is safe.

No it doesn't, I think you missed the pci in API name.

The initial behaviour doesn't use the pci version of the API, the
replacement did, and the fix used the drm wrapper around the pci one.

So this patch isn't necessary now that I've fixed it the other way,

Thanks,
Dave.


Re: [PATCH v30 07/20] x86/sgx: Enumerate and track EPC sections

2020-05-27 Thread Jarkko Sakkinen
On Thu, May 28, 2020 at 08:25:43AM +0300, Jarkko Sakkinen wrote:
> On Tue, May 26, 2020 at 08:56:14PM -0700, Sean Christopherson wrote:
> > On Mon, May 25, 2020 at 11:23:04AM +0200, Borislav Petkov wrote:
> > > On Fri, May 15, 2020 at 03:43:57AM +0300, Jarkko Sakkinen wrote:
> > > > +struct sgx_epc_section sgx_epc_sections[SGX_MAX_EPC_SECTIONS];
> > > > +int sgx_nr_epc_sections;
> > > 
> > > We have become very averse against global stuff. What is going to use
> > > those, only sgx code I assume...?
> > 
> > Yes, only SGX code.  The reclaim/swap code needs access to the sections,
> > and that code is in a different file, reclaim.c.  I don't have a super
> > strong objection to sucking reclaim.c into main.c, but I'm somewhat
> > indifferent on code organization as a whole.  Jarkko likely has a stronger
> > opinion.
> 
> I'll change it.
> 
> It's not quite as easy as just "sucking the file in". All the commits
> that touch the file need to be reworked:
> 
> $ git --no-pager log --format="%H %s" arch/x86/kernel/cpu/sgx/reclaim.c
> 5aeca6dabf767e9350ee3188ba25ceb21f3162b4 x86/sgx: Add a page reclaimer
> de9b1088959f36ffdaf43a49bfea1c7f9f81cac7 x86/sgx: Linux Enclave Driver
> 08d8fcb74fe268059ee58fcc2a0833b244e1f22a x86/sgx: Enumerate and track EPC 
> sections

Not that I haven't done this a lot last few years. A proven approach
is to do it in two "git rebase -i mainline/master" sweeps:

1. For each commit, remove reclaim.c entry from the Makefile and import
   reclaim.c contents to main.c.
2. For each commit, delete reclaim.c.

I've tried quite a few different angles and this what I've converged
into. Very hard to hit messy into messy merge conflicts.

/Jarkko


Re: [PATCH v3 5/6] bus: Add Baikal-T1 APB-bus driver

2020-05-27 Thread kbuild test robot
Hi Serge,

I love your patch! Yet something to improve:

[auto build test ERROR on robh/for-next]
[also build test ERROR on char-misc/char-misc-testing staging/staging-testing 
linus/master v5.7-rc7 next-20200526]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:
https://github.com/0day-ci/linux/commits/Serge-Semin/bus-memory-Add-Baikal-T1-SoC-APB-AXI-L2-drivers/20200526-210837
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
config: sparc-allyesconfig (attached as .config)
compiler: sparc64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross 
ARCH=sparc 

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

All error/warnings (new ones prefixed by >>, old ones prefixed by <<):

drivers/bus/bt1-apb.c: In function 'inject_error_store':
drivers/bus/bt1-apb.c:329:3: error: implicit declaration of function 'readl' 
[-Werror=implicit-function-declaration]
329 |   readl(apb->res);
|   ^
In file included from include/linux/kobject.h:20,
from include/linux/module.h:20,
from drivers/bus/bt1-apb.c:12:
drivers/bus/bt1-apb.c: At top level:
>> drivers/bus/bt1-apb.c:338:23: error: initialization of 'ssize_t (*)(struct 
>> device *, struct device_attribute *, char *)' {aka 'long int (*)(struct 
>> device *, struct device_attribute *, char *)'} from incompatible pointer 
>> type 'int (*)(struct device *, struct device_attribute *, char *)' 
>> [-Werror=incompatible-pointer-types]
338 | static DEVICE_ATTR_RW(inject_error);
|   ^~~~
include/linux/sysfs.h:104:10: note: in definition of macro '__ATTR'
104 |  .show = _show,   |  ^
include/linux/device.h:130:45: note: in expansion of macro '__ATTR_RW'
130 |  struct device_attribute dev_attr_##_name = __ATTR_RW(_name)
| ^
>> drivers/bus/bt1-apb.c:338:8: note: in expansion of macro 'DEVICE_ATTR_RW'
338 | static DEVICE_ATTR_RW(inject_error);
|^~
drivers/bus/bt1-apb.c:338:23: note: (near initialization for 
'dev_attr_inject_error.show')
338 | static DEVICE_ATTR_RW(inject_error);
|   ^~~~
include/linux/sysfs.h:104:10: note: in definition of macro '__ATTR'
104 |  .show = _show,   |  ^
include/linux/device.h:130:45: note: in expansion of macro '__ATTR_RW'
130 |  struct device_attribute dev_attr_##_name = __ATTR_RW(_name)
| ^
>> drivers/bus/bt1-apb.c:338:8: note: in expansion of macro 'DEVICE_ATTR_RW'
338 | static DEVICE_ATTR_RW(inject_error);
|^~
>> drivers/bus/bt1-apb.c:338:23: error: initialization of 'ssize_t (*)(struct 
>> device *, struct device_attribute *, const char *, size_t)' {aka 'long int 
>> (*)(struct device *, struct device_attribute *, const char *, long unsigned 
>> int)'} from incompatible pointer type 'int (*)(struct device *, struct 
>> device_attribute *, const char *, size_t)' {aka 'int (*)(struct device *, 
>> struct device_attribute *, const char *, long unsigned int)'} 
>> [-Werror=incompatible-pointer-types]
338 | static DEVICE_ATTR_RW(inject_error);
|   ^~~~
include/linux/sysfs.h:105:11: note: in definition of macro '__ATTR'
105 |  .store = _store,   |   ^~
include/linux/device.h:130:45: note: in expansion of macro '__ATTR_RW'
130 |  struct device_attribute dev_attr_##_name = __ATTR_RW(_name)
| ^
>> drivers/bus/bt1-apb.c:338:8: note: in expansion of macro 'DEVICE_ATTR_RW'
338 | static DEVICE_ATTR_RW(inject_error);
|^~
drivers/bus/bt1-apb.c:338:23: note: (near initialization for 
'dev_attr_inject_error.store')
338 | static DEVICE_ATTR_RW(inject_error);
|   ^~~~
include/linux/sysfs.h:105:11: note: in definition of macro '__ATTR'
105 |  .store = _store,   |   ^~
include/linux/device.h:130:45: note: in expansion of macro '__ATTR_RW'
130 |  struct device_attribute dev_attr_##_name = __ATTR_RW(_name)
| ^
>> drivers/bus/bt1-apb.c:338:8: note: in expansion of macro 'DEVICE_ATTR_RW'
338 | static DEVICE_ATTR_RW(inject_error);
|^~
cc1: some warnings being treated as errors

vim +338 drivers/bus/bt1-apb.c

   317  
   318  static int inject_error_store(struct device *dev,
   319struct device_attribute *attr,
   320 

Re: [PATCH -V3] swap: Reduce lock contention on swap cache from swap slots allocation

2020-05-27 Thread Huang, Ying
Daniel Jordan  writes:

> On Mon, May 25, 2020 at 08:26:48AM +0800, Huang Ying wrote:
>> diff --git a/mm/swapfile.c b/mm/swapfile.c
>> index 423c234aca15..0abd93d2a4fc 100644
>> --- a/mm/swapfile.c
>> +++ b/mm/swapfile.c
>> @@ -615,7 +615,8 @@ static bool scan_swap_map_try_ssd_cluster(struct 
>> swap_info_struct *si,
>>   * discarding, do discard now and reclaim them
>>   */
>>  swap_do_scheduled_discard(si);
>> -*scan_base = *offset = si->cluster_next;
>> +*scan_base = this_cpu_read(*si->cluster_next_cpu);
>> +*offset = *scan_base;
>>  goto new_cluster;
>
> Why is this done?  As far as I can tell, the values always get overwritten at
> the end of the function with tmp and tmp isn't derived from them.  Seems
> ebc2a1a69111 moved some logic that used to make sense but doesn't have any
> effect now.

If we fail to allocate from cluster, "scan_base" and "offset" will not
be overridden.  And "cluster_next" or "cluster_next_cpu" may be changed
in swap_do_scheduled_discard(), because the lock is released and
re-acquired there.

The code may not have much value.  And you may think that it's better to
remove it.  But that should be in another patch.

>>  } else
>>  return false;
>> @@ -721,6 +722,34 @@ static void swap_range_free(struct swap_info_struct 
>> *si, unsigned long offset,
>>  }
>>  }
>>  
>> +static void set_cluster_next(struct swap_info_struct *si, unsigned long 
>> next)
>> +{
>> +unsigned long prev;
>> +
>> +if (!(si->flags & SWP_SOLIDSTATE)) {
>> +si->cluster_next = next;
>> +return;
>> +}
>> +
>> +prev = this_cpu_read(*si->cluster_next_cpu);
>> +/*
>> + * Cross the swap address space size aligned trunk, choose
>> + * another trunk randomly to avoid lock contention on swap
>> + * address space if possible.
>> + */
>> +if ((prev >> SWAP_ADDRESS_SPACE_SHIFT) !=
>> +(next >> SWAP_ADDRESS_SPACE_SHIFT)) {
>> +/* No free swap slots available */
>> +if (si->highest_bit <= si->lowest_bit)
>> +return;
>> +next = si->lowest_bit +
>> +prandom_u32_max(si->highest_bit - si->lowest_bit + 1);
>> +next = ALIGN(next, SWAP_ADDRESS_SPACE_PAGES);
>> +next = max_t(unsigned int, next, si->lowest_bit);
>
> next is always greater than lowest_bit because it's aligned up.  I think the
> intent of the max_t line is to handle when next is aligned outside the valid
> range, so it'd have to be ALIGN_DOWN instead?

Oops.  I misunderstood "ALIGN()" here.  Yes.  we should use ALIGN_DOWN()
instead.  Thanks for pointing this out!

>
> These aside, patch looks good to me.

Thanks for your review!  It really help me to improve the quality of the
patch.  Can I add your "Reviewed-by" in the next version?

Best Regards,
Huang, Ying


RE: [PATCH 1/4] exfat: redefine PBR as boot_sector

2020-05-27 Thread Sungjong Seo
> Aggregate PBR related definitions and redefine as "boot_sector" to comply
> with the exFAT specification.
> And, rename variable names including 'pbr'.
> 
> Signed-off-by: Tetsuhiro Kohada 
> ---
>  fs/exfat/exfat_fs.h  |  2 +-
>  fs/exfat/exfat_raw.h | 79 +++--
>  fs/exfat/super.c | 84 ++--
>  3 files changed, 72 insertions(+), 93 deletions(-)
> 
[snip]
> +/* EXFAT: Main and Backup Boot Sector (512 bytes) */ struct boot_sector
> +{
> + __u8jmp_boot[BOOTSEC_JUMP_BOOT_LEN];
> + __u8oem_name[BOOTSEC_OEM_NAME_LEN];

According to the exFAT specification, fs_name and BOOTSEC_FS_NAME_LEN look
better.

> + __u8must_be_zero[BOOTSEC_OLDBPB_LEN];
> + __le64  partition_offset;
> + __le64  vol_length;
> + __le32  fat_offset;
> + __le32  fat_length;
> + __le32  clu_offset;
> + __le32  clu_count;
> + __le32  root_cluster;
> + __le32  vol_serial;
> + __u8fs_revision[2];
> + __le16  vol_flags;
> + __u8sect_size_bits;
> + __u8sect_per_clus_bits;
> + __u8num_fats;
> + __u8drv_sel;
> + __u8percent_in_use;
> + __u8reserved[7];
> + __u8boot_code[390];
> + __le16  signature;
>  } __packed;



Re: [PATCH v30 07/20] x86/sgx: Enumerate and track EPC sections

2020-05-27 Thread Jarkko Sakkinen
On Tue, May 26, 2020 at 08:56:14PM -0700, Sean Christopherson wrote:
> On Mon, May 25, 2020 at 11:23:04AM +0200, Borislav Petkov wrote:
> > On Fri, May 15, 2020 at 03:43:57AM +0300, Jarkko Sakkinen wrote:
> > > +struct sgx_epc_section sgx_epc_sections[SGX_MAX_EPC_SECTIONS];
> > > +int sgx_nr_epc_sections;
> > 
> > We have become very averse against global stuff. What is going to use
> > those, only sgx code I assume...?
> 
> Yes, only SGX code.  The reclaim/swap code needs access to the sections,
> and that code is in a different file, reclaim.c.  I don't have a super
> strong objection to sucking reclaim.c into main.c, but I'm somewhat
> indifferent on code organization as a whole.  Jarkko likely has a stronger
> opinion.

I'll change it.

It's not quite as easy as just "sucking the file in". All the commits
that touch the file need to be reworked:

$ git --no-pager log --format="%H %s" arch/x86/kernel/cpu/sgx/reclaim.c
5aeca6dabf767e9350ee3188ba25ceb21f3162b4 x86/sgx: Add a page reclaimer
de9b1088959f36ffdaf43a49bfea1c7f9f81cac7 x86/sgx: Linux Enclave Driver
08d8fcb74fe268059ee58fcc2a0833b244e1f22a x86/sgx: Enumerate and track EPC 
sections

/Jarkko


[PATCH v9 2/2] mtd: rawnand: Add NAND controller support on Intel LGM SoC

2020-05-27 Thread Ramuthevar,Vadivel MuruganX
From: Ramuthevar Vadivel Murugan 

This patch adds the new IP of Nand Flash Controller(NFC) support
on Intel's Lightning Mountain(LGM) SoC.

DMA is used for burst data transfer operation, also DMA HW supports
aligned 32bit memory address and aligned data access by default.
DMA burst of 8 supported. Data register used to support the read/write
operation from/to device.

NAND controller driver implements ->exec_op() to replace legacy hooks,
these specific call-back method to execute NAND operations.

Signed-off-by: Ramuthevar Vadivel Murugan 

---
 drivers/mtd/nand/raw/Kconfig |   8 +
 drivers/mtd/nand/raw/Makefile|   1 +
 drivers/mtd/nand/raw/intel-nand-controller.c | 747 +++
 3 files changed, 756 insertions(+)
 create mode 100644 drivers/mtd/nand/raw/intel-nand-controller.c

diff --git a/drivers/mtd/nand/raw/Kconfig b/drivers/mtd/nand/raw/Kconfig
index a80a46bb5b8b..75ab2afb78cf 100644
--- a/drivers/mtd/nand/raw/Kconfig
+++ b/drivers/mtd/nand/raw/Kconfig
@@ -457,6 +457,14 @@ config MTD_NAND_CADENCE
  Enable the driver for NAND flash on platforms using a Cadence NAND
  controller.
 
+config MTD_NAND_INTEL_LGM
+   tristate "Support for NAND controller on Intel LGM SoC"
+   depends on OF || COMPILE_TEST
+   depends on HAS_IOMEM
+   help
+ Enables support for NAND Flash chips on Intel's LGM SoC.
+ NAND flash controller interfaced through the External Bus Unit.
+
 comment "Misc"
 
 config MTD_SM_COMMON
diff --git a/drivers/mtd/nand/raw/Makefile b/drivers/mtd/nand/raw/Makefile
index 2d136b158fb7..bfc8fe4d2cb0 100644
--- a/drivers/mtd/nand/raw/Makefile
+++ b/drivers/mtd/nand/raw/Makefile
@@ -58,6 +58,7 @@ obj-$(CONFIG_MTD_NAND_TEGRA)  += tegra_nand.o
 obj-$(CONFIG_MTD_NAND_STM32_FMC2)  += stm32_fmc2_nand.o
 obj-$(CONFIG_MTD_NAND_MESON)   += meson_nand.o
 obj-$(CONFIG_MTD_NAND_CADENCE) += cadence-nand-controller.o
+obj-$(CONFIG_MTD_NAND_INTEL_LGM)   += intel-nand-controller.o
 
 nand-objs := nand_base.o nand_legacy.o nand_bbt.o nand_timings.o nand_ids.o
 nand-objs += nand_onfi.o
diff --git a/drivers/mtd/nand/raw/intel-nand-controller.c 
b/drivers/mtd/nand/raw/intel-nand-controller.c
new file mode 100644
index ..564d28978943
--- /dev/null
+++ b/drivers/mtd/nand/raw/intel-nand-controller.c
@@ -0,0 +1,747 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Copyright (c) 2020 Intel Corporation. */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define EBU_CLC0x000
+#define EBU_CLC_RST0xu
+
+#define EBU_ADDR_SEL(n)(0x20 + (n) * 4)
+/* 5 bits 26:22 included for comparison in the ADDR_SELx */
+#define EBU_ADDR_MASK(x)   ((x) << 4)
+#define EBU_ADDR_SEL_REGEN 0x1
+
+#define EBU_BUSCON(n)  (0x60 + (n) * 4)
+#define EBU_BUSCON_CMULT_V40x1
+#define EBU_BUSCON_RECOVC(n)   ((n) << 2)
+#define EBU_BUSCON_HOLDC(n)((n) << 4)
+#define EBU_BUSCON_WAITRDC(n)  ((n) << 6)
+#define EBU_BUSCON_WAITWRC(n)  ((n) << 8)
+#define EBU_BUSCON_BCGEN_CS0x0
+#define EBU_BUSCON_SETUP_ENBIT(22)
+#define EBU_BUSCON_ALEC0xC000
+
+#define EBU_CON0x0B0
+#define EBU_CON_NANDM_EN   BIT(0)
+#define EBU_CON_NANDM_DIS  0x0
+#define EBU_CON_CSMUX_E_EN BIT(1)
+#define EBU_CON_ALE_P_LOW  BIT(2)
+#define EBU_CON_CLE_P_LOW  BIT(3)
+#define EBU_CON_CS_P_LOW   BIT(4)
+#define EBU_CON_SE_P_LOW   BIT(5)
+#define EBU_CON_WP_P_LOW   BIT(6)
+#define EBU_CON_PRE_P_LOW  BIT(7)
+#define EBU_CON_IN_CS_S(n) ((n) << 8)
+#define EBU_CON_OUT_CS_S(n)((n) << 10)
+#define EBU_CON_LAT_EN_CS_P((0x3D) << 18)
+
+#define EBU_WAIT   0x0B4
+#define EBU_WAIT_RDBY  BIT(0)
+#define EBU_WAIT_WR_C  BIT(3)
+
+#define HSNAND_CTL10x110
+#define HSNAND_CTL1_ADDR_SHIFT 24
+
+#define HSNAND_CTL20x114
+#define HSNAND_CTL2_ADDR_SHIFT 8
+#define HSNAND_CTL2_CYC_N_V5   (0x2 << 16)
+
+#define HSNAND_INT_MSK_CTL 0x124
+#define HSNAND_INT_MSK_CTL_WR_CBIT(4)
+
+#define HSNAND_INT_STA 0x128
+#define HSNAND_INT_STA_WR_CBIT(4)
+
+#define HSNAND_CTL 0x130
+#define HSNAND_CTL_ENABLE_ECC  BIT(0)
+#define HSNAND_CTL_GO  BIT(2)
+#define HSNAND_CTL_CE_SEL_CS(n)BIT(3 + (n))
+#define HSNAND_CTL_RW_READ 0x0
+#define HSNAND_CTL_RW_WRITEBIT(10)
+#define HSNAND_CTL_ECC_OFF_V8THBIT(11)
+#define HSNAND_CTL_CKFF_EN 0x0
+#define HSNAND_CTL_MSG_EN  BIT(17)
+
+#define HSNAND_PARA0   0x13c
+#define HSNAND_PARA0_PAGE_V81920x3
+#define HSNAND_PARA0_PIB_V256  (0x3 << 4)
+#define HSNAND_PARA0_BYP_EN_NP 0x0
+#define HSNAND_PARA0_BYP_DEC_NP0x0
+#define HSNAND_PARA0_TYPE_ONFI BIT(18)

Re: [PATCH v3 0/7] Statsfs: a new ram-based file system for Linux kernel statistics

2020-05-27 Thread Paolo Bonzini
On 28/05/20 00:21, David Ahern wrote:
> On 5/27/20 3:07 PM, Paolo Bonzini wrote:
>> I see what you meant now.  statsfs can also be used to enumerate objects
>> if one is so inclined (with the prototype in patch 7, for example, each
>> network interface becomes a directory).
> 
> there are many use cases that have 100's to 1000's have network devices.
> Having a sysfs entry per device already bloats memory usage for these
> use cases; another filesystem with an entry per device makes that worse.
> Really the wrong direction for large scale systems.

Hi David,

IMO the important part for now is having a flexible kernel API for
exposing statistics across multiple subsystems, so that they can be
harvested in an efficient way.  The userspace API is secondary, and
multiple APIs can be added to cater for different usecases.

For example, as of the first five patches the memory usage is the same
as what is now in the mainline kernel, since all the patchset does is
take existing debugfs inodes and move them to statsfs.  I agree that, if
the concept is extended to the whole kernel, scalability and memory
usage becomes an issue; and indeed, the long-term plan is to support a
binary format that is actually _more_ efficient than the status quo for
large scale systems.

In the meanwhile, the new filesystem can be disabled (see the difference
between "STATS_FS" and "STATS_FS_API") if it imposes undesirable overhead.

Thanks,

Paolo



Re: [PATCH 8/8] blk-mq: drain I/O when all CPUs in a hctx are offline

2020-05-27 Thread Ming Lei
On Wed, May 27, 2020 at 08:33:48PM -0700, Bart Van Assche wrote:
> On 2020-05-27 18:46, Ming Lei wrote:
> > On Wed, May 27, 2020 at 04:09:19PM -0700, Bart Van Assche wrote:
> >> On 2020-05-27 11:06, Christoph Hellwig wrote:
> >>> --- a/block/blk-mq-tag.c
> >>> +++ b/block/blk-mq-tag.c
> >>> @@ -180,6 +180,14 @@ unsigned int blk_mq_get_tag(struct blk_mq_alloc_data 
> >>> *data)
> >>>   sbitmap_finish_wait(bt, ws, &wait);
> >>>  
> >>>  found_tag:
> >>> + /*
> >>> +  * Give up this allocation if the hctx is inactive.  The caller will
> >>> +  * retry on an active hctx.
> >>> +  */
> >>> + if (unlikely(test_bit(BLK_MQ_S_INACTIVE, &data->hctx->state))) {
> >>> + blk_mq_put_tag(tags, data->ctx, tag + tag_offset);
> >>> + return -1;
> >>> + }
> >>>   return tag + tag_offset;
> >>>  }
> >>
> >> The code that has been added in blk_mq_hctx_notify_offline() will only
> >> work correctly if blk_mq_get_tag() tests BLK_MQ_S_INACTIVE after the
> >> store instructions involved in the tag allocation happened. Does this
> >> mean that a memory barrier should be added in the above function before
> >> the test_bit() call?
> > 
> > Please see comment in blk_mq_hctx_notify_offline():
> > 
> > +   /*
> > +* Prevent new request from being allocated on the current hctx.
> > +*
> > +* The smp_mb__after_atomic() Pairs with the implied barrier in
> > +* test_and_set_bit_lock in sbitmap_get().  Ensures the inactive 
> > flag is
> > +* seen once we return from the tag allocator.
> > +*/
> > +   set_bit(BLK_MQ_S_INACTIVE, &hctx->state);
> 
> From Documentation/atomic_bitops.txt: "Except for a successful
> test_and_set_bit_lock() which has ACQUIRE semantics and
> clear_bit_unlock() which has RELEASE semantics."

test_bit(BLK_MQ_S_INACTIVE, &data->hctx->state) is called exactly after
one tag is allocated, that means test_and_set_bit_lock is successful before
the test_bit(). The ACQUIRE semantics guarantees that 
test_bit(BLK_MQ_S_INACTIVE)
is always done after successful test_and_set_bit_lock(), so tag bit is
always set before testing BLK_MQ_S_INACTIVE.
 
See Documentation/memory-barriers.txt:
 (5) ACQUIRE operations.

 This acts as a one-way permeable barrier.  It guarantees that all memory
 operations after the ACQUIRE operation will appear to happen after the
 ACQUIRE operation with respect to the other components of the system.
 ACQUIRE operations include LOCK operations and both smp_load_acquire()
 and smp_cond_load_acquire() operations.

> 
> My understanding is that operations that have acquire semantics pair
> with operations that have release semantics. I haven't been able to find
> any documentation that shows that smp_mb__after_atomic() has release
> semantics. So I looked up its definition. This is what I found:
> 
> $ git grep -nH 'define __smp_mb__after_atomic'
> arch/ia64/include/asm/barrier.h:49:#define __smp_mb__after_atomic()
> barrier()
> arch/mips/include/asm/barrier.h:133:#define __smp_mb__after_atomic()
> smp_llsc_mb()
> arch/s390/include/asm/barrier.h:50:#define __smp_mb__after_atomic()
> barrier()
> arch/sparc/include/asm/barrier_64.h:57:#define __smp_mb__after_atomic()
> barrier()
> arch/x86/include/asm/barrier.h:83:#define __smp_mb__after_atomic()do {
> } while (0)
> arch/xtensa/include/asm/barrier.h:20:#define __smp_mb__after_atomic() 
> barrier()
> include/asm-generic/barrier.h:116:#define __smp_mb__after_atomic()
> __smp_mb()
> 
> My interpretation of the above is that not all smp_mb__after_atomic()
> implementations have release semantics. Do you agree with this conclusion?

I understand smp_mb__after_atomic() orders set_bit(BLK_MQ_S_INACTIVE)
and reading the tag bit which is done in blk_mq_all_tag_iter().

So the two pair of OPs are ordered:

1) if one request(tag bit) is allocated before setting BLK_MQ_S_INACTIVE,
the tag bit will be observed in blk_mq_all_tag_iter() from 
blk_mq_hctx_has_requests(),
so the request will be drained.

OR

2) if one request(tag bit) is allocated after setting BLK_MQ_S_INACTIVE,
the request(tag bit) will be released and retried on another CPU
finally, see __blk_mq_alloc_request().

Cc Paul and linux-kernel list.


Thanks,
Ming



[PATCH] perf jit: Fix inaccurate DWARF line table

2020-05-27 Thread Nick Gasson
Fix an issue where addresses in the DWARF line table are offset by
-0x40 (GEN_ELF_TEXT_OFFSET). This can be seen with `objdump -S` on the
ELF files after perf inject.

Signed-off-by: Nick Gasson 
---
 tools/perf/util/genelf_debug.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/genelf_debug.c b/tools/perf/util/genelf_debug.c
index 30e9f618f6cd..dd40683bd4c0 100644
--- a/tools/perf/util/genelf_debug.c
+++ b/tools/perf/util/genelf_debug.c
@@ -342,7 +342,7 @@ static void emit_lineno_info(struct buffer_ext *be,
 */
 
/* start state of the state machine we take care of */
-   unsigned long last_vma = code_addr;
+   unsigned long last_vma = 0;
char const  *cur_filename = NULL;
unsigned long cur_file_idx = 0;
int last_line = 1;
@@ -473,7 +473,7 @@ jit_process_debug_info(uint64_t code_addr,
ent = debug_entry_next(ent);
}
add_compilation_unit(di, buffer_ext_size(dl));
-   add_debug_line(dl, debug, nr_debug_entries, 0);
+   add_debug_line(dl, debug, nr_debug_entries, GEN_ELF_TEXT_OFFSET);
add_debug_abbrev(da);
if (0) buffer_ext_dump(da, "abbrev");
 
-- 
2.26.2



[PATCH 02/28] net: add sock_no_linger

2020-05-27 Thread Christoph Hellwig
Add a helper to directly set the SO_LINGER sockopt from kernel space
with onoff set to true and a linger time of 0 without going through a
fake uaccess.

Signed-off-by: Christoph Hellwig 
Acked-by: Sagi Grimberg 
---
 drivers/nvme/host/tcp.c   |  9 +
 drivers/nvme/target/tcp.c |  6 +-
 include/net/sock.h|  1 +
 net/core/sock.c   |  9 +
 net/rds/tcp.h |  1 -
 net/rds/tcp_connect.c |  2 +-
 net/rds/tcp_listen.c  | 13 +
 net/sunrpc/svcsock.c  | 12 ++--
 8 files changed, 16 insertions(+), 37 deletions(-)

diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index c15a92163c1f7..e72d87482eb78 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -1313,7 +1313,6 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl,
 {
struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl);
struct nvme_tcp_queue *queue = &ctrl->queues[qid];
-   struct linger sol = { .l_onoff = 1, .l_linger = 0 };
int ret, opt, rcv_pdu_size;
 
queue->ctrl = ctrl;
@@ -1361,13 +1360,7 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl,
 * close. This is done to prevent stale data from being sent should
 * the network connection be restored before TCP times out.
 */
-   ret = kernel_setsockopt(queue->sock, SOL_SOCKET, SO_LINGER,
-   (char *)&sol, sizeof(sol));
-   if (ret) {
-   dev_err(nctrl->device,
-   "failed to set SO_LINGER sock opt %d\n", ret);
-   goto err_sock;
-   }
+   sock_no_linger(queue->sock->sk);
 
if (so_priority > 0) {
ret = kernel_setsockopt(queue->sock, SOL_SOCKET, SO_PRIORITY,
diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c
index 40757a63f4553..e0801494b097f 100644
--- a/drivers/nvme/target/tcp.c
+++ b/drivers/nvme/target/tcp.c
@@ -1429,7 +1429,6 @@ static int nvmet_tcp_set_queue_sock(struct 
nvmet_tcp_queue *queue)
 {
struct socket *sock = queue->sock;
struct inet_sock *inet = inet_sk(sock->sk);
-   struct linger sol = { .l_onoff = 1, .l_linger = 0 };
int ret;
 
ret = kernel_getsockname(sock,
@@ -1447,10 +1446,7 @@ static int nvmet_tcp_set_queue_sock(struct 
nvmet_tcp_queue *queue)
 * close. This is done to prevent stale data from being sent should
 * the network connection be restored before TCP times out.
 */
-   ret = kernel_setsockopt(sock, SOL_SOCKET, SO_LINGER,
-   (char *)&sol, sizeof(sol));
-   if (ret)
-   return ret;
+   sock_no_linger(sock->sk);
 
if (so_priority > 0) {
ret = kernel_setsockopt(sock, SOL_SOCKET, SO_PRIORITY,
diff --git a/include/net/sock.h b/include/net/sock.h
index 2ec085044790c..6ed00bf009bbe 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2688,6 +2688,7 @@ static inline bool sk_dev_equal_l3scope(struct sock *sk, 
int dif)
 
 void sock_def_readable(struct sock *sk);
 
+void sock_no_linger(struct sock *sk);
 void sock_set_reuseaddr(struct sock *sk);
 
 #endif /* _SOCK_H */
diff --git a/net/core/sock.c b/net/core/sock.c
index 18eb84fdf5fbe..f0f09524911c8 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -720,6 +720,15 @@ void sock_set_reuseaddr(struct sock *sk)
 }
 EXPORT_SYMBOL(sock_set_reuseaddr);
 
+void sock_no_linger(struct sock *sk)
+{
+   lock_sock(sk);
+   sk->sk_lingertime = 0;
+   sock_set_flag(sk, SOCK_LINGER);
+   release_sock(sk);
+}
+EXPORT_SYMBOL(sock_no_linger);
+
 /*
  * This is meant for all protocols to use and covers goings on
  * at the socket level. Everything here is generic.
diff --git a/net/rds/tcp.h b/net/rds/tcp.h
index 3c69361d21c73..d640e210b97b6 100644
--- a/net/rds/tcp.h
+++ b/net/rds/tcp.h
@@ -73,7 +73,6 @@ void rds_tcp_listen_data_ready(struct sock *sk);
 int rds_tcp_accept_one(struct socket *sock);
 int rds_tcp_keepalive(struct socket *sock);
 void *rds_tcp_listen_sock_def_readable(struct net *net);
-void rds_tcp_set_linger(struct socket *sock);
 
 /* tcp_recv.c */
 int rds_tcp_recv_init(void);
diff --git a/net/rds/tcp_connect.c b/net/rds/tcp_connect.c
index 008f50fb25dd2..4e64598176b05 100644
--- a/net/rds/tcp_connect.c
+++ b/net/rds/tcp_connect.c
@@ -207,7 +207,7 @@ void rds_tcp_conn_path_shutdown(struct rds_conn_path *cp)
 
if (sock) {
if (rds_destroy_pending(cp->cp_conn))
-   rds_tcp_set_linger(sock);
+   sock_no_linger(sock->sk);
sock->ops->shutdown(sock, RCV_SHUTDOWN | SEND_SHUTDOWN);
lock_sock(sock->sk);
rds_tcp_restore_callbacks(sock, tc); /* tc->tc_sock = NULL */
diff --git a/net/rds/tcp_listen.c b/net/rds/tcp_listen.c
index 810a3a49e9474..bbb31b9c0b391 100644
--- a/net/rds/tcp_listen.c
+++ b/net/rds/tcp_listen.c
@@ -111,17 +111,6 @@ struct rds_tcp_connection *rds_tcp_accept_one_path(struct 
rd

remove most callers of kernel_setsockopt v3

2020-05-27 Thread Christoph Hellwig
Hi Dave,

this series removes most callers of the kernel_setsockopt functions, and
instead switches their users to small functions that implement setting a
sockopt directly using a normal kernel function call with type safety and
all the other benefits of not having a function call.

In some cases these functions seem pretty heavy handed as they do
a lock_sock even for just setting a single variable, but this mirrors
the real setsockopt implementation unlike a few drivers that just set
set the fields directly.


Changes since v2:
 - drop the separately merged kernel_getopt_removal
 - drop the sctp patches, as there is conflicting cleanup going on
 - add an additional ACK for the rxrpc changes

Changes since v1:
 - use ->getname for sctp sockets in dlm
 - add a new ->bind_add struct proto method for dlm/sctp
 - switch the ipv6 and remaining sctp helpers to inline function so that
   the ipv6 and sctp modules are not pulled in by any module that could
   potentially use ipv6 or sctp connections
 - remove arguments to various sock_* helpers that are always used with
   the same constant arguments


[PATCH 08/28] net: add sock_set_rcvbuf

2020-05-27 Thread Christoph Hellwig
Add a helper to directly set the SO_RCVBUFFORCE sockopt from kernel space
without going through a fake uaccess.

Signed-off-by: Christoph Hellwig 
---
 fs/dlm/lowcomms.c  |  7 +-
 include/net/sock.h |  1 +
 net/core/sock.c| 59 +-
 3 files changed, 34 insertions(+), 33 deletions(-)

diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c
index 138009c6a2ee1..45c37f572c9d2 100644
--- a/fs/dlm/lowcomms.c
+++ b/fs/dlm/lowcomms.c
@@ -1297,7 +1297,6 @@ static int sctp_listen_for_all(void)
struct socket *sock = NULL;
int result = -EINVAL;
struct connection *con = nodeid2con(0, GFP_NOFS);
-   int bufsize = NEEDED_RMEM;
int one = 1;
 
if (!con)
@@ -1312,11 +1311,7 @@ static int sctp_listen_for_all(void)
goto out;
}
 
-   result = kernel_setsockopt(sock, SOL_SOCKET, SO_RCVBUFFORCE,
-(char *)&bufsize, sizeof(bufsize));
-   if (result)
-   log_print("Error increasing buffer space on socket %d", result);
-
+   sock_set_rcvbuf(sock->sk, NEEDED_RMEM);
result = kernel_setsockopt(sock, SOL_SCTP, SCTP_NODELAY, (char *)&one,
   sizeof(one));
if (result < 0)
diff --git a/include/net/sock.h b/include/net/sock.h
index dc08c176238fd..c997289aabbf9 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2693,6 +2693,7 @@ void sock_enable_timestamps(struct sock *sk);
 void sock_no_linger(struct sock *sk);
 void sock_set_keepalive(struct sock *sk);
 void sock_set_priority(struct sock *sk, u32 priority);
+void sock_set_rcvbuf(struct sock *sk, int val);
 void sock_set_reuseaddr(struct sock *sk);
 void sock_set_sndtimeo(struct sock *sk, s64 secs);
 
diff --git a/net/core/sock.c b/net/core/sock.c
index 728f5fb156a0c..3c6ebf952e9ad 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -789,6 +789,35 @@ void sock_set_keepalive(struct sock *sk)
 }
 EXPORT_SYMBOL(sock_set_keepalive);
 
+static void __sock_set_rcvbuf(struct sock *sk, int val)
+{
+   /* Ensure val * 2 fits into an int, to prevent max_t() from treating it
+* as a negative value.
+*/
+   val = min_t(int, val, INT_MAX / 2);
+   sk->sk_userlocks |= SOCK_RCVBUF_LOCK;
+
+   /* We double it on the way in to account for "struct sk_buff" etc.
+* overhead.   Applications assume that the SO_RCVBUF setting they make
+* will allow that much actual data to be received on that socket.
+*
+* Applications are unaware that "struct sk_buff" and other overheads
+* allocate from the receive buffer during socket buffer allocation.
+*
+* And after considering the possible alternatives, returning the value
+* we actually used in getsockopt is the most desirable behavior.
+*/
+   WRITE_ONCE(sk->sk_rcvbuf, max_t(int, val * 2, SOCK_MIN_RCVBUF));
+}
+
+void sock_set_rcvbuf(struct sock *sk, int val)
+{
+   lock_sock(sk);
+   __sock_set_rcvbuf(sk, val);
+   release_sock(sk);
+}
+EXPORT_SYMBOL(sock_set_rcvbuf);
+
 /*
  * This is meant for all protocols to use and covers goings on
  * at the socket level. Everything here is generic.
@@ -885,30 +914,7 @@ int sock_setsockopt(struct socket *sock, int level, int 
optname,
 * play 'guess the biggest size' games. RCVBUF/SNDBUF
 * are treated in BSD as hints
 */
-   val = min_t(u32, val, sysctl_rmem_max);
-set_rcvbuf:
-   /* Ensure val * 2 fits into an int, to prevent max_t()
-* from treating it as a negative value.
-*/
-   val = min_t(int, val, INT_MAX / 2);
-   sk->sk_userlocks |= SOCK_RCVBUF_LOCK;
-   /*
-* We double it on the way in to account for
-* "struct sk_buff" etc. overhead.   Applications
-* assume that the SO_RCVBUF setting they make will
-* allow that much actual data to be received on that
-* socket.
-*
-* Applications are unaware that "struct sk_buff" and
-* other overheads allocate from the receive buffer
-* during socket buffer allocation.
-*
-* And after considering the possible alternatives,
-* returning the value we actually used in getsockopt
-* is the most desirable behavior.
-*/
-   WRITE_ONCE(sk->sk_rcvbuf,
-  max_t(int, val * 2, SOCK_MIN_RCVBUF));
+   __sock_set_rcvbuf(sk, min_t(u32, val, sysctl_rmem_max));
break;
 
case SO_RCVBUFFORCE:
@@ -920,9 +926,8 @@ int sock_setsockopt(struct socket *sock, int level, int 
optname,
/* No negative values (to prevent underflow, as val will be
 * multiplied by 2).
 */
-

[PATCH 09/28] net: add sock_set_reuseport

2020-05-27 Thread Christoph Hellwig
Add a helper to directly set the SO_REUSEPORT sockopt from kernel space
without going through a fake uaccess.

Signed-off-by: Christoph Hellwig 
---
 include/net/sock.h|  1 +
 net/core/sock.c   |  8 
 net/sunrpc/xprtsock.c | 17 +
 3 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/include/net/sock.h b/include/net/sock.h
index c997289aabbf9..d994daa418ec2 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2695,6 +2695,7 @@ void sock_set_keepalive(struct sock *sk);
 void sock_set_priority(struct sock *sk, u32 priority);
 void sock_set_rcvbuf(struct sock *sk, int val);
 void sock_set_reuseaddr(struct sock *sk);
+void sock_set_reuseport(struct sock *sk);
 void sock_set_sndtimeo(struct sock *sk, s64 secs);
 
 #endif /* _SOCK_H */
diff --git a/net/core/sock.c b/net/core/sock.c
index 3c6ebf952e9ad..2ca3425b519c0 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -729,6 +729,14 @@ void sock_set_reuseaddr(struct sock *sk)
 }
 EXPORT_SYMBOL(sock_set_reuseaddr);
 
+void sock_set_reuseport(struct sock *sk)
+{
+   lock_sock(sk);
+   sk->sk_reuseport = true;
+   release_sock(sk);
+}
+EXPORT_SYMBOL(sock_set_reuseport);
+
 void sock_no_linger(struct sock *sk)
 {
lock_sock(sk);
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 30082cd039960..399848c2bcb29 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -1594,21 +1594,6 @@ static int xs_get_random_port(void)
return rand + min;
 }
 
-/**
- * xs_set_reuseaddr_port - set the socket's port and address reuse options
- * @sock: socket
- *
- * Note that this function has to be called on all sockets that share the
- * same port, and it must be called before binding.
- */
-static void xs_sock_set_reuseport(struct socket *sock)
-{
-   int opt = 1;
-
-   kernel_setsockopt(sock, SOL_SOCKET, SO_REUSEPORT,
-   (char *)&opt, sizeof(opt));
-}
-
 static unsigned short xs_sock_getport(struct socket *sock)
 {
struct sockaddr_storage buf;
@@ -1801,7 +1786,7 @@ static struct socket *xs_create_sock(struct rpc_xprt 
*xprt,
xs_reclassify_socket(family, sock);
 
if (reuseport)
-   xs_sock_set_reuseport(sock);
+   sock_set_reuseport(sock->sk);
 
err = xs_bind(transport, sock);
if (err) {
-- 
2.26.2



Re: [PATCH] ASoC: AMD: Use mixer control to switch between DMICs

2020-05-27 Thread Agrawal, Akshu



On 5/27/2020 4:57 PM, Mark Brown wrote:

On Wed, May 27, 2020 at 07:10:16AM +0530, Akshu Agrawal wrote:


+   SOC_SINGLE_BOOL_EXT("Front Mic", 0, front_mic_get, front_mic_set),

This should probably be a mux with two labelled options, or if it's a
boolean control it should end in Switch.  A mux definitely seems like a
better option though.


Actually it's a dmic switch, so will change it to boolean control named 
"DMIC switch". Front or rear mic might change with variants.


Thanks,

Akshu



  1   2   3   4   5   6   7   8   9   10   >