Re: About the try to remove cross-release feature entirely by Ingo

2018-01-01 Thread Byungchul Park

On 12/30/2017 3:16 PM, Matthew Wilcox wrote:

On Fri, Dec 29, 2017 at 04:28:51PM +0900, Byungchul Park wrote:

On Thu, Dec 28, 2017 at 10:51:46PM -0500, Theodore Ts'o wrote:

On Fri, Dec 29, 2017 at 10:47:36AM +0900, Byungchul Park wrote:


(1) The best way: To classify all waiters correctly.


It's really not all waiters, but all *locks*, no?


Thanks for your opinion. I will add my opinion on you.

I meant *waiters*. Locks are only a sub set of potential waiters, which
actually cause deadlocks. Cross-release was designed to consider the
super set including all general waiters such as typical locks,
wait_for_completion(), and lock_page() and so on..


I think this is a terminology problem.  To me (and, I suspect Ted), a
waiter is a subject of a verb while a lock is an object.  So Ted is asking
whether we have to classify the users, while I think you're saying we
have extra objects to classify.

I'd be comfortable continuing to refer to completions as locks.  We could
try to come up with a new object name like waitpoints though?


Right. Then "event" should be used as an object name than "waiter".


The problems come from wrong classification. Waiters either classfied
well or invalidated properly won't bitrot.


I disagree here.  As Ted says, it's the interactions between the


As you know, the classification is something already considering
the interactions between the subsystems and classified. But, yes.
That is just what we have to do untimately but not what we can do
right away. That's why I suggested all 3 ways + 1 way (by Amir).


subsystems that leads to problems.  Everything's goig to work great
until somebody does something in a way that's never been tried before.


Yes. Everything has worked great so far, since the classification
by now is done well enough at least to avoid such problems, not
perfect though. IMO, the classification does not have to be perfect
but needs to be good enough to work.

--
Thanks,
Byungchul


[PATCH 2/3] nvme-pci: change the name of functions corresponding to setup adminq

2018-01-01 Thread Jianchao Wang
No functional change. Just change name of functions corresponding
to setup adminq to make it more readable.
nvme_pci_configure_admin_queue -> nvme_pci_setup_adminq
nvme_alloc_admin_tags  -> nvme_pci_start_adminq

Signed-off-by: Jianchao Wang 
---
 drivers/nvme/host/pci.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 365dd05..1a63835 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -1517,7 +1517,7 @@ static void nvme_dev_remove_admin(struct nvme_dev *dev)
}
 }
 
-static int nvme_alloc_admin_tags(struct nvme_dev *dev)
+static int nvme_pci_start_adminq(struct nvme_dev *dev)
 {
if (!dev->ctrl.admin_q) {
dev->admin_tagset.ops = &nvme_mq_admin_ops;
@@ -1576,7 +1576,7 @@ static int nvme_remap_bar(struct nvme_dev *dev, unsigned 
long size)
return 0;
 }
 
-static int nvme_pci_configure_admin_queue(struct nvme_dev *dev)
+static int nvme_pci_setup_adminq(struct nvme_dev *dev)
 {
int result;
u32 aqa;
@@ -2321,11 +2321,11 @@ static void nvme_reset_work(struct work_struct *work)
if (result)
goto out;
 
-   result = nvme_pci_configure_admin_queue(dev);
+   result = nvme_pci_setup_adminq(dev);
if (result)
goto out;
 
-   result = nvme_alloc_admin_tags(dev);
+   result = nvme_pci_start_adminq(dev);
if (result)
goto out;
 
-- 
2.7.4



[PATCH 1/3] nvme-pci: add nvme_pci_pre_init

2018-01-01 Thread Jianchao Wang
No fucntional change. Add nvme_pci_pre_init to package the nvme
specified initialization work before configuring admin queue.
Then nvme_pci_enable and nvme_pci_configure_admin_queue could be
clearer.

Signed-off-by: Jianchao Wang 
---
 drivers/nvme/host/pci.c | 145 +---
 1 file changed, 77 insertions(+), 68 deletions(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 6e58de1..365dd05 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -1581,21 +1581,7 @@ static int nvme_pci_configure_admin_queue(struct 
nvme_dev *dev)
int result;
u32 aqa;
struct nvme_queue *nvmeq;
-
-   result = nvme_remap_bar(dev, db_bar_size(dev, 0));
-   if (result < 0)
-   return result;
-
-   dev->subsystem = readl(dev->bar + NVME_REG_VS) >= NVME_VS(1, 1, 0) ?
-   NVME_CAP_NSSRC(dev->ctrl.cap) : 0;
-
-   if (dev->subsystem &&
-   (readl(dev->bar + NVME_REG_CSTS) & NVME_CSTS_NSSRO))
-   writel(NVME_CSTS_NSSRO, dev->bar + NVME_REG_CSTS);
-
-   result = nvme_disable_ctrl(&dev->ctrl, dev->ctrl.cap);
-   if (result < 0)
-   return result;
+   struct pci_dev *pdev = to_pci_dev(dev->dev);
 
nvmeq = dev->queues[0];
if (!nvmeq) {
@@ -1616,13 +1602,20 @@ static int nvme_pci_configure_admin_queue(struct 
nvme_dev *dev)
if (result)
return result;
 
+   /*
+* Some devices and/or platforms don't advertise or work with INTx
+* interrupts. Pre-enable a single MSIX or MSI vec for setup. We'll
+* adjust this later.
+*/
+   result = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
+   if (result < 0)
+   return result;
+
nvmeq->cq_vector = 0;
nvme_init_queue(nvmeq, 0);
result = queue_request_irq(nvmeq);
-   if (result) {
+   if (result)
nvmeq->cq_vector = -1;
-   return result;
-   }
 
return result;
 }
@@ -2096,56 +2089,6 @@ static int nvme_pci_enable(struct nvme_dev *dev)
goto disable;
}
 
-   /*
-* Some devices and/or platforms don't advertise or work with INTx
-* interrupts. Pre-enable a single MSIX or MSI vec for setup. We'll
-* adjust this later.
-*/
-   result = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
-   if (result < 0)
-   return result;
-
-   dev->ctrl.cap = lo_hi_readq(dev->bar + NVME_REG_CAP);
-
-   dev->q_depth = min_t(int, NVME_CAP_MQES(dev->ctrl.cap) + 1,
-   io_queue_depth);
-   dev->db_stride = 1 << NVME_CAP_STRIDE(dev->ctrl.cap);
-   dev->dbs = dev->bar + 4096;
-
-   /*
-* Temporary fix for the Apple controller found in the MacBook8,1 and
-* some MacBook7,1 to avoid controller resets and data loss.
-*/
-   if (pdev->vendor == PCI_VENDOR_ID_APPLE && pdev->device == 0x2001) {
-   dev->q_depth = 2;
-   dev_warn(dev->ctrl.device, "detected Apple NVMe controller, "
-   "set queue depth=%u to work around controller resets\n",
-   dev->q_depth);
-   } else if (pdev->vendor == PCI_VENDOR_ID_SAMSUNG &&
-  (pdev->device == 0xa821 || pdev->device == 0xa822) &&
-  NVME_CAP_MQES(dev->ctrl.cap) == 0) {
-   dev->q_depth = 64;
-   dev_err(dev->ctrl.device, "detected PM1725 NVMe controller, "
-"set queue depth=%u\n", dev->q_depth);
-   }
-
-   /*
-* CMBs can currently only exist on >=1.2 PCIe devices. We only
-* populate sysfs if a CMB is implemented. Since nvme_dev_attrs_group
-* has no name we can pass NULL as final argument to
-* sysfs_add_file_to_group.
-*/
-
-   if (readl(dev->bar + NVME_REG_VS) >= NVME_VS(1, 2, 0)) {
-   dev->cmb = nvme_map_cmb(dev);
-   if (dev->cmb) {
-   if (sysfs_add_file_to_group(&dev->ctrl.device->kobj,
-   &dev_attr_cmb.attr, NULL))
-   dev_warn(dev->ctrl.device,
-"failed to add sysfs attribute for 
CMB\n");
-   }
-   }
-
pci_enable_pcie_error_reporting(pdev);
pci_save_state(pdev);
return 0;
@@ -2290,6 +2233,68 @@ static void nvme_remove_dead_ctrl(struct nvme_dev *dev, 
int status)
nvme_put_ctrl(&dev->ctrl);
 }
 
+/* Include the initialization work before setup admin queue
+ */
+static int nvme_pci_pre_init(struct nvme_dev *dev)
+{
+   int ret;
+   struct pci_dev *pdev = to_pci_dev(dev->dev);
+
+   dev->ctrl.cap = lo_hi_readq(dev->bar + NVME_REG_CAP);
+
+   dev->q_depth = min_t(int, NVME_CAP_MQES(dev->ctrl.cap) + 1,
+   io_queue_de

Re: [PATCH] x86/xen/time: fix section mismatch for xen_init_time_ops()

2018-01-01 Thread Juergen Gross
On 24/12/17 03:50, Nick Desaulniers wrote:
> The header declares this function as __init but is defined in __ref
> section.
> 
> Signed-off-by: Nick Desaulniers 

Reviewed-by: Juergen Gross 


Juergen


[PATCH v4] crypto: AF_ALG - whitelist mask and type

2018-01-01 Thread Stephan Müller
Hi,

sorry, I forgot the right tags.

---8<---

The user space interface allows specifying the type and mask field used
to allocate the cipher. Only a subset of the possible flags are intended
for user space. Therefore, white-list the allowed flags.

In case the user space caller uses at least one non-allowed flag, EINVAL
is returned.

Reported-by: syzbot 
Cc: 
Signed-off-by: Stephan Mueller 
---
 crypto/af_alg.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/crypto/af_alg.c b/crypto/af_alg.c
index 35d4dcea381f..5231f421ad00 100644
--- a/crypto/af_alg.c
+++ b/crypto/af_alg.c
@@ -150,7 +150,7 @@ EXPORT_SYMBOL_GPL(af_alg_release_parent);
 
 static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
 {
-   const u32 forbidden = CRYPTO_ALG_INTERNAL;
+   const u32 allowed = CRYPTO_ALG_KERN_DRIVER_ONLY;
struct sock *sk = sock->sk;
struct alg_sock *ask = alg_sk(sk);
struct sockaddr_alg *sa = (void *)uaddr;
@@ -158,6 +158,10 @@ static int alg_bind(struct socket *sock, struct sockaddr 
*uaddr, int addr_len)
void *private;
int err;
 
+   /* If caller uses non-allowed flag, return error. */
+   if ((sa->salg_feat & ~allowed) || (sa->salg_mask & ~allowed))
+   return -EINVAL;
+
if (sock->state == SS_CONNECTED)
return -EINVAL;
 
@@ -176,9 +180,7 @@ static int alg_bind(struct socket *sock, struct sockaddr 
*uaddr, int addr_len)
if (IS_ERR(type))
return PTR_ERR(type);
 
-   private = type->bind(sa->salg_name,
-sa->salg_feat & ~forbidden,
-sa->salg_mask & ~forbidden);
+   private = type->bind(sa->salg_name, sa->salg_feat, sa->salg_mask);
if (IS_ERR(private)) {
module_put(type->owner);
return PTR_ERR(private);
-- 
2.14.3




[PATCH v3] crypto: AF_ALG - whitelist mask and type

2018-01-01 Thread Stephan Müller
The user space interface allows specifying the type and mask field used
to allocate the cipher. Only a subset of the possible flags are intended
for user space. Therefore, white-list the allowed flags.

In case the user space caller uses at least one non-allowed flag, EINVAL
is returned.

Signed-off-by: Stephan Mueller 
---
 crypto/af_alg.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/crypto/af_alg.c b/crypto/af_alg.c
index 35d4dcea381f..5231f421ad00 100644
--- a/crypto/af_alg.c
+++ b/crypto/af_alg.c
@@ -150,7 +150,7 @@ EXPORT_SYMBOL_GPL(af_alg_release_parent);
 
 static int alg_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
 {
-   const u32 forbidden = CRYPTO_ALG_INTERNAL;
+   const u32 allowed = CRYPTO_ALG_KERN_DRIVER_ONLY;
struct sock *sk = sock->sk;
struct alg_sock *ask = alg_sk(sk);
struct sockaddr_alg *sa = (void *)uaddr;
@@ -158,6 +158,10 @@ static int alg_bind(struct socket *sock, struct sockaddr 
*uaddr, int addr_len)
void *private;
int err;
 
+   /* If caller uses non-allowed flag, return error. */
+   if ((sa->salg_feat & ~allowed) || (sa->salg_mask & ~allowed))
+   return -EINVAL;
+
if (sock->state == SS_CONNECTED)
return -EINVAL;
 
@@ -176,9 +180,7 @@ static int alg_bind(struct socket *sock, struct sockaddr 
*uaddr, int addr_len)
if (IS_ERR(type))
return PTR_ERR(type);
 
-   private = type->bind(sa->salg_name,
-sa->salg_feat & ~forbidden,
-sa->salg_mask & ~forbidden);
+   private = type->bind(sa->salg_name, sa->salg_feat, sa->salg_mask);
if (IS_ERR(private)) {
module_put(type->owner);
return PTR_ERR(private);
-- 
2.14.3




Re: [RFC PATCH 1/4] rtc: Introduce one interface to save the RTC hardware time range

2018-01-01 Thread Alexandre Belloni
Hi Baolin,

Could you have a look at
https://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux.git/commit/?h=rtc-ranges

My approach has multiple advantages as it works for 64-bit counters and
the range can be updated at runtime.

On 02/01/2018 at 13:10:05 +0800, Baolin Wang wrote:
> In order to the setting time values are not beyond the limitation
> supported by RTC hardware, we introduce one interface to tell the
> hardware range to the RTC core, which are used to valid if the
> setting time values are in the RTC hardware range.
> 
> Moreover we also need the RTC hardware range to expand the RTC
> range in next patches by adding one offset.
> 
> Signed-off-by: Baolin Wang 
> ---
>  drivers/rtc/class.c |   13 ++
>  drivers/rtc/interface.c |   62 
> +++
>  include/linux/rtc.h |9 +++
>  3 files changed, 84 insertions(+)
> 
> diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
> index 722d683..31fc0f1 100644
> --- a/drivers/rtc/class.c
> +++ b/drivers/rtc/class.c
> @@ -247,6 +247,12 @@ struct rtc_device *rtc_device_register(const char *name, 
> struct device *dev,
>  
>   dev_set_name(&rtc->dev, "rtc%d", id);
>  
> + err = rtc_read_range(rtc, &rtc->max_hw_secs, &rtc->min_hw_secs);
> + if (err) {
> + dev_err(&rtc->dev, "%s: failed to get RTC range\n", name);
> + goto exit_ida;
> + }
> +
>   /* Check to see if there is an ALARM already set in hw */
>   err = __rtc_read_alarm(rtc, &alrm);
>  
> @@ -436,6 +442,13 @@ int __rtc_register_device(struct module *owner, struct 
> rtc_device *rtc)
>  
>   rtc->owner = owner;
>  
> + err = rtc_read_range(rtc, &rtc->max_hw_secs, &rtc->min_hw_secs);
> + if (err) {
> + dev_err(&rtc->dev, "%s: failed to get RTC range\n",
> + dev_name(&rtc->dev));
> + return err;
> + }
> +
>   /* Check to see if there is an ALARM already set in hw */
>   err = __rtc_read_alarm(rtc, &alrm);
>   if (!err && !rtc_valid_tm(&alrm.time))
> diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
> index 672b192..c8090e3 100644
> --- a/drivers/rtc/interface.c
> +++ b/drivers/rtc/interface.c
> @@ -65,6 +65,10 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time 
> *tm)
>   if (err != 0)
>   return err;
>  
> + err = rtc_valid_range(rtc, tm);
> + if (err)
> + return err;
> +
>   err = mutex_lock_interruptible(&rtc->ops_lock);
>   if (err)
>   return err;
> @@ -329,6 +333,11 @@ static int __rtc_set_alarm(struct rtc_device *rtc, 
> struct rtc_wkalrm *alarm)
>   err = rtc_valid_tm(&alarm->time);
>   if (err)
>   return err;
> +
> + err = rtc_valid_range(rtc, &alarm->time);
> + if (err)
> + return err;
> +
>   scheduled = rtc_tm_to_time64(&alarm->time);
>  
>   /* Make sure we're not setting alarms in the past */
> @@ -1027,3 +1036,56 @@ int rtc_set_offset(struct rtc_device *rtc, long offset)
>   mutex_unlock(&rtc->ops_lock);
>   return ret;
>  }
> +
> +/* rtc_read_range - Read the max and min hardware count supported by RTC 
> device
> + * @ rtc: rtc device to be used.
> + * @ max_hw_secs: maximum hardware count in seconds, which can represent
> + * the maximum time values in RTC hardware.
> + * @ min_hw_secs: minimum hardware count in seconds, which can represent
> + * the minimum time values in RTC hardware.
> + *
> + * The max_hw_secs and min_hw_secs implemented by user must represent the
> + * correct hardware start time and maximum time, which means the count
> + * will wrap around to min_hw_secs after the maximum count.
> + *
> + * If user did not implement the read_range() interface, we can set 
> max_hw_secs
> + * and min_hw_secs to 0, which avoids validing the range.
> + */
> +int rtc_read_range(struct rtc_device *rtc, time64_t *max_hw_secs,
> +time64_t *min_hw_secs)
> +{
> + int ret;
> +
> + if (!rtc->ops || !rtc->ops->read_range) {
> + *max_hw_secs = 0;
> + *min_hw_secs = 0;
> + return 0;
> + }
> +
> + mutex_lock(&rtc->ops_lock);
> + ret = rtc->ops->read_range(rtc->dev.parent, max_hw_secs, min_hw_secs);
> + mutex_unlock(&rtc->ops_lock);
> +
> + return ret;
> +}
> +
> +/* rtc_valid_range - Valid if the setting time in the RTC range
> + * @ rtc: rtc device to be used.
> + * @ tm: time values need to valid.
> + *
> + * Only the rtc->max_hw_secs was set, then we can valid if the setting time
> + * values are beyond the RTC range.
> + */
> +int rtc_valid_range(struct rtc_device *rtc, struct rtc_time *tm)
> +{
> + time64_t secs;
> +
> + if (!rtc->max_hw_secs)
> + return 0;
> +
> + secs = rtc_tm_to_time64(tm);
> + if (secs < rtc->min_hw_secs || secs > rtc->max_hw_secs)
> + return -EINVAL;
> +
> + return 0;
> +}
> diff --git a/include/linux/rtc.h b/include/linux/rt

Re: [PATCH -next] tee: shm: make local function __tee_shm_alloc() static

2018-01-01 Thread Jens Wiklander
On Tue, Jan 2, 2018 at 5:09 AM, Wei Yongjun  wrote:
> Fixes the following sparse warnings:
>
> drivers/tee/tee_shm.c:115:16: warning:
>  symbol '__tee_shm_alloc' was not declared. Should it be static?
>
> Signed-off-by: Wei Yongjun 
> ---
>  drivers/tee/tee_shm.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c
> index 04e1b8b..13b4de1 100644
> --- a/drivers/tee/tee_shm.c
> +++ b/drivers/tee/tee_shm.c
> @@ -112,9 +112,9 @@ static int tee_shm_op_mmap(struct dma_buf *dmabuf, struct 
> vm_area_struct *vma)
> .mmap = tee_shm_op_mmap,
>  };
>
> -struct tee_shm *__tee_shm_alloc(struct tee_context *ctx,
> -   struct tee_device *teedev,
> -   size_t size, u32 flags)
> +static struct tee_shm *__tee_shm_alloc(struct tee_context *ctx,
> +  struct tee_device *teedev,
> +  size_t size, u32 flags)
>  {
> struct tee_shm_pool_mgr *poolm = NULL;
> struct tee_shm *shm;
>

Thanks, but I've already picked up the same patch from Colin King a
few days ago.

/Jens


Re: thermal/drivers/hisi: Remove bogus const from function return type

2018-01-01 Thread Geert Uytterhoeven
Hi Eduardo,

On Mon, Jan 1, 2018 at 7:21 PM, Eduardo Valentin  wrote:
> On Sun, Nov 19, 2017 at 12:04:27PM +0100, Geert Uytterhoeven wrote:
>> With gcc-4.1.2:
>>
>> drivers/thermal/hisi_thermal.c: In function ‘hisi_thermal_probe’:
>> drivers/thermal/hisi_thermal.c:530: warning: type qualifiers ignored on 
>> function return type
>>
>> Remove the "const" keyword to fix this.
>
> Interesting.
>
> I intentionally asked Daniel to include the modifier because sparse
> pointed this to me:
>
> This patch adds this issue to hisi driver (sparse)
>
> drivers/thermal/hisi_thermal.c:398:24: warning: incorrect type in assignment 
> (different modifiers)
> drivers/thermal/hisi_thermal.c:398:24:expected int ( *platform_probe )( 
> ... )
> drivers/thermal/hisi_thermal.c:398:24:got void const *

Sparse doesn't like assigning void pointers to function pointers without a cast.

> which makes sense to me to be const, given that it is receiving the return
> of a function which returns a const void *.
> nclude/linux/of_device.h:extern const void *of_device_get_match_data(const 
> struct device *dev);

That const applies to what is returned by of_device_get_match_data() (a const
void *), not to what is returned by the returned function (an int).

Gr{oetje,eeting}s,

Geert

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

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


Re: [PATCH 3/3] md: bitmap: Support circular buffer list.

2018-01-01 Thread Sean Fu
On Tue, Jan 02, 2018 at 02:54:49PM +0800, Sean Fu wrote:
> Modify write_page free_buffers and read_page to support circular buffer
> list.
> 
> Signed-off-by: Sean Fu 
> ---
>  drivers/md/md-bitmap.c | 36 +++-
>  1 file changed, 19 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
> index 239c7bb..b8412c2 100644
> --- a/drivers/md/md-bitmap.c
> +++ b/drivers/md/md-bitmap.c
> @@ -286,7 +286,7 @@ static void bitmap_file_kick(struct bitmap *bitmap);
>   */
>  static void write_page(struct bitmap *bitmap, struct page *page, int wait)
>  {
> - struct buffer_head *bh;
> + struct buffer_head *bh, *head;
>  
>   if (bitmap->storage.file == NULL) {
>   switch (write_sb_page(bitmap, page, wait)) {
> @@ -295,15 +295,16 @@ static void write_page(struct bitmap *bitmap, struct 
> page *page, int wait)
>   }
>   } else {
>  
> - bh = page_buffers(page);
> + bh = head = page_buffers(page);
>  
> - while (bh && bh->b_blocknr) {
> - atomic_inc(&bitmap->pending_writes);
> - set_buffer_locked(bh);
> - set_buffer_mapped(bh);
> - submit_bh(REQ_OP_WRITE, REQ_SYNC, bh);
> - bh = bh->b_this_page;
> - }
> + do {
> + if (bh && bh->b_blocknr) {
> + atomic_inc(&bitmap->pending_writes);
> + set_buffer_locked(bh);
> + set_buffer_mapped(bh);
> + submit_bh(REQ_OP_WRITE, REQ_SYNC, bh);
> + }
> + } while ((bh = bh->b_this_page) != head);
>  
>   if (wait)
>   wait_event(bitmap->write_wait,
> @@ -333,17 +334,18 @@ __clear_page_buffers(struct page *page)
>  }
>  static void free_buffers(struct page *page)
>  {
> - struct buffer_head *bh;
> + struct buffer_head *bh, *head;
>  
>   if (!PagePrivate(page))
>   return;
>  
> - bh = page_buffers(page);
> - while (bh) {
> + bh = head = page_buffers(page);
> + do {
>   struct buffer_head *next = bh->b_this_page;
>   free_buffer_head(bh);
>   bh = next;
> - }
> + } while (bh != head);
> +
>   __clear_page_buffers(page);
>   put_page(page);
>  }
> @@ -362,20 +364,20 @@ static int read_page(struct file *file, unsigned long 
> index,
>  {
>   int ret = 0;
>   struct inode *inode = file_inode(file);
> - struct buffer_head *bh;
> + struct buffer_head *bh, *head;
>   sector_t block;
>  
>   pr_debug("read bitmap file (%dB @ %llu)\n", (int)PAGE_SIZE,
>(unsigned long long)index << PAGE_SHIFT);
>  
> - bh = alloc_page_buffers(page, 1 + bh = head = alloc_page_buffers(page, 1   if (!bh) {
>   ret = -ENOMEM;
>   goto out;
>   }
>   attach_page_buffers(page, bh);
>   block = index << (PAGE_SHIFT - inode->i_blkbits);
> - while (bh) {
> + do {
>   if (count == 0)
>   bh->b_blocknr = 0;
>   else {
> @@ -400,7 +402,7 @@ static int read_page(struct file *file, unsigned long 
> index,
>   }
>   block++;
>   bh = bh->b_this_page;
> - }
> + } while (bh != head);
>   page->index = index;
>  
>   wait_event(bitmap->write_wait,
> -- 
> 2.6.2
>
Before
sean@linux-zmni:~/sda5/source/linus_repo/linux> size fs/buffer.o
   textdata bss dec hex filename
  336931466  16   351758967 fs/buffer.o
sean@linux-zmni:~/sda5/source/linus_repo/linux> size drivers/md/md-bitmap.o
   textdata bss dec hex filename
  281492168   0   30317766d drivers/md/md-bitmap.o
sean@linux-zmni:~/sda5/source/linus_repo/linux> size fs/ntfs/mft.o 
   textdata bss dec hex filename
   2133  36   02169 879 fs/ntfs/mft.o
sean@linux-zmni:~/sda5/source/linus_repo/linux> size fs/ntfs/aops.o
   textdata bss dec hex filename
   6125 168   062931895 fs/ntfs/aops.o
sean@linux-zmni:~/sda5/source/linus_repo/linux> size vmlinux
   textdata bss dec hex filename
114802605730762 1646084 1885710611fbc92 vmlinux
sean@linux-zmni:~/sda5/source/linus_repo/linux> size ./arch/x86/boot/bzImage
size: ./arch/x86/boot/bzImage: Warning: Ignoring section flag 
IMAGE_SCN_MEM_NOT_PAGED in section .bss
   textdata bss dec hex filename
6571744   0 16975648235473921674e00 ./arch/x86/boot/bzImage


After
sean@linux-zmni:~/sda5/source/linus_repo/linux> size fs/buffer.o 
   textdata bss dec hex filename
  336871466  16   351698961 fs/buffer.o
sean@linux-zmni:~/sda5/source/linus_repo/linux> size drivers

Re: [PATCH V3 04/12] perf mmap: introduce perf_mmap__read_done

2018-01-01 Thread Namhyung Kim
Hello,

On Thu, Dec 21, 2017 at 10:08:46AM -0800, kan.li...@intel.com wrote:
> From: Kan Liang 
> 
> The direction of overwrite mode is backward. The last mmap__read_event
> will set tail to map->prev. Need to correct the map->prev to head which
> is the end of next read.

Why do you update the map->prev needlessly then?  I think we don't
need it for overwrite/backward mode, right?

Also I guess the current code might miss some events since the head
can be different between _read_init() and _read_done(), no?

Thanks,
Namhyung


> 
> It will be used later.
> 
> Signed-off-by: Kan Liang 
> ---
>  tools/perf/util/mmap.c | 11 +++
>  tools/perf/util/mmap.h |  1 +
>  2 files changed, 12 insertions(+)
> 
> diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
> index a844a2f..4aaeb64 100644
> --- a/tools/perf/util/mmap.c
> +++ b/tools/perf/util/mmap.c
> @@ -343,3 +343,14 @@ int perf_mmap__push(struct perf_mmap *md, bool overwrite,
>  out:
>   return rc;
>  }
> +
> +/*
> + * Mandatory for overwrite mode
> + * The direction of overwrite mode is backward.
> + * The last mmap__read_event will set tail to map->prev.
> + * Need to correct the map->prev to head which is the end of next read.
> + */
> +void perf_mmap__read_done(struct perf_mmap *map)
> +{
> + map->prev = perf_mmap__read_head(map);
> +}
> diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h
> index abe9b9f..2df27c1 100644
> --- a/tools/perf/util/mmap.h
> +++ b/tools/perf/util/mmap.h
> @@ -96,4 +96,5 @@ size_t perf_mmap__mmap_len(struct perf_mmap *map);
>  
>  int perf_mmap__read_init(struct perf_mmap *map, bool overwrite,
>u64 *start, u64 *end);
> +void perf_mmap__read_done(struct perf_mmap *map);
>  #endif /*__PERF_MMAP_H */
> -- 
> 2.5.5
> 


[PATCH v2 2/2] clk: qcom: Configure the RCGs to a safe source as needed

2018-01-01 Thread Amit Nischal
For some root clock generators, there could be child branches which are
controlled by an entity other than application processor subsystem. For
such RCGs, as per application processor subsystem clock driver, all of its
downstream clocks are disabled and RCG is in disabled state but in actual
downstream clocks can be left enabled before.

So in this scenario, when RCG is disabled as per clock driver's point of
view and when rate scaling request comes before downstream clock enable
request, then RCG fails to update its configuration because in actual RCG
is on and it expects its new source to alredy in enable state  but in
reality new source is in off state. In order to avoid letting the RCG to
go into an invalid state, add support to just cache the rate of RCG during
set_rate(), defer actual RCG configuration update to be done during
clk_enable() as at this point of time, both its new parent and safe source
will be already enabled and RCG can safely switch to new parent.

During clk_disable() request, configure it to safe source as both
its parents, safe source and current parent will be enabled and RCG can
safely execute a switch. Also add support to have safe configuration
frequency table structure for each shared RCG.

Signed-off-by: Amit Nischal 
---
 drivers/clk/qcom/clk-rcg.h  |   8 ++-
 drivers/clk/qcom/clk-rcg2.c | 149 
 2 files changed, 156 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/qcom/clk-rcg.h b/drivers/clk/qcom/clk-rcg.h
index a249545..bb63bc0 100644
--- a/drivers/clk/qcom/clk-rcg.h
+++ b/drivers/clk/qcom/clk-rcg.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013, 2017, The Linux Foundation. All rights reserved.
  *
  * This software is licensed under the terms of the GNU General Public
  * License version 2, as published by the Free Software Foundation, and
@@ -156,6 +156,9 @@ struct clk_dyn_rcg {
  * @hid_width: number of bits in half integer divider
  * @parent_map: map from software's parent index to hardware's src_sel field
  * @freq_tbl: frequency table
+ * @current_freq: last cached frequency when using branches with shared RCGs
+ * @safe_src_freq_tbl : frequency table of safe source when using branches
+ * with shared RCGs
  * @clkr: regmap clock handle
  *
  */
@@ -165,6 +168,8 @@ struct clk_rcg2 {
u8  hid_width;
const struct parent_map *parent_map;
const struct freq_tbl   *freq_tbl;
+   unsigned long   current_freq;
+   const struct freq_tbl   *safe_src_freq_tbl;
struct clk_regmap   clkr;
 };

@@ -177,5 +182,6 @@ struct clk_rcg2 {
 extern const struct clk_ops clk_byte2_ops;
 extern const struct clk_ops clk_pixel_ops;
 extern const struct clk_ops clk_gfx3d_ops;
+extern const struct clk_ops clk_rcg2_shared_ops;

 #endif
diff --git a/drivers/clk/qcom/clk-rcg2.c b/drivers/clk/qcom/clk-rcg2.c
index ef8b14a..1816e10 100644
--- a/drivers/clk/qcom/clk-rcg2.c
+++ b/drivers/clk/qcom/clk-rcg2.c
@@ -790,3 +790,152 @@ static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned 
long rate,
.determine_rate = clk_gfx3d_determine_rate,
 };
 EXPORT_SYMBOL_GPL(clk_gfx3d_ops);
+
+static int clk_rcg2_set_force_enable(struct clk_hw *hw)
+{
+   struct clk_rcg2 *rcg = to_clk_rcg2(hw);
+   const char *name = clk_hw_get_name(hw);
+   int ret, count;
+
+   /* Force enable bit */
+   ret = regmap_update_bits(rcg->clkr.regmap, rcg->cmd_rcgr + CMD_REG,
+CMD_ROOT_EN, CMD_ROOT_EN);
+   if (ret)
+   return ret;
+
+   /* wait for RCG to turn ON */
+   for (count = 500; count > 0; count--) {
+   if (clk_rcg2_is_enabled(hw))
+   return 0;
+
+   /* Delay for 1usec and retry polling the status bit */
+   udelay(1);
+   }
+   if (!count)
+   pr_err("%s: RCG did not turn on\n", name);
+
+   return -ETIMEDOUT;
+}
+
+static int clk_rcg2_clear_force_enable(struct clk_hw *hw)
+{
+   struct clk_rcg2 *rcg = to_clk_rcg2(hw);
+
+   /* Clear force enable bit */
+   return regmap_update_bits(rcg->clkr.regmap, rcg->cmd_rcgr + CMD_REG,
+   CMD_ROOT_EN, 0);
+}
+
+static int
+clk_rcg2_shared_force_enable_clear(struct clk_hw *hw, unsigned long rate)
+{
+   int ret;
+
+   ret = clk_rcg2_set_force_enable(hw);
+   if (ret)
+   return ret;
+
+   /* set clock rate */
+   ret = __clk_rcg2_set_rate(hw, rate, CEIL);
+   if (ret)
+   return ret;
+
+   return clk_rcg2_clear_force_enable(hw);
+}
+
+static int clk_rcg2_shared_set_rate(struct clk_hw *hw, unsigned long rate,
+   unsigned long parent_rate)
+{
+   struct clk_rcg2 *rcg = to_clk_rcg2(hw);
+   int ret;
+
+   /*
+* Return if the RCG is currently disabled. This configuration
+  

[PATCH v2 1/2] clk: qcom: Clear hardware clock control bit of RCG

2018-01-01 Thread Amit Nischal
For upcoming targets like sdm845, POR value of the hardware clock control
bit is set for most of root clocks which needs to be cleared for software
to be able to control. For older targets like MSM8996, this bit is reserved
bit and having POR value as 0 so this patch will work for the older targets
too. So update the configuration mask to take care of the same to clear
hardware clock control bit.

Signed-off-by: Amit Nischal 
---
 drivers/clk/qcom/clk-rcg2.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/qcom/clk-rcg2.c b/drivers/clk/qcom/clk-rcg2.c
index bbeaf9c..ef8b14a 100644
--- a/drivers/clk/qcom/clk-rcg2.c
+++ b/drivers/clk/qcom/clk-rcg2.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013, 2017, The Linux Foundation. All rights reserved.
  *
  * This software is licensed under the terms of the GNU General Public
  * License version 2, as published by the Free Software Foundation, and
@@ -42,6 +42,7 @@
 #define CFG_MODE_SHIFT 12
 #define CFG_MODE_MASK  (0x3 << CFG_MODE_SHIFT)
 #define CFG_MODE_DUAL_EDGE (0x2 << CFG_MODE_SHIFT)
+#define CFG_HW_CLK_CTRL_MASK   BIT(20)

 #define M_REG  0x8
 #define N_REG  0xc
@@ -276,7 +277,7 @@ static int clk_rcg2_configure(struct clk_rcg2 *rcg, const 
struct freq_tbl *f)
}

mask = BIT(rcg->hid_width) - 1;
-   mask |= CFG_SRC_SEL_MASK | CFG_MODE_MASK;
+   mask |= CFG_SRC_SEL_MASK | CFG_MODE_MASK | CFG_HW_CLK_CTRL_MASK;
cfg = f->pre_div << CFG_SRC_DIV_SHIFT;
cfg |= rcg->parent_map[index].cfg << CFG_SRC_SEL_SHIFT;
if (rcg->mnd_width && f->n && (f->m != f->n))
--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation



[PATCH v2 0/2] clk: qcom: MISC RCG changes for SDM845

2018-01-01 Thread Amit Nischal
Changes in v2:
* Changed usage of clk_hw_is_prepared() to __clk_is_enabled()
  in clk_rcg2_shared_ops to fix build test error.

Changes in v1:
This patch series does the miscellaneous changes for RCGs
used in SDM845.

1. Clear hardware clock control bit of RCGs where HW clock
   control bit is set by default so that software can control
   those root clocks.
2. Introduces clk_rcg2_shared_ops to support clock controller
   drivers for SDM845. With new shared ops, RCGs with shared
   branches will be configured to a safe source in disable
   path and actual RCG update configuration will be done in
   enable path instead of doing config update in set_rate.
   In set_rate(), just cache the rate instead of doing actual
   configuration update. Also each RCG in clock controller
   driver will have their own safe configuration frequency
   table to switch to safe frequency.

Amit Nischal (2):
  clk: qcom: Clear hardware clock control bit of RCG
  clk: qcom: Configure the RCGs to a safe source as needed

 drivers/clk/qcom/clk-rcg.h  |   8 ++-
 drivers/clk/qcom/clk-rcg2.c | 154 +++-
 2 files changed, 159 insertions(+), 3 deletions(-)

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



Re: [PATCH v2 0/4] arm64: defconfig: enable additional led triggers

2018-01-01 Thread Amit Kucheria
On Thu, Dec 21, 2017 at 8:46 PM, Arnd Bergmann  wrote:
> On Wed, Dec 6, 2017 at 9:57 AM, Amit Kucheria  
> wrote:
>> (Adding Arnd)
>>
>> Now that the merge window rush has abated, can you please apply this
>> trivial series?
>>
>> On Mon, Nov 6, 2017 at 12:38 PM, Amit Kucheria  
>> wrote:
>>> This patchset enables the kernel panic and disk-activity trigger for LEDs
>>> and then enables the panic trigger for three 96Boards - DB410c, Hikey and
>>> Hikey960.
>>>
>>> DB410c and Hikey panic behaviour has been tested by triggering a panic
>>> through /proc/sysrq-trigger, while Hikey960 is only compile-tested.
>
> I applied all four now, but it would have been easier for me if you had either
> sent them to the platform maintainers, or to a...@kernel.org.

The platform maintainers are cc'ed but I guess nobody took them since
the patchset touched 3 different platforms and a common defconfig.

I'll remember to cc a...@kernel.org in the future but is there any
reason why this email address isn't listed in MAINTAINERS?

Thanks for applying the patches.

Wish you a Happy New Year.

Regards,
Amit


linux-next: Tree for Jan 2

2018-01-01 Thread Stephen Rothwell
Hi all,

Changes since 20171222:

New tree: iversion

The clk tree gained a build failure so I used the version from
next-20171222.

The vfs tree gained a conflict against Linus' tree

The v4l-dvb tree gained conflicts against the vfs tree.

The drm tree gained a build failure due to a bad automatic merge (of
the same patch from 2 trees), so I applied a merge fix patch.

The integrity tree gained a conflict against the iversion tree.

The spi tree lost its build failure.

The akpm tree gained a conflict against the vfs tree for which I dropped
a patch.

Non-merge commits (relative to Linus' tree): 6359
 6691 files changed, 251279 insertions(+), 181770 deletions(-)



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

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

Below is a summary of the state of the merge.

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

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

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

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

-- 
Cheers,
Stephen Rothwell

$ git checkout master
$ git reset --hard stable
Merging origin/master (30a7acd57389 Linux 4.15-rc6)
Merging fixes/master (820bf5c419e4 Merge tag 'scsi-fixes' of 
git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi)
Merging kbuild-current/fixes (cfe17c9bbe6a kbuild: move cc-option and 
cc-disable-warning after incl. arch Makefile)
Merging arc-current/for-curr (d3b388559fac ARC: handle gcc generated 
__builtin_trap for older compiler)
Merging arm-current/fixes (36b0cb84ee85 ARM: 8731/1: Fix 
csum_partial_copy_from_user() stack mismatch)
Merging m68k-current/for-linus (5e387199c17c m68k/defconfig: Update defconfigs 
for v4.14-rc7)
Merging metag-fixes/fixes (b884a190afce metag/usercopy: Add missing fixups)
Merging powerpc-fixes/fixes (7333b5aca412 KVM: PPC: Book3S HV: Fix pending_pri 
value in kvmppc_xive_get_icp())
Merging sparc/master (59585b4be9ae sparc64: repair calling incorrect hweight 
function from stubs)
Merging fscrypt-current/for-stable (42d97eb0ade3 fscrypt: fix renaming and 
linking special files)
Merging net/master (2758b3e3e630 Merge 
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net)
Merging bpf/master (2758b3e3e630 Merge 
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net)
Merging ipsec/master (2f10a61cee8f xfrm: fix rcu usage in xfrm_get_type_offload)
Merging netfilter/master (8bea728dce89 netfilter: nf_tables: fix potential 
NULL-ptr deref in nf_tables_dump_obj_done())
Merging ipvs/master (f7fb77fc1235 netfilter: nft_compat: check extension hook 
mask only if set)
Merging wireless-drivers/master (a41886f56b7b Merge tag 
'iwlwifi-for-kalle-2017-12-05' of 
git://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/iwlwifi-fixes)
Merging mac80211/master (04a7279ff12f cfg80211: ship certificates as hex files)
Merging sound-current/for-linus (44be77c590f3 ALSA: hda - Fix missing COEF init 
for ALC225/295/299)
Merging pci-current/for-linus (1291a0d5049d Linux 4.15-rc4)
Merging driver-core.current/driver-core-linus (9b3fa47d4a76 kobject: fix 
suppressing modalias in uevents delivered over netlink)
Merging tty.current/tty-linus (966031f34018 n_tty: fix EXTPROC vs ICANON 
interaction with TIOCINQ (aka FIONREAD))
Merging usb.current/usb-linus (da9970668948 usb: xhci: Add XHCI_TRUST_TX_LENGTH 
for Renesas uPD720201)
Merging usb-gadget-fixes/fixes (1291a0d5049d Linux 4.15-rc4)
Merging usb-serial-fixes/usb-linus (c6a36ad38355 USB: serial: ftdi_sio: add id 
for Airbus DS P8GR)
Merging usb-chipidea-fixes/ci-for-usb-stable (964728f9f407 USB: chipidea: msm: 
fix ulpi-node lookup)
Merging phy/fix

Re: [PATCH v7 3/5] clk: aspeed: Add platform driver and register PLLs

2018-01-01 Thread Benjamin Herrenschmidt
On Fri, 2017-12-22 at 13:15 +1030, Joel Stanley wrote:
> This registers a platform driver to set up all of the non-core clocks.
> 
> The clocks that have configurable rates are now registered.
> 
> Reviewed-by: Andrew Jeffery 
> Signed-off-by: Joel Stanley 

Reviewed-by: Benjamin Herrenschmidt 
> --
> v6:
>  - Add Andrew's reviewed-by
> v5:
>  - Remove eclk configuration. We do not have enough information to
>  correctly implement the mux and divisor, so it will have to be
>  implemented in the future
> v4:
>  - Add eclk div table to fix ast2500 calculation
>  - Add defines to document the BIT() macros
>  - Pass dev where we can when registering clocks
>  - Check for errors when registering clk_hws
> v3:
>  - Fix bclk and eclk calculation
>  - Separate out ast2400 and ast25000 for pll calculation
> ---
>  drivers/clk/clk-aspeed.c | 130 
> +++
>  1 file changed, 130 insertions(+)
> 
> diff --git a/drivers/clk/clk-aspeed.c b/drivers/clk/clk-aspeed.c
> index 5adedda82d26..cf5ea63feb31 100644
> --- a/drivers/clk/clk-aspeed.c
> +++ b/drivers/clk/clk-aspeed.c
> @@ -5,6 +5,8 @@
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -107,6 +109,18 @@ static const struct aspeed_gate_data aspeed_gates[] = {
>   [ASPEED_CLK_GATE_LHCCLK] =  { 28, -1, "lhclk-gate", 
> "lhclk", 0 }, /* LPC master/LPC+ */
>  };
>  
> +static const struct clk_div_table ast2500_mac_div_table[] = {
> + { 0x0, 4 }, /* Yep, really. Aspeed confirmed this is correct */
> + { 0x1, 4 },
> + { 0x2, 6 },
> + { 0x3, 8 },
> + { 0x4, 10 },
> + { 0x5, 12 },
> + { 0x6, 14 },
> + { 0x7, 16 },
> + { 0 }
> +};
> +
>  static const struct clk_div_table ast2400_div_table[] = {
>   { 0x0, 2 },
>   { 0x1, 4 },
> @@ -172,6 +186,122 @@ static struct clk_hw *aspeed_ast2500_calc_pll(const 
> char *name, u32 val)
>   mult, div);
>  }
>  
> +struct aspeed_clk_soc_data {
> + const struct clk_div_table *div_table;
> + const struct clk_div_table *mac_div_table;
> + struct clk_hw *(*calc_pll)(const char *name, u32 val);
> +};
> +
> +static const struct aspeed_clk_soc_data ast2500_data = {
> + .div_table = ast2500_div_table,
> + .mac_div_table = ast2500_mac_div_table,
> + .calc_pll = aspeed_ast2500_calc_pll,
> +};
> +
> +static const struct aspeed_clk_soc_data ast2400_data = {
> + .div_table = ast2400_div_table,
> + .mac_div_table = ast2400_div_table,
> + .calc_pll = aspeed_ast2400_calc_pll,
> +};
> +
> +static int aspeed_clk_probe(struct platform_device *pdev)
> +{
> + const struct aspeed_clk_soc_data *soc_data;
> + struct device *dev = &pdev->dev;
> + struct regmap *map;
> + struct clk_hw *hw;
> + u32 val, rate;
> +
> + map = syscon_node_to_regmap(dev->of_node);
> + if (IS_ERR(map)) {
> + dev_err(dev, "no syscon regmap\n");
> + return PTR_ERR(map);
> + }
> +
> + /* SoC generations share common layouts but have different divisors */
> + soc_data = of_device_get_match_data(dev);
> + if (!soc_data) {
> + dev_err(dev, "no match data for platform\n");
> + return -EINVAL;
> + }
> +
> + /* UART clock div13 setting */
> + regmap_read(map, ASPEED_MISC_CTRL, &val);
> + if (val & UART_DIV13_EN)
> + rate = 2400 / 13;
> + else
> + rate = 2400;
> + /* TODO: Find the parent data for the uart clock */
> + hw = clk_hw_register_fixed_rate(dev, "uart", NULL, 0, rate);
> + if (IS_ERR(hw))
> + return PTR_ERR(hw);
> + aspeed_clk_data->hws[ASPEED_CLK_UART] = hw;
> +
> + /*
> +  * Memory controller (M-PLL) PLL. This clock is configured by the
> +  * bootloader, and is exposed to Linux as a read-only clock rate.
> +  */
> + regmap_read(map, ASPEED_MPLL_PARAM, &val);
> + hw = soc_data->calc_pll("mpll", val);
> + if (IS_ERR(hw))
> + return PTR_ERR(hw);
> + aspeed_clk_data->hws[ASPEED_CLK_MPLL] = hw;
> +
> + /* SD/SDIO clock divider (TODO: There's a gate too) */
> + hw = clk_hw_register_divider_table(dev, "sdio", "hpll", 0,
> + scu_base + ASPEED_CLK_SELECTION, 12, 3, 0,
> + soc_data->div_table,
> + &aspeed_clk_lock);
> + if (IS_ERR(hw))
> + return PTR_ERR(hw);
> + aspeed_clk_data->hws[ASPEED_CLK_SDIO] = hw;
> +
> + /* MAC AHB bus clock divider */
> + hw = clk_hw_register_divider_table(dev, "mac", "hpll", 0,
> + scu_base + ASPEED_CLK_SELECTION, 16, 3, 0,
> + soc_data->mac_div_table,
> + &aspeed_clk_lock);
> + if (IS_ERR(hw))
> + return PTR_ERR(hw);
> + aspeed_clk_data->hws[ASPEED_CLK_MAC] = hw;
> +
> + /* LPC Host (LHCLK) clock divider */
> + hw = clk_hw_register_divider_table(dev, "lhclk", "hpll

linux-next: build warning after merge of the akpm-current tree

2018-01-01 Thread Stephen Rothwell
Hi Andrew,

After merging the akpm-current tree, today's linux-next build (arm
multi_v7_defconfig) produced this warning:

WARNING: vmlinux: 'abort' exported twice. Previous export was in vmlinux
WARNING: vmlinux: 'abort' exported twice. Previous export was in vmlinux

Introduced by commit

  3ff677e9abdf ("kernel/exit.c: export abort() to modules")

EXPORT_SYMBOL(abort) already exists in

arch/arc/kernel/traps.c
arch/arm/kernel/traps.c
arch/m32r/kernel/traps.c
arch/unicore32/kernel/traps.c

-- 
Cheers,
Stephen Rothwell


[PATCH 3/3] md: bitmap: Support circular buffer list.

2018-01-01 Thread Sean Fu
Modify write_page free_buffers and read_page to support circular buffer
list.

Signed-off-by: Sean Fu 
---
 drivers/md/md-bitmap.c | 36 +++-
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
index 239c7bb..b8412c2 100644
--- a/drivers/md/md-bitmap.c
+++ b/drivers/md/md-bitmap.c
@@ -286,7 +286,7 @@ static void bitmap_file_kick(struct bitmap *bitmap);
  */
 static void write_page(struct bitmap *bitmap, struct page *page, int wait)
 {
-   struct buffer_head *bh;
+   struct buffer_head *bh, *head;
 
if (bitmap->storage.file == NULL) {
switch (write_sb_page(bitmap, page, wait)) {
@@ -295,15 +295,16 @@ static void write_page(struct bitmap *bitmap, struct page 
*page, int wait)
}
} else {
 
-   bh = page_buffers(page);
+   bh = head = page_buffers(page);
 
-   while (bh && bh->b_blocknr) {
-   atomic_inc(&bitmap->pending_writes);
-   set_buffer_locked(bh);
-   set_buffer_mapped(bh);
-   submit_bh(REQ_OP_WRITE, REQ_SYNC, bh);
-   bh = bh->b_this_page;
-   }
+   do {
+   if (bh && bh->b_blocknr) {
+   atomic_inc(&bitmap->pending_writes);
+   set_buffer_locked(bh);
+   set_buffer_mapped(bh);
+   submit_bh(REQ_OP_WRITE, REQ_SYNC, bh);
+   }
+   } while ((bh = bh->b_this_page) != head);
 
if (wait)
wait_event(bitmap->write_wait,
@@ -333,17 +334,18 @@ __clear_page_buffers(struct page *page)
 }
 static void free_buffers(struct page *page)
 {
-   struct buffer_head *bh;
+   struct buffer_head *bh, *head;
 
if (!PagePrivate(page))
return;
 
-   bh = page_buffers(page);
-   while (bh) {
+   bh = head = page_buffers(page);
+   do {
struct buffer_head *next = bh->b_this_page;
free_buffer_head(bh);
bh = next;
-   }
+   } while (bh != head);
+
__clear_page_buffers(page);
put_page(page);
 }
@@ -362,20 +364,20 @@ static int read_page(struct file *file, unsigned long 
index,
 {
int ret = 0;
struct inode *inode = file_inode(file);
-   struct buffer_head *bh;
+   struct buffer_head *bh, *head;
sector_t block;
 
pr_debug("read bitmap file (%dB @ %llu)\n", (int)PAGE_SIZE,
 (unsigned long long)index << PAGE_SHIFT);
 
-   bh = alloc_page_buffers(page, 1i_blkbits);
-   while (bh) {
+   do {
if (count == 0)
bh->b_blocknr = 0;
else {
@@ -400,7 +402,7 @@ static int read_page(struct file *file, unsigned long index,
}
block++;
bh = bh->b_this_page;
-   }
+   } while (bh != head);
page->index = index;
 
wait_event(bitmap->write_wait,
-- 
2.6.2



[PATCH 0/3] Create circular buffer list for every page instead of linear list.

2018-01-01 Thread Sean Fu
1.Create circular buffer list in alloc_page_buffers.
Remove unnecessary traversal in link_dev_buffers to create circular buffer list.
Make nobh_write_begin and nobh_write_end to support circular buffer list.

2.fs/ntfs: Make ntfs to support circular buffer list.

3.md: bitmap: Support circular buffer list.
Modify write_page free_buffers and read_page to support circular buffer list.

Sean Fu (3):
  fs: buffer: Create circular buffer list for pages.
  fs/ntfs: Make ntfs to support circular buffer list.
  md: bitmap: Support circular buffer list.

 drivers/md/md-bitmap.c | 36 +++-
 fs/buffer.c| 48 +---
 fs/ntfs/aops.c |  6 ++
 fs/ntfs/mft.c  |  4 
 4 files changed, 42 insertions(+), 52 deletions(-)

-- 
2.6.2



[PATCH 2/3] fs/ntfs: Make ntfs to support circular buffer list.

2018-01-01 Thread Sean Fu
Modify mark_ntfs_record_dirty to support circular buffer list.
alloc_page_buffers created circular buffer list. So the circular list
linking in ntfs_sync_mft_mirror is unnecessary.

Signed-off-by: Sean Fu 
---
 fs/ntfs/aops.c | 6 ++
 fs/ntfs/mft.c  | 4 
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/fs/ntfs/aops.c b/fs/ntfs/aops.c
index 3a2e509..4e69577 100644
--- a/fs/ntfs/aops.c
+++ b/fs/ntfs/aops.c
@@ -1746,10 +1746,8 @@ void mark_ntfs_record_dirty(struct page *page, const 
unsigned int ofs) {
 
do {
set_buffer_uptodate(bh);
-   tail = bh;
bh = bh->b_this_page;
-   } while (bh);
-   tail->b_this_page = head;
+   } while (bh != head);
attach_page_buffers(page, head);
} else
buffers_to_free = bh;
@@ -1771,7 +1769,7 @@ void mark_ntfs_record_dirty(struct page *page, const 
unsigned int ofs) {
bh = buffers_to_free->b_this_page;
free_buffer_head(buffers_to_free);
buffers_to_free = bh;
-   } while (buffers_to_free);
+   } while (buffers_to_free != head);
}
 }
 
diff --git a/fs/ntfs/mft.c b/fs/ntfs/mft.c
index ee8392a..26ba4f6 100644
--- a/fs/ntfs/mft.c
+++ b/fs/ntfs/mft.c
@@ -505,15 +505,11 @@ int ntfs_sync_mft_mirror(ntfs_volume *vol, const unsigned 
long mft_no,
memcpy(kmirr, m, vol->mft_record_size);
/* Create uptodate buffers if not present. */
if (unlikely(!page_has_buffers(page))) {
-   struct buffer_head *tail;
-
bh = head = alloc_page_buffers(page, blocksize, true);
do {
set_buffer_uptodate(bh);
-   tail = bh;
bh = bh->b_this_page;
} while (bh);
-   tail->b_this_page = head;
attach_page_buffers(page, head);
}
bh = head = page_buffers(page);
-- 
2.6.2



[PATCH 1/3] fs: buffer: Create circular buffer list for pages.

2018-01-01 Thread Sean Fu
Make alloc_page_buffers to create circular buffer list instead linear
list.
Remove unnecessary traversal in link_dev_buffers to create circular
buffer list.
Make nobh_write_begin and nobh_write_end to support circular buffer list
traversal.

Signed-off-by: Sean Fu 
---
 fs/buffer.c | 48 +---
 1 file changed, 21 insertions(+), 27 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index 0736a6a..7e62c75 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -842,29 +842,36 @@ int remove_inode_buffers(struct inode *inode)
 struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size,
bool retry)
 {
-   struct buffer_head *bh, *head;
+   struct buffer_head *bh, *head, *tail;
gfp_t gfp = GFP_NOFS;
long offset;
 
if (retry)
gfp |= __GFP_NOFAIL;
 
-   head = NULL;
+   head = tail = NULL;
offset = PAGE_SIZE;
while ((offset -= size) >= 0) {
bh = alloc_buffer_head(gfp);
if (!bh)
goto no_grow;
 
-   bh->b_this_page = head;
+   if (unlikely(!head))
+   tail = bh;
+   else
+   bh->b_this_page = head;
+
bh->b_blocknr = -1;
head = bh;
-
bh->b_size = size;
 
/* Link the buffer to its page */
set_bh_page(bh, page, offset);
}
+
+   if (tail)
+   tail->b_this_page = head;
+
return head;
 /*
  * In case anything failed, we just free everything we got.
@@ -882,20 +889,6 @@ struct buffer_head *alloc_page_buffers(struct page *page, 
unsigned long size,
 }
 EXPORT_SYMBOL_GPL(alloc_page_buffers);
 
-static inline void
-link_dev_buffers(struct page *page, struct buffer_head *head)
-{
-   struct buffer_head *bh, *tail;
-
-   bh = head;
-   do {
-   tail = bh;
-   bh = bh->b_this_page;
-   } while (bh);
-   tail->b_this_page = head;
-   attach_page_buffers(page, head);
-}
-
 static sector_t blkdev_max_block(struct block_device *bdev, unsigned int size)
 {
sector_t retval = ~((sector_t)0);
@@ -993,7 +986,7 @@ grow_dev_page(struct block_device *bdev, sector_t block,
 * run under the page lock.
 */
spin_lock(&inode->i_mapping->private_lock);
-   link_dev_buffers(page, bh);
+   attach_page_buffers(page, bh);
end_block = init_page_buffers(page, bdev, (sector_t)index << sizebits,
size);
spin_unlock(&inode->i_mapping->private_lock);
@@ -1533,16 +1526,14 @@ EXPORT_SYMBOL(block_invalidatepage);
 void create_empty_buffers(struct page *page,
unsigned long blocksize, unsigned long b_state)
 {
-   struct buffer_head *bh, *head, *tail;
+   struct buffer_head *bh, *head;
 
head = alloc_page_buffers(page, blocksize, true);
bh = head;
do {
bh->b_state |= b_state;
-   tail = bh;
bh = bh->b_this_page;
-   } while (bh);
-   tail->b_this_page = head;
+   } while (bh != head);
 
spin_lock(&page->mapping->private_lock);
if (PageUptodate(page) || PageDirty(page)) {
@@ -2655,11 +2646,14 @@ int nobh_write_begin(struct address_space *mapping,
 * any VM or truncate activity.  Hence we don't need to care
 * for the buffer_head refcounts.
 */
-   for (bh = head; bh; bh = bh->b_this_page) {
+   bh = head;
+   do {
wait_on_buffer(bh);
if (!buffer_uptodate(bh))
ret = -EIO;
-   }
+   bh = bh->b_this_page;
+   } while (bh != head);
+
if (ret)
goto failed;
}
@@ -2717,11 +2711,11 @@ int nobh_write_end(struct file *file, struct 
address_space *mapping,
unlock_page(page);
put_page(page);
 
-   while (head) {
+   do {
bh = head;
head = head->b_this_page;
free_buffer_head(bh);
-   }
+   } while (head != fsdata);
 
return copied;
 }
-- 
2.6.2



Re: [PATCH] Input: misc: Kconfig: fixed a spelling mistake

2018-01-01 Thread Dmitry Torokhov
On Thu, Dec 28, 2017 at 04:30:50PM +0800, Zhuohua Li wrote:
> fixed a spelling mistake: buttong -> button
> 
> Signed-off-by: Zhuohua Li 

Applied, thank you.

> ---
>  drivers/input/misc/Kconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
> index 9f082a388388..509ba8ef1464 100644
> --- a/drivers/input/misc/Kconfig
> +++ b/drivers/input/misc/Kconfig
> @@ -468,7 +468,7 @@ config INPUT_TPS65218_PWRBUTTON
>   tristate "TPS65218 Power button driver"
>   depends on (MFD_TPS65217 || MFD_TPS65218)
>   help
> -   Say Y here if you want to enable power buttong reporting for
> +   Say Y here if you want to enable power button reporting for
> TPS65217 and TPS65218 Power Management IC devices.
>  
> To compile this driver as a module, choose M here. The module will
> -- 
> 2.13.6
> 

-- 
Dmitry


[PATCH v6 3/3] fs: fat: add ioctl method in fat filesystem driver

2018-01-01 Thread ChenGuanqiao
Signed-off-by: ChenGuanqiao 
---
 fs/fat/file.c | 150 ++
 1 file changed, 150 insertions(+)

diff --git a/fs/fat/file.c b/fs/fat/file.c
index 4724cc9ad650..829c91ef1ea0 100644
--- a/fs/fat/file.c
+++ b/fs/fat/file.c
@@ -15,11 +15,36 @@
 #include 
 #include 
 #include 
+#include 
 #include "fat.h"

 static long fat_fallocate(struct file *file, int mode,
  loff_t offset, loff_t len);

+static int fat_check_d_characters(char *label, unsigned long len)
+{
+   int i;
+
+   for (i=0; ivol_id, user_attr);
 }

+static int fat_ioctl_get_volume_label(struct inode *inode,
+ u8 __user *vol_label)
+{
+   int err = 0;
+   struct buffer_head *bh;
+   struct msdos_dir_entry *de;
+
+   inode_lock_shared(inode);
+   err = fat_scan_volume_label(inode, &bh, &de);
+   if (err)
+   goto out;
+
+   if (copy_to_user(vol_label, de->name, MSDOS_NAME))
+   err = -EFAULT;
+
+   brelse(bh);
+out:
+   inode_unlock_shared(inode);
+
+   return err;
+}
+
+static int fat_ioctl_set_volume_label(struct file *file,
+ u8 __user *vol_label)
+{
+   int err = 0;
+   u8 label[MSDOS_NAME];
+   struct buffer_head *boot_bh;
+   struct buffer_head *vol_bh;
+   struct msdos_dir_entry *de;
+   struct fat_boot_sector *b;
+   struct inode *inode = file_inode(file);
+   struct super_block *sb = inode->i_sb;
+   struct msdos_sb_info *sbi = MSDOS_SB(sb);
+
+   if (inode->i_ino != MSDOS_ROOT_INO) {
+   err = -EINVAL;
+   goto out;
+   }
+
+   if (copy_from_user(label, vol_label, sizeof(label))) {
+   err = -EFAULT;
+   goto out;
+   }
+
+   err = fat_check_d_characters(label, sizeof(label));
+   if (err)
+   goto out;
+
+   err = mnt_want_write_file(file);
+   if (err)
+   goto out;
+
+   down_write(&sb->s_umount);
+   inode_lock(inode);
+
+   /* Updates root directory's vol_label */
+   err = fat_scan_volume_label(inode, &vol_bh, &de);
+   if (err) {
+   /* Create volume label entry */
+   struct timespec ts;
+
+   mutex_lock(&sbi->s_lock);
+   ts = current_time(inode);
+   err = fat_add_volume_label_entry(inode, label, &ts);
+   mutex_unlock(&sbi->s_lock);
+
+   if (err)
+   goto out_vol_brelse;
+   } else {
+   /* Write to root directory */
+   lock_buffer(vol_bh);
+   memcpy(de->name, label, sizeof(de->name));
+   mark_buffer_dirty(vol_bh);
+   unlock_buffer(vol_bh);
+   }
+
+   /* Update sector's vol_label */
+   boot_bh = sb_bread(sb, 0);
+   if (boot_bh == NULL) {
+   fat_msg(sb, KERN_ERR,
+   "unable to read boot sector to write volume label");
+   err = -EIO;
+   goto out_boot_brelse;
+   }
+
+   b = (struct fat_boot_sector *)boot_bh->b_data;
+   lock_buffer(boot_bh);
+   if (sbi->fat_bits == 32)
+   memcpy(b->fat32.vol_label, label, sizeof(label));
+   else
+   memcpy(b->fat16.vol_label, label, sizeof(label));
+
+   mark_buffer_dirty(boot_bh);
+   unlock_buffer(boot_bh);
+
+   /* Synchronize the data together */
+   err = sync_dirty_buffer(boot_bh);
+   if (err)
+   goto out_boot_brelse;
+
+   err = sync_dirty_buffer(vol_bh);
+   if (err)
+   goto out_boot_brelse;
+
+   /* Flush sbi */
+   memcpy(sbi->vol_label, label, sizeof(sbi->vol_label));
+
+out_boot_brelse:
+   brelse(boot_bh);
+out_vol_brelse:
+   brelse(vol_bh);
+
+   inode_unlock(inode);
+   up_write(&sb->s_umount);
+   mnt_drop_write_file(file);
+out:
+   return err;
+}
+
 long fat_generic_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
struct inode *inode = file_inode(filp);
u32 __user *user_attr = (u32 __user *)arg;
+   u8 __user *user_vol_label = (u8 __user *)arg;

switch (cmd) {
case FAT_IOCTL_GET_ATTRIBUTES:
@@ -133,6 +279,10 @@ long fat_generic_ioctl(struct file *filp, unsigned int 
cmd, unsigned long arg)
return fat_ioctl_set_attributes(filp, user_attr);
case FAT_IOCTL_GET_VOLUME_ID:
return fat_ioctl_get_volume_id(inode, user_attr);
+   case FAT_IOCTL_GET_VOLUME_LABEL:
+   return fat_ioctl_get_volume_label(inode, user_vol_label);
+   case FAT_IOCTL_SET_VOLUME_LABEL:
+   return fat_ioctl_set_volume_label(filp, user_vol_label);
default:
return -ENOTTY; /* Inappropriate ioctl for device */
}
--
2.11.0




[PATCH v6 2/3] fs: fat: Add volume label entry method function

2018-01-01 Thread ChenGuanqiao
Signed-off-by: ChenGuanqiao 
---
 fs/fat/dir.c | 62 
 1 file changed, 62 insertions(+)

diff --git a/fs/fat/dir.c b/fs/fat/dir.c
index 81cecbe6d7cf..63aab656c08e 100644
--- a/fs/fat/dir.c
+++ b/fs/fat/dir.c
@@ -881,6 +881,68 @@ static int fat_get_short_entry(struct inode *dir, loff_t 
*pos,
return -ENOENT;
 }

+static int fat_get_volume_label_entry(struct inode *dir, loff_t *pos,
+  struct buffer_head **bh,
+  struct msdos_dir_entry **de)
+{
+   while (fat_get_entry(dir, pos, bh, de) >= 0) {
+   if (((*de)->attr & ATTR_VOLUME) && (*de)->attr != ATTR_EXT)
+   return 0;
+   }
+   return -ENOENT;
+}
+
+int fat_scan_volume_label(struct inode *dir, struct buffer_head **bh,
+ struct msdos_dir_entry **de)
+{
+   loff_t offset = 0;
+
+   if (dir->i_ino != MSDOS_ROOT_INO)
+   return -EINVAL;
+
+   *bh = NULL;
+   *de = NULL;
+   while (fat_get_volume_label_entry(dir, &offset, bh, de) >= 0)
+   return 0;
+
+   return -ENOENT;
+}
+EXPORT_SYMBOL_GPL(fat_scan_volume_label);
+
+int fat_add_volume_label_entry(struct inode *dir, const unsigned char *name,
+  struct timespec *ts)
+{
+   struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb);
+   struct msdos_dir_entry de;
+   struct fat_slot_info sinfo;
+   __le16 time, date;
+   int err;
+
+   if (dir->i_ino != MSDOS_ROOT_INO)
+   return -EINVAL;
+
+   memcpy(de.name, name, MSDOS_NAME);
+   de.attr = ATTR_VOLUME;
+   de.lcase = 0;
+   fat_time_unix2fat(sbi, ts, &time, &date, NULL);
+   de.cdate = de.adate = 0;
+   de.ctime = 0;
+   de.ctime_cs = 0;
+   de.time = time;
+   de.date = date;
+   fat_set_start(&de, 0);
+   de.size = 0;
+
+   err = fat_add_entries(dir, &de, 1, &sinfo);
+   if (err)
+   return err;
+
+   dir->i_ctime = dir->i_mtime = *ts;
+
+   return fat_sync_inode(dir);
+}
+EXPORT_SYMBOL_GPL(fat_add_volume_label_entry);
+
 /*
  * The ".." entry can not provide the "struct fat_slot_info" information
  * for inode, nor a usable i_pos. So, this function provides some information
--
2.11.0


Re: [PATCH] f2fs: check segment type before recover data

2018-01-01 Thread Chao Yu
On 2017/12/30 15:42, Yunlong Song wrote:
> In some case, the node blocks has wrong blkaddr whose segment type is

You mean *data block* has wrong blkaddr whose segment type is NODE?

> NODE, e.g., recover inode has missing xattr flag and the blkaddr is in
> the xattr range. Since fsck.f2fs does not check the recovery nodes, this
> will cause __f2fs_replace_block change the curseg of node and do the
> update_sit_entry(sbi, new_blkaddr, 1) with no next_blkoff refresh, as a

Do you mean the root cause is that __f2fs_replace_block didn't update
next_blkoff?

> result, when recovery process write checkpoint and sync nodes, the
> next_blkoff of curseg is used in the segment bit map, then it will
> cause f2fs_bug_on. So let's check the segment type before recover data,
> and stop recover if it is not in DATA segment.

Sorry, I can't catch the whole cause and effect from you description, if
possible, could you give an example?

Thanks,

> 
> Signed-off-by: Yunlong Song 
> ---
>  fs/f2fs/recovery.c | 3 ++-
>  fs/f2fs/segment.h  | 3 +++
>  2 files changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c
> index 7d63faf..e8fee4a 100644
> --- a/fs/f2fs/recovery.c
> +++ b/fs/f2fs/recovery.c
> @@ -478,7 +478,8 @@ static int do_recover_data(struct f2fs_sb_info *sbi, 
> struct inode *inode,
>   }
>  
>   /* dest is valid block, try to recover from src to dest */
> - if (is_valid_blkaddr(sbi, dest, META_POR)) {
> + if (is_valid_blkaddr(sbi, dest, META_POR) &&
> + is_data_blkaddr(sbi, dest)) {
>  
>   if (src == NULL_ADDR) {
>   err = reserve_new_block(&dn);
> diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
> index 71a2aaa..5c5a215 100644
> --- a/fs/f2fs/segment.h
> +++ b/fs/f2fs/segment.h
> @@ -115,6 +115,9 @@
>  #define SECTOR_TO_BLOCK(sectors) \
>   ((sectors) >> F2FS_LOG_SECTORS_PER_BLOCK)
>  
> +#define is_data_blkaddr(sbi, blkaddr)\
> + (IS_DATASEG(get_seg_entry(sbi, GET_SEGNO(sbi, blkaddr))->type))
> +
>  /*
>   * indicate a block allocation direction: RIGHT and LEFT.
>   * RIGHT means allocating new sections towards the end of volume.
> 



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

2018-01-01 Thread Stephen Rothwell
Hi Andrew,

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

  ipc/mqueue.c

between commits:

  3ec41d6c2257 ("tidy do_mq_open() up a bit")
  946086abeddf ("mqueue: switch to on-demand creation of internal mount")

from the vfs tree and patch:

  "ipc, mqueue: lazy call kern_mount_data in new namespaces"

from the akpm tree.

I fixed it up (I could not see how to fix this obviously, so I just
dropped the akpm tree patch) 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


Re: [PATCH v5 2/3] input: evdev: Replace timeval with timespec64

2018-01-01 Thread Dmitry Torokhov
Hi Deepa,

On Sun, Dec 17, 2017 at 09:18:43PM -0800, Deepa Dinamani wrote:
> struct timeval is not y2038 safe.
> 
> All references to timeval in the kernel will be replaced
> by y2038 safe structures.
> Replace all references to timeval with y2038 safe
> struct timespec64 here.
> 
> struct input_event will be changed in a different patch.
> 
> Signed-off-by: Deepa Dinamani 
> Reviewed-by: Arnd Bergmann 
> Acked-by: Peter Hutterer 
> ---
>  drivers/input/evdev.c | 37 +++--
>  1 file changed, 23 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
> index 0193dd4f0452..3171c4882d80 100644
> --- a/drivers/input/evdev.c
> +++ b/drivers/input/evdev.c
> @@ -156,15 +156,22 @@ static void __evdev_flush_queue(struct evdev_client 
> *client, unsigned int type)
>  static void __evdev_queue_syn_dropped(struct evdev_client *client)
>  {
>   struct input_event ev;
> - ktime_t time;
> + struct timespec64 ts;
>  
> - time = client->clk_type == EV_CLK_REAL ?
> - ktime_get_real() :
> - client->clk_type == EV_CLK_MONO ?
> - ktime_get() :
> - ktime_get_boottime();
> + switch (client->clk_type) {
> + case EV_CLK_REAL:
> + ktime_get_real_ts64(&ts);
> + break;
> + case EV_CLK_MONO:
> + ktime_get_ts64(&ts);
> + break;
> + case EV_CLK_BOOT:
> + get_monotonic_boottime64(&ts);
> + break;
> + }
>  
> - ev.time = ktime_to_timeval(time);
> + ev.time.tv_sec = ts.tv_sec;
> + ev.time.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
>   ev.type = EV_SYN;
>   ev.code = SYN_DROPPED;
>   ev.value = 0;
> @@ -257,17 +264,20 @@ static void __pass_event(struct evdev_client *client,
>  
>  static void evdev_pass_values(struct evdev_client *client,
>   const struct input_value *vals, unsigned int count,
> - ktime_t *ev_time)
> + struct timespec64 *ev_time)
>  {
>   struct evdev *evdev = client->evdev;
>   const struct input_value *v;
>   struct input_event event;
> + struct timespec64 ts;
>   bool wakeup = false;
>  
>   if (client->revoked)
>   return;
>  
> - event.time = ktime_to_timeval(ev_time[client->clk_type]);
> + ts = ev_time[client->clk_type];
> + event.time.tv_sec = ts.tv_sec;
> + event.time.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
>  
>   /* Interrupts are disabled, just acquire the lock. */
>   spin_lock(&client->buffer_lock);
> @@ -304,12 +314,11 @@ static void evdev_events(struct input_handle *handle,
>  {
>   struct evdev *evdev = handle->private;
>   struct evdev_client *client;
> - ktime_t ev_time[EV_CLK_MAX];
> + struct timespec64 ev_time[EV_CLK_MAX];
>  
> - ev_time[EV_CLK_MONO] = ktime_get();
> - ev_time[EV_CLK_REAL] = ktime_mono_to_real(ev_time[EV_CLK_MONO]);
> - ev_time[EV_CLK_BOOT] = ktime_mono_to_any(ev_time[EV_CLK_MONO],
> -  TK_OFFS_BOOT);
> + ktime_get_ts64(&ev_time[EV_CLK_MONO]);
> + ktime_get_real_ts64(&ev_time[EV_CLK_REAL]);
> + get_monotonic_boottime64(&ev_time[EV_CLK_BOOT]);

This may result in different ev_time[] members holding different times,
whereas the original code would take one time sample and convert it to
different clocks.

Also, why can't we keep using ktime_t internally? It is y2038 safe,
right? I think you should drop this patch and adjust the 3rd one to
massage the input event timestamp patch to do ktime->timespec64->input
timestamp conversion.

Thanks.

-- 
Dmitry


Re: [PATCH v5 1/3] uinput: Use monotonic times for uinput timestamps.

2018-01-01 Thread Dmitry Torokhov
On Sun, Dec 17, 2017 at 09:18:42PM -0800, Deepa Dinamani wrote:
> struct timeval which is part of struct input_event to
> maintain the event times is not y2038 safe.
> 
> Real time timestamps are also not ideal for input_event
> as this time can go backwards as noted in the patch
> a80b83b7b8 by John Stultz.
> 
> The patch switches the timestamps to use monotonic time
> from realtime time. This is assuming no one is using
> absolute times from these timestamps.
> 
> The structure to maintain input events will be changed
> in a different patch.
> 
> Signed-off-by: Deepa Dinamani 
> Acked-by: Peter Hutterer 

Applied, thank you.

> ---
>  drivers/input/misc/uinput.c | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
> index 91df0df15e68..9251765645d1 100644
> --- a/drivers/input/misc/uinput.c
> +++ b/drivers/input/misc/uinput.c
> @@ -84,11 +84,14 @@ static int uinput_dev_event(struct input_dev *dev,
>   unsigned int type, unsigned int code, int value)
>  {
>   struct uinput_device*udev = input_get_drvdata(dev);
> + struct timespec64   ts;
>  
>   udev->buff[udev->head].type = type;
>   udev->buff[udev->head].code = code;
>   udev->buff[udev->head].value = value;
> - do_gettimeofday(&udev->buff[udev->head].time);
> + ktime_get_ts64(&ts);
> + udev->buff[udev->head].time.tv_sec = ts.tv_sec;
> + udev->buff[udev->head].time.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
>   udev->head = (udev->head + 1) % UINPUT_BUFFER_SIZE;
>  
>   wake_up_interruptible(&udev->waitq);
> -- 
> 2.14.1
> 

-- 
Dmitry


Re: [PATCH] ACPI / sysfs: fix shift-overflow in GPE flooding quirk mechanism

2018-01-01 Thread Du, Changbin
Hi Wysocki and Brown,
May I know wether you have checked this? Thanks!

On Fri, Dec 22, 2017 at 11:11:10PM +0800, changbin...@intel.com wrote:
> From: Changbin Du 
> 
> The ACPI_MASKABLE_GPE_MAX is larger than the number of bits that u64 can
> represent. This result in shift-overflow. So actually we need a bitmap.
> 
> [1.003153] 
> ==
> [1.003257] UBSAN: Undefined behaviour in drivers/acpi/sysfs.c:849:33
> [1.003314] shift exponent 64 is too large for 64-bit type 'long long 
> unsigned int'
> [1.003381] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.15.0-rc4+ #40
> [1.003436] Hardware name: LENOVO 20HAS02515/20HAS02515, BIOS N1VET36W 
> (1.26 ) 10/03/2017
> [1.003504] Call Trace:
> [1.003542]  dump_stack+0xe3/0x177
> [1.003582]  ? _atomic_dec_and_lock+0x219/0x219
> [1.003653]  ubsan_epilogue+0xd/0x4e
> [1.003695]  __ubsan_handle_shift_out_of_bounds+0x1f8/0x23d
> [1.003754]  ? __ubsan_handle_load_invalid_value+0x13b/0x13b
> [1.003817]  ? trace_hardirqs_on_caller+0x1f3/0x370
> [1.003868]  ? trace_hardirqs_on+0xd/0x10
> [1.003917]  ? up+0xe9/0x160
> [1.003957]  ? sugov_should_update_freq+0xa1/0x1f0
> [1.004000]  ? trace_hardirqs_on+0xd/0x10
> [1.004000]  acpi_gpe_apply_masked_gpes+0xa4/0x125
> [1.004000]  ? acpi_gpe_apply_masked_gpes+0xa4/0x125
> [1.004000]  ? acpi_gpe_set_masked_gpes+0xe3/0xe3
> [1.004000]  ? acpi_get_table+0x111/0x127
> [1.004000]  acpi_scan_init+0x299/0x598
> [1.004000]  ? acpi_match_madt+0xae/0xae
> [1.004000]  ? sysfs_add_file_mode_ns+0x160/0x320
> [1.004000]  ? kobject_put+0x23/0x220
> [1.004000]  ? bus_create_file+0x75/0x90
> [1.004000]  ? bus_register+0x44a/0x540
> [1.004000]  ? subsys_register.part.1+0x140/0x140
> [1.004000]  acpi_init+0x532/0x5d8
> [1.004000]  ? acpi_sleep_proc_init+0x36/0x36
> [1.004000]  ? console_trylock+0x60/0x60
> [1.004000]  ? sysfs_add_file_mode_ns+0x160/0x320
> [1.004000]  ? sysfs_create_file_ns+0x56/0x80
> [1.004000]  ? video_setup+0x13c/0x13c
> [1.004000]  ? fb_console_init+0x16c/0x1fc
> [1.004000]  ? acpi_sleep_proc_init+0x36/0x36
> [1.004000]  do_one_initcall+0xae/0x282
> [1.004000]  ? initcall_blacklisted+0x1c0/0x1c0
> [1.004000]  ? up_write+0x92/0x100
> [1.004000]  ? down_write_nested+0x110/0x110
> [1.004000]  ? kasan_unpoison_shadow+0x35/0x50
> [1.004000]  kernel_init_freeable+0x4af/0x573
> [1.004000]  ? start_kernel+0x6b1/0x6b1
> [1.004000]  ? rest_init+0x100/0x100
> [1.004000]  kernel_init+0x13/0x13d
> [1.004000]  ? rest_init+0x100/0x100
> [1.004000]  ? rest_init+0x100/0x100
> [1.004000]  ret_from_fork+0x24/0x30
> [1.004000] 
> ==
> 
> Fixes: 9c4aa1eecb48 ("ACPI / sysfs: Provide quirk mechanism to prevent GPE 
> flooding")
> Signed-off-by: Changbin Du 
> ---
>  drivers/acpi/sysfs.c | 7 ---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
> index 06a150b..60ade0b 100644
> --- a/drivers/acpi/sysfs.c
> +++ b/drivers/acpi/sysfs.c
> @@ -823,7 +823,7 @@ static ssize_t counter_set(struct kobject *kobj,
>   */
>  #define ACPI_MASKABLE_GPE_MAX0x80
>  
> -static u64 __initdata acpi_masked_gpes;
> +static __initdata DECLARE_BITMAP(acpi_masked_gpes, ACPI_MASKABLE_GPE_MAX);
>  
>  static int __init acpi_gpe_set_masked_gpes(char *val)
>  {
> @@ -831,7 +831,8 @@ static int __init acpi_gpe_set_masked_gpes(char *val)
>  
>   if (kstrtou8(val, 0, &gpe) || gpe > ACPI_MASKABLE_GPE_MAX)
>   return -EINVAL;
> - acpi_masked_gpes |= ((u64)1< +
> + set_bit(gpe, acpi_masked_gpes);
>  
>   return 1;
>  }
> @@ -846,7 +847,7 @@ void __init acpi_gpe_apply_masked_gpes(void)
>   for (gpe = 0;
>gpe < min_t(u8, ACPI_MASKABLE_GPE_MAX, acpi_current_gpe_count);
>gpe++) {
> - if (acpi_masked_gpes & ((u64)1< + if (test_bit(gpe, acpi_masked_gpes)) {
>   status = acpi_get_gpe_device(gpe, &handle);
>   if (ACPI_SUCCESS(status)) {
>   pr_info("Masking GPE 0x%x.\n", gpe);
> -- 
> 2.7.4
> 

-- 
Thanks,
Changbin Du


[PATCH v6 0/3] fs: fat: add ioctl to modify fat filesystem partion volume label

2018-01-01 Thread ChenGuanqiao
The FAT filesystem partition volume label can be read with
FAT_IOCTL_GET_VOLUME_LABEL and written with FAT_IOCTL_SET_VOLUME_LABEL.

FAT volume label (volume name) is exactly same stored in boot sector and root
directory. Thus, the boot sector just needs to be upgrade when the label
writing.

v6:
1. fixed volume label name check function.
2. add volume label entry if no volume label.
v5:
1. find the volume label entry through the scan function.
2. the volume label only retains the d-characters (reference from Ecma-107).
v4:
1. read/write volume label from/to the location of the respective version.
2. correct volume label check reference from mkfs.fat.
3. fixed some code issue.
v3:
1. write volume label both boot sector and root directory.
v2:
1. add filesystem version check.
2. add diretory permissions check.
3. add volume label string check.
4. fixed part of return value.
5. fixed some indent issue.
6. remove sync_dirty_buffer().

ChenGuanqiao (3):
  fs: fat: Add fat filesystem partition volume label in local structure
  fs: fat: Add volume label entry method function
  fs: fat: add ioctl method in fat filesystem driver

 fs/fat/dir.c  |  62 +
 fs/fat/fat.h  |   6 ++
 fs/fat/file.c | 150 ++
 fs/fat/inode.c|  15 -
 include/uapi/linux/msdos_fs.h |   2 +
 5 files changed, 232 insertions(+), 3 deletions(-)

--
2.11.0




[PATCH v6 1/3] fs: fat: Add fat filesystem partition volume label in local structure

2018-01-01 Thread ChenGuanqiao
Signed-off-by: ChenGuanqiao 
---
 fs/fat/fat.h  |  6 ++
 fs/fat/inode.c| 15 ---
 include/uapi/linux/msdos_fs.h |  2 ++
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/fs/fat/fat.h b/fs/fat/fat.h
index 051dac1ce3be..0b7b635742fc 100644
--- a/fs/fat/fat.h
+++ b/fs/fat/fat.h
@@ -85,6 +85,7 @@ struct msdos_sb_info {
int dir_per_block;/* dir entries per block */
int dir_per_block_bits;   /* log2(dir_per_block) */
unsigned int vol_id;/*volume ID*/
+   char vol_label[11]; /*volume label*/

int fatent_shift;
const struct fatent_operations *fatent_ops;
@@ -299,6 +300,11 @@ extern int fat_dir_empty(struct inode *dir);
 extern int fat_subdirs(struct inode *dir);
 extern int fat_scan(struct inode *dir, const unsigned char *name,
struct fat_slot_info *sinfo);
+extern int fat_scan_volume_label(struct inode *dir, struct buffer_head **bh,
+struct msdos_dir_entry **de);
+extern int fat_add_volume_label_entry(struct inode*dir,
+ const unsigned char *name,
+ struct timespec *ts);
 extern int fat_scan_logstart(struct inode *dir, int i_logstart,
 struct fat_slot_info *sinfo);
 extern int fat_get_dotdot_entry(struct inode *dir, struct buffer_head **bh,
diff --git a/fs/fat/inode.c b/fs/fat/inode.c
index 30c52394a7ad..e73379a41d49 100644
--- a/fs/fat/inode.c
+++ b/fs/fat/inode.c
@@ -45,12 +45,14 @@ struct fat_bios_param_block {

u8  fat16_state;
u32 fat16_vol_id;
+   u8  fat16_vol_label[11];

u32 fat32_length;
u32 fat32_root_cluster;
u16 fat32_info_sector;
u8  fat32_state;
u32 fat32_vol_id;
+   u8  fat32_vol_label[11];
 };

 static int fat_default_codepage = CONFIG_FAT_DEFAULT_CODEPAGE;
@@ -1460,12 +1462,16 @@ static int fat_read_bpb(struct super_block *sb, struct 
fat_boot_sector *b,

bpb->fat16_state = b->fat16.state;
bpb->fat16_vol_id = get_unaligned_le32(b->fat16.vol_id);
+   memcpy(bpb->fat16_vol_label, b->fat16.vol_label,
+  sizeof(bpb->fat16_vol_label));

bpb->fat32_length = le32_to_cpu(b->fat32.length);
bpb->fat32_root_cluster = le32_to_cpu(b->fat32.root_cluster);
bpb->fat32_info_sector = le16_to_cpu(b->fat32.info_sector);
bpb->fat32_state = b->fat32.state;
bpb->fat32_vol_id = get_unaligned_le32(b->fat32.vol_id);
+   memcpy(bpb->fat32_vol_label, b->fat32.vol_label,
+  sizeof(bpb->fat32_vol_label));

/* Validate this looks like a FAT filesystem BPB */
if (!bpb->fat_reserved) {
@@ -1723,11 +1729,14 @@ int fat_fill_super(struct super_block *sb, void *data, 
int silent, int isvfat,
brelse(fsinfo_bh);
}

-   /* interpret volume ID as a little endian 32 bit integer */
-   if (sbi->fat_bits == 32)
+   /* interpret volume ID and label as a little endian 32 bit integer */
+   if (sbi->fat_bits == 32) {
sbi->vol_id = bpb.fat32_vol_id;
-   else /* fat 16 or 12 */
+   memcpy(sbi->vol_label, bpb.fat32_vol_label, 
sizeof(sbi->vol_label));
+   } else { /* fat 16 or 12 */
sbi->vol_id = bpb.fat16_vol_id;
+   memcpy(sbi->vol_label, bpb.fat16_vol_label, 
sizeof(sbi->vol_label));
+   }

sbi->dir_per_block = sb->s_blocksize / sizeof(struct msdos_dir_entry);
sbi->dir_per_block_bits = ffs(sbi->dir_per_block) - 1;
diff --git a/include/uapi/linux/msdos_fs.h b/include/uapi/linux/msdos_fs.h
index e956704f5fb1..b4fced0988a9 100644
--- a/include/uapi/linux/msdos_fs.h
+++ b/include/uapi/linux/msdos_fs.h
@@ -106,6 +106,8 @@ struct __fat_dirent {
 #define FAT_IOCTL_SET_ATTRIBUTES   _IOW('r', 0x11, __u32)
 /*Android kernel has used 0x12, so we use 0x13*/
 #define FAT_IOCTL_GET_VOLUME_ID_IOR('r', 0x13, __u32)
+#define FAT_IOCTL_GET_VOLUME_LABEL _IOR('r', 0x14, __u8[11])
+#define FAT_IOCTL_SET_VOLUME_LABEL _IOW('r', 0x15, __u8[11])

 struct fat_boot_sector {
__u8ignored[3]; /* Boot strap short or near jump */
--
2.11.0




Re: [PATCH V8 3/3] OPP: Allow "opp-hz" and "opp-microvolt" to contain magic values

2018-01-01 Thread Viresh Kumar
On 02-01-18, 11:35, Rajendra Nayak wrote:
> I would want to reiterate what I have been saying for a while, that for these 
> patches
> to be usable on any qualcomm platform completely we need support to associate
> multiple power-domains to a single device which is missing today.

Sure, but I had the understanding based on our last communication that
you are going to go with partial support for now and multiple domain
thing will be done later on.

> What I have been testing with these patches is to move a single user (MMC, 
> which BTW does not
> have to put requests on multiple powerdomains) to use this solution on a 
> db820c (msm8996) device.

Right.

> Getting this merged now can open up issues for other devices (which can't 
> move to this solution)
> since MMC alone would put requests to pull a *common* rail up/down while 
> others can't.

Even on that I thought that you will artificially vote for a high
requirement for those devices from some platform code initially, and
remove that code once all the device drivers (you need) are updated to
post their own requirements.

-- 
viresh


Re: [f2fs-dev v2] [PATCH 1/2] f2fs: stop checkpoint only from fault injection

2018-01-01 Thread Chao Yu
On 2018/1/1 9:31, Jaegeuk Kim wrote:
> We can give another chance to write user data, which can resolve
> generic/441.
> 
> Signed-off-by: Jaegeuk Kim 

Reviewed-by: Chao Yu 

Thanks,



[PATCH] nvme-pci: fix the timeout case when reset is ongoing

2018-01-01 Thread Jianchao Wang
NVME_CTRL_RESETTING used to indicate the range of nvme initializing
strictly in fd634f41(nvme: merge probe_work and reset_work), but it
is not now. The NVME_CTRL_RESETTING is set before queue the
reset_work, there could be a big gap before the reset work handles
the outstanding requests. So when the NVME_CTRL_RESETTING is set,
nvme_timeout will not only meet the admin requests from the
initializing procedure, but also the IO and admin requests from
previous work before nvme_dev_disable is invoked.

To fix it, introduce a flag NVME_DEV_FLAG_INITIALIZING to mark the
range of initializing. When this flag is not set, handle the expried
requests as nvme_cancel_request. Otherwise, the requests should be
from the initializing procedure. Handle them as before. Because the
nvme_reset_work will see the error and disable the dev itself, so
discard the nvme_dev_disable here.

Signed-off-by: Jianchao Wang 
---
 drivers/nvme/host/pci.c | 26 +-
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index f5800c3..6e58de1 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -99,6 +99,9 @@ struct nvme_dev {
struct nvme_ctrl ctrl;
struct completion ioq_wait;
 
+   unsigned long flag;
+#define NVME_DEV_FLAG_INITIALIZING 0
+
/* shadow doorbell buffer support: */
u32 *dbbuf_dbs;
dma_addr_t dbbuf_dbs_dma_addr;
@@ -1207,17 +1210,19 @@ static enum blk_eh_timer_return nvme_timeout(struct 
request *req, bool reserved)
}
 
/*
-* Shutdown immediately if controller times out while starting. The
-* reset work will see the pci device disabled when it gets the forced
-* cancellation error. All outstanding requests are completed on
-* shutdown, so we return BLK_EH_HANDLED.
+* There could be two kinds of expired reqs when reset is ongoing.
+* Outstanding IO or admin requests from previous work before the
+* nvme_reset_work invokes nvme_dev_disable. Handle them as the
+* nvme_cancel_request. Outstanding admin requests from the
+* initializing procedure. Set NVME_REQ_CANCELLED flag on them,
+* then nvme_reset_work will see the error, then disable the device
+* and remove the ctrl.
 */
if (dev->ctrl.state == NVME_CTRL_RESETTING) {
-   dev_warn(dev->ctrl.device,
-"I/O %d QID %d timeout, disable controller\n",
-req->tag, nvmeq->qid);
-   nvme_dev_disable(dev, false);
-   nvme_req(req)->flags |= NVME_REQ_CANCELLED;
+   if (test_bit(NVME_DEV_FLAG_INITIALIZING, &dev->flag))
+   nvme_req(req)->flags |= NVME_REQ_CANCELLED;
+   else
+   nvme_req(req)->status = NVME_SC_ABORT_REQ;
return BLK_EH_HANDLED;
}
 
@@ -2302,6 +2307,7 @@ static void nvme_reset_work(struct work_struct *work)
if (dev->ctrl.ctrl_config & NVME_CC_ENABLE)
nvme_dev_disable(dev, false);
 
+   set_bit(NVME_DEV_FLAG_INITIALIZING, &dev->flag);
result = nvme_pci_enable(dev);
if (result)
goto out;
@@ -2366,10 +2372,12 @@ static void nvme_reset_work(struct work_struct *work)
goto out;
}
 
+   clear_bit(NVME_DEV_FLAG_INITIALIZING, &dev->flag);
nvme_start_ctrl(&dev->ctrl);
return;
 
  out:
+   clear_bit(NVME_DEV_FLAG_INITIALIZING, &dev->flag);
nvme_remove_dead_ctrl(dev, result);
 }
 
-- 
2.7.4



Re: [f2fs-dev] [PATCH v3] f2fs: add reserved blocks for root user

2018-01-01 Thread Chao Yu
On 2018/1/1 9:29, Jaegeuk Kim wrote:
> This patch allows root to reserve some blocks via mount option.
> 
> "-o reserve_root=N" means N x 4KB-sized blocks for root only.
> 
> Signed-off-by: Jaegeuk Kim 
> ---
> 
> Change log from v2:
>  - wrong submission. :P
> 
>  fs/f2fs/f2fs.h  | 26 ++
>  fs/f2fs/super.c | 26 +++---
>  fs/f2fs/sysfs.c |  3 ++-
>  3 files changed, 47 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 5f7f42267221..123d875f7293 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -95,6 +95,7 @@ extern char *fault_name[FAULT_MAX];
>  #define F2FS_MOUNT_PRJQUOTA  0x0020
>  #define F2FS_MOUNT_QUOTA 0x0040
>  #define F2FS_MOUNT_INLINE_XATTR_SIZE 0x0080
> +#define F2FS_MOUNT_RESERVE_ROOT  0x0100
>  
>  #define clear_opt(sbi, option)   ((sbi)->mount_opt.opt &= 
> ~F2FS_MOUNT_##option)
>  #define set_opt(sbi, option) ((sbi)->mount_opt.opt |= F2FS_MOUNT_##option)
> @@ -1110,6 +,7 @@ struct f2fs_sb_info {
>   block_t last_valid_block_count; /* for recovery */
>   block_t reserved_blocks;/* configurable reserved blocks 
> */
>   block_t current_reserved_blocks;/* current reserved blocks */
> + block_t root_reserved_blocks;   /* root reserved blocks */
>  
>   unsigned int nquota_files;  /* # of quota sysfile */
>  
> @@ -1562,6 +1564,12 @@ static inline bool f2fs_has_xattr_block(unsigned int 
> ofs)
>   return ofs == XATTR_NODE_OFFSET;
>  }
>  
> +static inline block_t reserve_root_limit(struct f2fs_sb_info *sbi)
> +{
> + /* limit is 0.2% */

Should be 2% according to below calculation?

> + return (sbi->user_block_count << 1) / 100;
> +}
> +
>  static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool);
>  static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
>struct inode *inode, blkcnt_t *count)
> @@ -1591,11 +1599,17 @@ static inline int inc_valid_block_count(struct 
> f2fs_sb_info *sbi,
>   sbi->total_valid_block_count += (block_t)(*count);
>   avail_user_block_count = sbi->user_block_count -
>   sbi->current_reserved_blocks;
> +
> + if (!(test_opt(sbi, RESERVE_ROOT) && capable(CAP_SYS_RESOURCE)))

How about adding uid & gid verification also like ext4?

As this is a mount option, in ->remount_fs, we should consider to recover
original reserved block number if we encounter some error during remount.

Thanks,

> + avail_user_block_count -= sbi->root_reserved_blocks;
> +
>   if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) {
>   diff = sbi->total_valid_block_count - avail_user_block_count;
> + if (diff > *count)
> + diff = *count;
>   *count -= diff;
>   release = diff;
> - sbi->total_valid_block_count = avail_user_block_count;
> + sbi->total_valid_block_count -= diff;
>   if (!*count) {
>   spin_unlock(&sbi->stat_lock);
>   percpu_counter_sub(&sbi->alloc_valid_block_count, diff);
> @@ -1784,9 +1798,13 @@ static inline int inc_valid_node_count(struct 
> f2fs_sb_info *sbi,
>  
>   spin_lock(&sbi->stat_lock);
>  
> - valid_block_count = sbi->total_valid_block_count + 1;
> - if (unlikely(valid_block_count + sbi->current_reserved_blocks >
> - sbi->user_block_count)) {
> + valid_block_count = sbi->total_valid_block_count +
> + sbi->current_reserved_blocks + 1;
> +
> + if (!(test_opt(sbi, RESERVE_ROOT) && capable(CAP_SYS_RESOURCE)))
> + valid_block_count += sbi->root_reserved_blocks;
> +
> + if (unlikely(valid_block_count > sbi->user_block_count)) {
>   spin_unlock(&sbi->stat_lock);
>   goto enospc;
>   }
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index cb876d905ca5..9221b013db98 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -107,6 +107,7 @@ enum {
>   Opt_noextent_cache,
>   Opt_noinline_data,
>   Opt_data_flush,
> + Opt_reserve_root,
>   Opt_mode,
>   Opt_io_size_bits,
>   Opt_fault_injection,
> @@ -157,6 +158,7 @@ static match_table_t f2fs_tokens = {
>   {Opt_noextent_cache, "noextent_cache"},
>   {Opt_noinline_data, "noinline_data"},
>   {Opt_data_flush, "data_flush"},
> + {Opt_reserve_root, "reserve_root=%u"},
>   {Opt_mode, "mode=%s"},
>   {Opt_io_size_bits, "io_bits=%u"},
>   {Opt_fault_injection, "fault_injection=%u"},
> @@ -488,6 +490,12 @@ static int parse_options(struct super_block *sb, char 
> *options)
>   case Opt_data_flush:
>   set_opt(sbi, DATA_FLUSH);
>   break;
> + case Opt_reserve_root:
> +  

[PATCH -next] dm raid: make local symbol raid_sets static

2018-01-01 Thread Wei Yongjun
Fixes the following sparse warning:

drivers/md/dm-raid.c:33:1: warning:
 symbol 'raid_sets' was not declared. Should it be static?

Signed-off-by: Wei Yongjun 
---
 drivers/md/dm-raid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
index a96ca44..7ef469e 100644
--- a/drivers/md/dm-raid.c
+++ b/drivers/md/dm-raid.c
@@ -30,7 +30,7 @@
 #defineMIN_RAID456_JOURNAL_SPACE (4*2048)
 
 /* Global list of all raid sets */
-LIST_HEAD(raid_sets);
+static LIST_HEAD(raid_sets);
 
 static bool devices_handle_discard_safely = false;



Re: [PATCH V8 3/3] OPP: Allow "opp-hz" and "opp-microvolt" to contain magic values

2018-01-01 Thread Rajendra Nayak


On 12/28/2017 10:07 AM, Viresh Kumar wrote:
> On 27-12-17, 15:54, Rob Herring wrote:
>> On Wed, Dec 27, 2017 at 2:56 AM, Viresh Kumar  
>> wrote:
>>> On 26-12-17, 14:29, Rob Herring wrote:
 On Mon, Dec 18, 2017 at 03:51:30PM +0530, Viresh Kumar wrote:
>>>
> +On some platforms the exact frequency or voltage may be hidden from the 
> OS by
> +the firmware and the "opp-hz" or the "opp-microvolt" properties may 
> contain
> +magic values that represent the frequency or voltage in a firmware 
> dependent
> +way, for example an index of an array in the firmware.

 I'm still not convinced this is a good idea.
>>>
>>> You were kind-of a few days back :)
>>>
>>> lkml.kernel.org/r/CAL_JsqK-qtAaM_Ou5NtxcWR3F_q=8rmpjum-vqgtkhbtwe5...@mail.gmail.com
>>
>> Yeah, well that was before Stephen said anything.
>>
>>> So here is the deal:
>>>
>>> - I proposed "domain-performance-state" property for this stuff
>>>   initially.
>>> - But Kevin didn't like that and proposed reusing "opp-hz" and
>>>   "opp-microvolt", which we all agreed to multiple times..
>>> - And we are back to the same discussion now and its painful and time
>>>   killing for all of us.
>>
>> There's bigger issues than where we put magic values as I raised in
>> the other patch.
>>
>>> TBH, I don't have too strong preferences about any of the suggestions
>>> you guys have and I need you guys to tell me what binding changes to
>>> do here and I will do that.
>>>
 If you have firmware
 partially managing things, then I think we should have platform specific
 bindings or drivers.
>>>
>>> What about the initial idea then, like "performance-state" for the
>>> power domains ? All platforms will anyway replicate that binding only.
>>
>> I don't really know. I don't really care either. I'll probably go
>> along with what everyone agrees to, but the only one I see any
>> agreement from is Ulf. Also, it is pretty vague as to what platforms
>> will use this. You claimed you can support QCom scenarios, but there's
>> really no evidence that that is true.
> 
> Well, I sent out the code few days back based on these bindings and everyone 
> can
> see how these bindings will get used now.
> 
>> What I don't want to see is this
>> merged and then we need something more yet again in a few months for
>> another platform.
> 
> Sure, I get your concerns.
> 
> So what we need now is:
> 
> - Stephen to start responding and clarify all the doubts he had as being 
> silent
>   isn't helping.
> 
> - Or Rajendra to post patches which can prove that this is usable. The last 
> time
>   I had a chat with him, he confirmed that he will post patches after 4.15-rc1
>   and he should have posted them by now, but he didn't :(

I would want to reiterate what I have been saying for a while, that for these 
patches
to be usable on any qualcomm platform completely we need support to associate
multiple power-domains to a single device which is missing today.

The last time this came up during a discussion at connect, I believe the 
understanding
was to get this (performance state support) merged *after* we decide how to 
support
multiple powerdomains per device.

What I have been testing with these patches is to move a single user (MMC, 
which BTW does not
have to put requests on multiple powerdomains) to use this solution on a db820c 
(msm8996) device.
Getting this merged now can open up issues for other devices (which can't move 
to this solution)
since MMC alone would put requests to pull a *common* rail up/down while others 
can't.

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


Re: [alsa-devel] [PATCH 15/27] ALSA: hda - Use timecounter_initialize interface

2018-01-01 Thread Sagar Arun Kamble



On 12/28/2017 10:19 PM, Richard Cochran wrote:

On Tue, Dec 26, 2017 at 01:07:35PM +0530, Sagar Arun Kamble wrote:

Or can we provide simpler versions for covering some defaults?  At
least reducing the number of arguments would make things easier.

Thought about specifying 1. cyclecounter read func 2. frequency 3. width of
counter as parameters here
which can get rid of mult, shift params. But this is not easy as most of the
drivers do not specify
cyclecounter frequency and instead hard-code the mult/shift factors.

You are talking about using clocks_calc_mult_shift() here, right? (See
the usage example in drivers/net/ethernet/ti/cpts.c).

Yes

This is a good idea, and it is worth getting the driver authors' input
to figure out the correct parameters.

I bet we can use that almost everywhere.  If there are any drivers
that cannot be converted, then we can leave some sort of low level
legacy initialization method.

Agree

Thanks,
Richard





Re: [PATCH v7 4/5] clk: aspeed: Register gated clocks

2018-01-01 Thread Benjamin Herrenschmidt
On Fri, 2017-12-22 at 13:15 +1030, Joel Stanley wrote:
> The majority of the clocks in the system are gates paired with a reset
> controller that holds the IP in reset.
> 
> This borrows from clk_hw_register_gate, but registers two 'gates', one
> to control the clock enable register and the other to control the reset
> IP. This allows us to enforce the ordering:
> 
>  1. Place IP in reset
>  2. Enable clock
>  3. Delay
>  4. Release reset
> 
> There are some gates that do not have an associated reset; these are
> handled by using -1 as the index for the reset.
> 
> Reviewed-by: Andrew Jeffery 
> Signed-off-by: Joel Stanley 

Reviewed-by: Benjamin Herrenschmidt 
> ---
> v7:
>  - Use mdelay instead of msleep and remove the todo. Stephen points out:
> > No you can't sleep here. It needs to delay because this is inside
> > spinlock_irqsave.
> v5:
>   - Add Andrew's Reviewed-by
> v4:
>  - Drop useless 'disable clock' comment
>  - Drop CLK_IS_BASIC flag
>  - Fix 'there are a number of clocks...' comment
>  - Pass device to clk registration functions
>  - Check for errors when registering clk_hws
> v3:
>  - Remove gates offset as gates are now at the start of the list
> 
> mdelay
> 
> Signed-off-by: Joel Stanley 
> ---
>  drivers/clk/clk-aspeed.c | 130 
> +++
>  1 file changed, 130 insertions(+)
> 
> diff --git a/drivers/clk/clk-aspeed.c b/drivers/clk/clk-aspeed.c
> index cf5ea63feb31..dbd3c7774831 100644
> --- a/drivers/clk/clk-aspeed.c
> +++ b/drivers/clk/clk-aspeed.c
> @@ -204,6 +204,106 @@ static const struct aspeed_clk_soc_data ast2400_data = {
>   .calc_pll = aspeed_ast2400_calc_pll,
>  };
>  
> +static int aspeed_clk_enable(struct clk_hw *hw)
> +{
> + struct aspeed_clk_gate *gate = to_aspeed_clk_gate(hw);
> + unsigned long flags;
> + u32 clk = BIT(gate->clock_idx);
> + u32 rst = BIT(gate->reset_idx);
> +
> + spin_lock_irqsave(gate->lock, flags);
> +
> + if (gate->reset_idx >= 0) {
> + /* Put IP in reset */
> + regmap_update_bits(gate->map, ASPEED_RESET_CTRL, rst, rst);
> +
> + /* Delay 100us */
> + udelay(100);
> + }
> +
> + /* Enable clock */
> + regmap_update_bits(gate->map, ASPEED_CLK_STOP_CTRL, clk, 0);
> +
> + if (gate->reset_idx >= 0) {
> + /* A delay of 10ms is specified by the ASPEED docs */
> + mdelay(10);
> +
> + /* Take IP out of reset */
> + regmap_update_bits(gate->map, ASPEED_RESET_CTRL, rst, 0);
> + }
> +
> + spin_unlock_irqrestore(gate->lock, flags);
> +
> + return 0;
> +}
> +
> +static void aspeed_clk_disable(struct clk_hw *hw)
> +{
> + struct aspeed_clk_gate *gate = to_aspeed_clk_gate(hw);
> + unsigned long flags;
> + u32 clk = BIT(gate->clock_idx);
> +
> + spin_lock_irqsave(gate->lock, flags);
> +
> + regmap_update_bits(gate->map, ASPEED_CLK_STOP_CTRL, clk, clk);
> +
> + spin_unlock_irqrestore(gate->lock, flags);
> +}
> +
> +static int aspeed_clk_is_enabled(struct clk_hw *hw)
> +{
> + struct aspeed_clk_gate *gate = to_aspeed_clk_gate(hw);
> + u32 clk = BIT(gate->clock_idx);
> + u32 reg;
> +
> + regmap_read(gate->map, ASPEED_CLK_STOP_CTRL, ®);
> +
> + return (reg & clk) ? 0 : 1;
> +}
> +
> +static const struct clk_ops aspeed_clk_gate_ops = {
> + .enable = aspeed_clk_enable,
> + .disable = aspeed_clk_disable,
> + .is_enabled = aspeed_clk_is_enabled,
> +};
> +
> +static struct clk_hw *aspeed_clk_hw_register_gate(struct device *dev,
> + const char *name, const char *parent_name, unsigned long flags,
> + struct regmap *map, u8 clock_idx, u8 reset_idx,
> + u8 clk_gate_flags, spinlock_t *lock)
> +{
> + struct aspeed_clk_gate *gate;
> + struct clk_init_data init;
> + struct clk_hw *hw;
> + int ret;
> +
> + gate = kzalloc(sizeof(*gate), GFP_KERNEL);
> + if (!gate)
> + return ERR_PTR(-ENOMEM);
> +
> + init.name = name;
> + init.ops = &aspeed_clk_gate_ops;
> + init.flags = flags;
> + init.parent_names = parent_name ? &parent_name : NULL;
> + init.num_parents = parent_name ? 1 : 0;
> +
> + gate->map = map;
> + gate->clock_idx = clock_idx;
> + gate->reset_idx = reset_idx;
> + gate->flags = clk_gate_flags;
> + gate->lock = lock;
> + gate->hw.init = &init;
> +
> + hw = &gate->hw;
> + ret = clk_hw_register(dev, hw);
> + if (ret) {
> + kfree(gate);
> + hw = ERR_PTR(ret);
> + }
> +
> + return hw;
> +}
> +
>  static int aspeed_clk_probe(struct platform_device *pdev)
>  {
>   const struct aspeed_clk_soc_data *soc_data;
> @@ -211,6 +311,7 @@ static int aspeed_clk_probe(struct platform_device *pdev)
>   struct regmap *map;
>   struct clk_hw *hw;
>   u32 val, rate;
> + int i;
>  
>   map = syscon_node_to_regmap(dev->of_node);
>   if (IS_ERR(map)) {
> @@ -283,6 +384,35 @@

Re: [PATCH v7 5/5] clk: aspeed: Add reset controller

2018-01-01 Thread Benjamin Herrenschmidt
On Fri, 2017-12-22 at 13:15 +1030, Joel Stanley wrote:
> There are some resets that are not associated with gates. These are
> represented by a reset controller.
> 
> Reviewed-by: Andrew Jeffery 
> Signed-off-by: Joel Stanley 


Reviewed-by: Benjamin Herrenschmidt 

> ---
> v7:
>   - Rebase on dt-bindings patch
> v5:
>   - Add Andrew's Reviewed-by
> v3:
>   - Add named initalisers for the reset defines
>   - Add define for ADC
> ---
>  drivers/clk/clk-aspeed.c | 82 
> +++-
>  1 file changed, 81 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/clk/clk-aspeed.c b/drivers/clk/clk-aspeed.c
> index dbd3c7774831..6fb344730cea 100644
> --- a/drivers/clk/clk-aspeed.c
> +++ b/drivers/clk/clk-aspeed.c
> @@ -8,6 +8,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  
> @@ -267,6 +268,68 @@ static const struct clk_ops aspeed_clk_gate_ops = {
>   .is_enabled = aspeed_clk_is_enabled,
>  };
>  
> +/**
> + * struct aspeed_reset - Aspeed reset controller
> + * @map: regmap to access the containing system controller
> + * @rcdev: reset controller device
> + */
> +struct aspeed_reset {
> + struct regmap   *map;
> + struct reset_controller_dev rcdev;
> +};
> +
> +#define to_aspeed_reset(p) container_of((p), struct aspeed_reset, rcdev)
> +
> +static const u8 aspeed_resets[] = {
> + [ASPEED_RESET_XDMA] = 25,
> + [ASPEED_RESET_MCTP] = 24,
> + [ASPEED_RESET_ADC]  = 23,
> + [ASPEED_RESET_JTAG_MASTER] = 22,
> + [ASPEED_RESET_MIC]  = 18,
> + [ASPEED_RESET_PWM]  =  9,
> + [ASPEED_RESET_PCIVGA]   =  8,
> + [ASPEED_RESET_I2C]  =  2,
> + [ASPEED_RESET_AHB]  =  1,
> +};
> +
> +static int aspeed_reset_deassert(struct reset_controller_dev *rcdev,
> +  unsigned long id)
> +{
> + struct aspeed_reset *ar = to_aspeed_reset(rcdev);
> + u32 rst = BIT(aspeed_resets[id]);
> +
> + return regmap_update_bits(ar->map, ASPEED_RESET_CTRL, rst, 0);
> +}
> +
> +static int aspeed_reset_assert(struct reset_controller_dev *rcdev,
> +unsigned long id)
> +{
> + struct aspeed_reset *ar = to_aspeed_reset(rcdev);
> + u32 rst = BIT(aspeed_resets[id]);
> +
> + return regmap_update_bits(ar->map, ASPEED_RESET_CTRL, rst, rst);
> +}
> +
> +static int aspeed_reset_status(struct reset_controller_dev *rcdev,
> +unsigned long id)
> +{
> + struct aspeed_reset *ar = to_aspeed_reset(rcdev);
> + u32 val, rst = BIT(aspeed_resets[id]);
> + int ret;
> +
> + ret = regmap_read(ar->map, ASPEED_RESET_CTRL, &val);
> + if (ret)
> + return ret;
> +
> + return !!(val & rst);
> +}
> +
> +static const struct reset_control_ops aspeed_reset_ops = {
> + .assert = aspeed_reset_assert,
> + .deassert = aspeed_reset_deassert,
> + .status = aspeed_reset_status,
> +};
> +
>  static struct clk_hw *aspeed_clk_hw_register_gate(struct device *dev,
>   const char *name, const char *parent_name, unsigned long flags,
>   struct regmap *map, u8 clock_idx, u8 reset_idx,
> @@ -308,10 +371,11 @@ static int aspeed_clk_probe(struct platform_device 
> *pdev)
>  {
>   const struct aspeed_clk_soc_data *soc_data;
>   struct device *dev = &pdev->dev;
> + struct aspeed_reset *ar;
>   struct regmap *map;
>   struct clk_hw *hw;
>   u32 val, rate;
> - int i;
> + int i, ret;
>  
>   map = syscon_node_to_regmap(dev->of_node);
>   if (IS_ERR(map)) {
> @@ -319,6 +383,22 @@ static int aspeed_clk_probe(struct platform_device *pdev)
>   return PTR_ERR(map);
>   }
>  
> + ar = devm_kzalloc(dev, sizeof(*ar), GFP_KERNEL);
> + if (!ar)
> + return -ENOMEM;
> +
> + ar->map = map;
> + ar->rcdev.owner = THIS_MODULE;
> + ar->rcdev.nr_resets = ARRAY_SIZE(aspeed_resets);
> + ar->rcdev.ops = &aspeed_reset_ops;
> + ar->rcdev.of_node = dev->of_node;
> +
> + ret = devm_reset_controller_register(dev, &ar->rcdev);
> + if (ret) {
> + dev_err(dev, "could not register reset controller\n");
> + return ret;
> + }
> +
>   /* SoC generations share common layouts but have different divisors */
>   soc_data = of_device_get_match_data(dev);
>   if (!soc_data) {


Re: [PATCH v7 2/5] clk: aspeed: Register core clocks

2018-01-01 Thread Benjamin Herrenschmidt
On Fri, 2017-12-22 at 13:15 +1030, Joel Stanley wrote:
> This registers the core clocks; those which are required to calculate
> the rate of the timer peripheral so the system can load a clocksource
> driver.
> 
> Reviewed-by: Andrew Jeffery 
> Signed-off-by: Joel Stanley 

Reviewed-by: Benjamin Herrenschmidt 

> ---
> v5:
>   - Add Andrew's Reviewed-by
> v4:
>   - Add defines to document the BIT() macros
> v3:
>   - Fix ast2400 ahb calculation
>   - Remove incorrect 'this is wrong' comment
>   - Separate out clkin calc to be per platform
>   - Support 48MHz clkin on ast2400
> ---
>  drivers/clk/clk-aspeed.c | 177 
> +++
>  1 file changed, 177 insertions(+)
> 
> diff --git a/drivers/clk/clk-aspeed.c b/drivers/clk/clk-aspeed.c
> index 7a86ee08ea4f..5adedda82d26 100644
> --- a/drivers/clk/clk-aspeed.c
> +++ b/drivers/clk/clk-aspeed.c
> @@ -13,7 +13,23 @@
>  
>  #define ASPEED_NUM_CLKS  35
>  
> +#define ASPEED_RESET_CTRL0x04
> +#define ASPEED_CLK_SELECTION 0x08
> +#define ASPEED_CLK_STOP_CTRL 0x0c
> +#define ASPEED_MPLL_PARAM0x20
> +#define ASPEED_HPLL_PARAM0x24
> +#define  AST2500_HPLL_BYPASS_EN  BIT(20)
> +#define  AST2400_HPLL_STRAPPED   BIT(18)
> +#define  AST2400_HPLL_BYPASS_EN  BIT(17)
> +#define ASPEED_MISC_CTRL 0x2c
> +#define  UART_DIV13_EN   BIT(12)
>  #define ASPEED_STRAP 0x70
> +#define  CLKIN_25MHZ_EN  BIT(23)
> +#define  AST2400_CLK_SOURCE_SEL  BIT(18)
> +#define ASPEED_CLK_SELECTION_2   0xd8
> +
> +/* Globally visible clocks */
> +static DEFINE_SPINLOCK(aspeed_clk_lock);
>  
>  /* Keeps track of all clocks */
>  static struct clk_hw_onecell_data *aspeed_clk_data;
> @@ -91,6 +107,160 @@ static const struct aspeed_gate_data aspeed_gates[] = {
>   [ASPEED_CLK_GATE_LHCCLK] =  { 28, -1, "lhclk-gate", 
> "lhclk", 0 }, /* LPC master/LPC+ */
>  };
>  
> +static const struct clk_div_table ast2400_div_table[] = {
> + { 0x0, 2 },
> + { 0x1, 4 },
> + { 0x2, 6 },
> + { 0x3, 8 },
> + { 0x4, 10 },
> + { 0x5, 12 },
> + { 0x6, 14 },
> + { 0x7, 16 },
> + { 0 }
> +};
> +
> +static const struct clk_div_table ast2500_div_table[] = {
> + { 0x0, 4 },
> + { 0x1, 8 },
> + { 0x2, 12 },
> + { 0x3, 16 },
> + { 0x4, 20 },
> + { 0x5, 24 },
> + { 0x6, 28 },
> + { 0x7, 32 },
> + { 0 }
> +};
> +
> +static struct clk_hw *aspeed_ast2400_calc_pll(const char *name, u32 val)
> +{
> + unsigned int mult, div;
> +
> + if (val & AST2400_HPLL_BYPASS_EN) {
> + /* Pass through mode */
> + mult = div = 1;
> + } else {
> + /* F = 24Mhz * (2-OD) * [(N + 2) / (D + 1)] */
> + u32 n = (val >> 5) & 0x3f;
> + u32 od = (val >> 4) & 0x1;
> + u32 d = val & 0xf;
> +
> + mult = (2 - od) * (n + 2);
> + div = d + 1;
> + }
> + return clk_hw_register_fixed_factor(NULL, name, "clkin", 0,
> + mult, div);
> +};
> +
> +static struct clk_hw *aspeed_ast2500_calc_pll(const char *name, u32 val)
> +{
> + unsigned int mult, div;
> +
> + if (val & AST2500_HPLL_BYPASS_EN) {
> + /* Pass through mode */
> + mult = div = 1;
> + } else {
> + /* F = clkin * [(M+1) / (N+1)] / (P + 1) */
> + u32 p = (val >> 13) & 0x3f;
> + u32 m = (val >> 5) & 0xff;
> + u32 n = val & 0x1f;
> +
> + mult = (m + 1) / (n + 1);
> + div = p + 1;
> + }
> +
> + return clk_hw_register_fixed_factor(NULL, name, "clkin", 0,
> + mult, div);
> +}
> +
> +static void __init aspeed_ast2400_cc(struct regmap *map)
> +{
> + struct clk_hw *hw;
> + u32 val, freq, div;
> +
> + /*
> +  * CLKIN is the crystal oscillator, 24, 48 or 25MHz selected by
> +  * strapping
> +  */
> + regmap_read(map, ASPEED_STRAP, &val);
> + if (val & CLKIN_25MHZ_EN)
> + freq = 2500;
> + else if (val & AST2400_CLK_SOURCE_SEL)
> + freq = 4800;
> + else
> + freq = 2400;
> + hw = clk_hw_register_fixed_rate(NULL, "clkin", NULL, 0, freq);
> + pr_debug("clkin @%u MHz\n", freq / 100);
> +
> + /*
> +  * High-speed PLL clock derived from the crystal. This the CPU clock,
> +  * and we assume that it is enabled
> +  */
> + regmap_read(map, ASPEED_HPLL_PARAM, &val);
> + WARN(val & AST2400_HPLL_STRAPPED, "hpll is strapped not configured");
> + aspeed_clk_data->hws[ASPEED_CLK_HPLL] = aspeed_ast2400_calc_pll("hpll", 
> val);
> +
> + /*
> +  * Strap bits 11:10 define the CPU/AHB clock frequency ratio (aka HCLK)
> +  *   00: Select CPU:AHB = 1:1
> +  *   01: Select CPU:AHB = 2:1
> +  *   10: Select CPU:AHB = 4:1
> +  *   11: Select CPU:AHB = 3:1
> +  */
> + regmap_read(map, ASPEED_STRAP, &val);
> + val = (val >> 10) & 

Re: [PATCH v7 1/5] clk: Add clock driver for ASPEED BMC SoCs

2018-01-01 Thread Benjamin Herrenschmidt
On Fri, 2017-12-22 at 13:15 +1030, Joel Stanley wrote:
> This adds the stub of a driver for the ASPEED SoCs. The clocks are
> defined and the static registration is set up.
> 
> Reviewed-by: Andrew Jeffery 
> Signed-off-by: Joel Stanley 

Reviewed-by: Benjamin Herrenschmidt 
> ---
> v7:
>  - Rebase on dt-bindings patch
>  - Add ASPEED_NUM_CLKS as it no longer lives in the header
> v6:
>  - Add SPDX copyright notices
> v5:
>  - Add Andrew's reviewed-by
>  - Make aspeed_gates not initconst to avoid section mismatch warning
> v3:
>  - use named initlisers for aspeed_gates table
>  - fix clocks typo
>  - Move ASPEED_NUM_CLKS to the bottom of the list
>  - Put gates at the start of the list, so we can use them to initalise
>the aspeed_gates table
>  - Add ASPEED_CLK_SELECTION_2
>  - Set parent of network MAC gates
> ---
>  drivers/clk/Kconfig  |  12 
>  drivers/clk/Makefile |   1 +
>  drivers/clk/clk-aspeed.c | 141 
> +++
>  3 files changed, 154 insertions(+)
>  create mode 100644 drivers/clk/clk-aspeed.c
> 
> diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
> index 1c4e1aa6767e..9abe063ef8d2 100644
> --- a/drivers/clk/Kconfig
> +++ b/drivers/clk/Kconfig
> @@ -142,6 +142,18 @@ config COMMON_CLK_GEMINI
> This driver supports the SoC clocks on the Cortina Systems Gemini
> platform, also known as SL3516 or CS3516.
>  
> +config COMMON_CLK_ASPEED
> + bool "Clock driver for Aspeed BMC SoCs"
> + depends on ARCH_ASPEED || COMPILE_TEST
> + default ARCH_ASPEED
> + select MFD_SYSCON
> + select RESET_CONTROLLER
> + ---help---
> +   This driver supports the SoC clocks on the Aspeed BMC platforms.
> +
> +   The G4 and G5 series, including the ast2400 and ast2500, are supported
> +   by this driver.
> +
>  config COMMON_CLK_S2MPS11
>   tristate "Clock driver for S2MPS1X/S5M8767 MFD"
>   depends on MFD_SEC_CORE || COMPILE_TEST
> diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
> index f7f761b02bed..d260da4809f8 100644
> --- a/drivers/clk/Makefile
> +++ b/drivers/clk/Makefile
> @@ -27,6 +27,7 @@ obj-$(CONFIG_ARCH_CLPS711X) += clk-clps711x.o
>  obj-$(CONFIG_COMMON_CLK_CS2000_CP)   += clk-cs2000-cp.o
>  obj-$(CONFIG_ARCH_EFM32) += clk-efm32gg.o
>  obj-$(CONFIG_COMMON_CLK_GEMINI)  += clk-gemini.o
> +obj-$(CONFIG_COMMON_CLK_ASPEED)  += clk-aspeed.o
>  obj-$(CONFIG_ARCH_HIGHBANK)  += clk-highbank.o
>  obj-$(CONFIG_CLK_HSDK)   += clk-hsdk-pll.o
>  obj-$(CONFIG_COMMON_CLK_MAX77686)+= clk-max77686.o
> diff --git a/drivers/clk/clk-aspeed.c b/drivers/clk/clk-aspeed.c
> new file mode 100644
> index ..7a86ee08ea4f
> --- /dev/null
> +++ b/drivers/clk/clk-aspeed.c
> @@ -0,0 +1,141 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +
> +#define pr_fmt(fmt) "clk-aspeed: " fmt
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +
> +#define ASPEED_NUM_CLKS  35
> +
> +#define ASPEED_STRAP 0x70
> +
> +/* Keeps track of all clocks */
> +static struct clk_hw_onecell_data *aspeed_clk_data;
> +
> +static void __iomem *scu_base;
> +
> +/**
> + * struct aspeed_gate_data - Aspeed gated clocks
> + * @clock_idx: bit used to gate this clock in the clock register
> + * @reset_idx: bit used to reset this IP in the reset register. -1 if no
> + * reset is required when enabling the clock
> + * @name: the clock name
> + * @parent_name: the name of the parent clock
> + * @flags: standard clock framework flags
> + */
> +struct aspeed_gate_data {
> + u8  clock_idx;
> + s8  reset_idx;
> + const char  *name;
> + const char  *parent_name;
> + unsigned long   flags;
> +};
> +
> +/**
> + * struct aspeed_clk_gate - Aspeed specific clk_gate structure
> + * @hw:  handle between common and hardware-specific interfaces
> + * @reg: register controlling gate
> + * @clock_idx:   bit used to gate this clock in the clock register
> + * @reset_idx:   bit used to reset this IP in the reset register. -1 if 
> no
> + *   reset is required when enabling the clock
> + * @flags:   hardware-specific flags
> + * @lock:register lock
> + *
> + * Some of the clocks in the Aspeed SoC must be put in reset before enabling.
> + * This modified version of clk_gate allows an optional reset bit to be
> + * specified.
> + */
> +struct aspeed_clk_gate {
> + struct clk_hw   hw;
> + struct regmap   *map;
> + u8  clock_idx;
> + s8  reset_idx;
> + u8  flags;
> + spinlock_t  *lock;
> +};
> +
> +#define to_aspeed_clk_gate(_hw) container_of(_hw, struct aspeed_clk_gate, hw)
> +
> +/* TODO: ask Aspeed about the actual parent data */
> +static const struct aspeed_gate_data aspeed_gates[] = {
> + /*   clk rst   name paren

Re: [RESEND PATCH v2 07/15] ASoC: qcom: q6asm: Add support to memory map and unmap

2018-01-01 Thread Bjorn Andersson
On Thu 14 Dec 09:33 PST 2017, srinivas.kandaga...@linaro.org wrote:

> From: Srinivas Kandagatla 
> 
> This patch adds support to memory map and unmap regions commands in
> q6asm module.
> 
> Signed-off-by: Srinivas Kandagatla 
> ---
>  sound/soc/qcom/qdsp6/q6asm.c | 343 
> ++-
>  sound/soc/qcom/qdsp6/q6asm.h |   5 +
>  2 files changed, 347 insertions(+), 1 deletion(-)
> 
> diff --git a/sound/soc/qcom/qdsp6/q6asm.c b/sound/soc/qcom/qdsp6/q6asm.c
> index 9cc583afef4d..4be92441f524 100644
> --- a/sound/soc/qcom/qdsp6/q6asm.c
> +++ b/sound/soc/qcom/qdsp6/q6asm.c
> @@ -14,9 +14,46 @@
>  #include "q6asm.h"
>  #include "common.h"
>  
> +#define ASM_CMD_SHARED_MEM_MAP_REGIONS   0x00010D92
> +#define ASM_CMDRSP_SHARED_MEM_MAP_REGIONS0x00010D93
> +#define ASM_CMD_SHARED_MEM_UNMAP_REGIONS 0x00010D94
> +
>  #define TUN_READ_IO_MODE 0x0004  /* tunnel read write mode */
>  #define SYNC_IO_MODE 0x0001
>  #define ASYNC_IO_MODE0x0002
> +#define ASM_SHIFT_GAPLESS_MODE_FLAG  31
> +#define ADSP_MEMORY_MAP_SHMEM8_4K_POOL   3
> +
> +struct avs_cmd_shared_mem_map_regions {
> + struct apr_hdr hdr;
> + u16 mem_pool_id;
> + u16 num_regions;
> + u32 property_flag;
> +} __packed;
> +
> +struct avs_shared_map_region_payload {
> + u32 shm_addr_lsw;
> + u32 shm_addr_msw;
> + u32 mem_size_bytes;
> +} __packed;
> +
> +struct avs_cmd_shared_mem_unmap_regions {
> + struct apr_hdr hdr;
> + u32 mem_map_handle;
> +} __packed;
> +
> +struct audio_buffer {
> + dma_addr_t phys;
> + uint32_t used;
> + uint32_t size;  /* size of buffer */
> +};
> +
> +struct audio_port_data {
> + struct audio_buffer *buf;
> + uint32_t max_buf_cnt;

This seems to denote the number of audio_buffers in the buf array, so
I'm not sure about the meaning of "max_".

> + uint32_t dsp_buf;
> + uint32_t mem_map_handle;
> +};
>  
>  struct audio_client {
>   int session;
> @@ -27,6 +64,8 @@ struct audio_client {
>   uint64_t time_stamp;
>   struct apr_device *adev;
>   struct mutex cmd_lock;
> + /* idx:1 out port, 0: in port */
> + struct audio_port_data port[2];
>   wait_queue_head_t cmd_wait;
>   int perf_mode;
>   int stream_id;
> @@ -86,6 +125,260 @@ static void q6asm_session_free(struct audio_client *ac)
>   mutex_unlock(&a->session_lock);
>  }
>  
> +static inline void q6asm_add_mmaphdr(struct audio_client *ac,
> +  struct apr_hdr *hdr, u32 pkt_size,
> +  bool cmd_flg, u32 token)

cmd_flg is true in both callers, so this function ends up simply
assigning hdr_field, pkt_size and token. Inlining these assignments
would make for cleaner call sites as well.

> +{
> + hdr->hdr_field = APR_SEQ_CMD_HDR_FIELD;
> + hdr->src_port = 0;
> + hdr->dest_port = 0;
> + hdr->pkt_size = pkt_size;
> + if (cmd_flg)
> + hdr->token = token;
> +}
> +
> +static inline void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr 
> *hdr,

This is unused.

> +  uint32_t pkt_size, bool cmd_flg,
> +  uint32_t stream_id)
> +{
> + hdr->hdr_field = APR_SEQ_CMD_HDR_FIELD;
> + hdr->src_svc = ac->adev->svc_id;
> + hdr->src_domain = APR_DOMAIN_APPS;
> + hdr->dest_svc = APR_SVC_ASM;
> + hdr->dest_domain = APR_DOMAIN_ADSP;
> + hdr->src_port = ((ac->session << 8) & 0xFF00) | (stream_id);
> + hdr->dest_port = ((ac->session << 8) & 0xFF00) | (stream_id);
> + hdr->pkt_size = pkt_size;
> + if (cmd_flg)
> + hdr->token = ac->session;
> +}
> +
> +static int __q6asm_memory_unmap(struct audio_client *ac,
> + phys_addr_t buf_add, int dir)
> +{
> + struct avs_cmd_shared_mem_unmap_regions mem_unmap;

If you name this "cmd" you will declutter below code a bit.

> + struct q6asm *a = dev_get_drvdata(ac->dev->parent);
> + int rc;
> +
> + if (!a)
> + return -ENODEV;

Does this NULL check add any real value?

> +
> + q6asm_add_mmaphdr(ac, &mem_unmap.hdr, sizeof(mem_unmap), true,
> +   ((ac->session << 8) | dir));
> + a->mem_state = -1;
> +
> + mem_unmap.hdr.opcode = ASM_CMD_SHARED_MEM_UNMAP_REGIONS;
> + mem_unmap.mem_map_handle = ac->port[dir].mem_map_handle;
> +
> + if (mem_unmap.mem_map_handle == 0) {

Start the function by checking for !ac->port[dir].mem_map_handle

> + dev_err(ac->dev, "invalid mem handle\n");
> + return -EINVAL;
> + }
> +
> + rc = apr_send_pkt(a->adev, (uint32_t *) &mem_unmap);
> + if (rc < 0)
> + return rc;
> +
> + rc = wait_event_timeout(a->mem_wait, (a->mem_state >= 0),
> + 5 * HZ);
> + if (!rc) {
> + dev_err(ac->dev, "CMD timeout for memory_unmap 0x%x\n",
> + mem_unmap.mem

Re: [PATCH v6 4/5] clk: aspeed: Register gated clocks

2018-01-01 Thread Benjamin Herrenschmidt
On Sat, 2017-12-30 at 09:03 +1100, Benjamin Herrenschmidt wrote:
> On Tue, 2017-12-26 at 17:32 -0800, Stephen Boyd wrote:
> > > I noticed we do have a few i2c based clock drivers... how are they ever
> > > supposed to work ? i2c bus controllers are allowed to sleep and the i2c
> > > core takes mutexes...
> > 
> > We have clk_prepare()/clk_unprepare() for sleeping suckage. You
> > can use that, and i2c based clk drivers do that today.
> 
> "suckage" ? Hehe ... the suckage should rather be stuff that cannot
> sleep. Arbitrary latencies and jitter caused by too much code wanting
> to be "atomic" when unnecessary are a bad thing.
> 
> In the case of clocks like the aspeed where we have to wait for a
> rather long stabilization delay, way too long to legitimately do a non-
> sleepable delay with a lock held, do we need to do everything in
> prepare() then ?

BTW. Pls don't hold Joel's patches for this. Without that clk framework
a lot of the aspeed stuff already upstream doesn't actually work
without additional out-of-tree hacks or uboot black magic.

We can sort out the sleeping issues (and possibly move to using prepare
for the clocks that have that delay requirement) via subsequent
improvements.

Cheers,
Ben.




Re: [PATCH v3 14/16] phy: Add notify_speed callback

2018-01-01 Thread Manu Gautam
Hi,


On 12/29/2017 11:58 AM, Kishon Vijay Abraham I wrote:
> Hi,
>
> On Friday 29 December 2017 09:54 AM, Manu Gautam wrote:
>> Hi,
[snip]
>
> suggest using switch in such case.. and not all PHY drivers do specific
> configurations for specific speeds.
>> This looks clumsy.
>> Where as if bits to used then there is no need for such changes.
> really? using bits should only make it more clumsy.

Thanks for your feedback. I will update this in next patchset.


> -Kishon

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



RE: [PATCH 8/9] scsi: bfa: Use zeroing allocator rather than allocator/memset

2018-01-01 Thread Gurumurthy, Anil


-Original Message-
From: Himanshu Jha [mailto:himanshujha199...@gmail.com] 
Sent: 30 December 2017 20:59
To: j...@linux.vnet.ibm.com; martin.peter...@oracle.com; aacr...@adaptec.com
Cc: Gurumurthy, Anil ; Kalluru, Sudarsana 
; Dept-Eng QLogic Storage Upstream 
; satis...@cisco.com; sebad...@cisco.com; 
karti...@cisco.com; Dept-Eng QLogic Storage Upstream 
; Dept-Eng QLA2xxx Upstream 
; linux-s...@vger.kernel.org; 
linux-kernel@vger.kernel.org; Himanshu Jha 
Subject: [PATCH 8/9] scsi: bfa: Use zeroing allocator rather than 
allocator/memset

Use vzalloc instead of vmalloc followed by memset 0.

Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci

Suggested-by: Luis R. Rodriguez 
Signed-off-by: Himanshu Jha 
---
 drivers/scsi/bfa/bfad.c | 3 +--
 drivers/scsi/bfa/bfad_debugfs.c | 8 ++--
 2 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/bfa/bfad.c b/drivers/scsi/bfa/bfad.c index 
bac18f6..bd7e6a6f 100644
--- a/drivers/scsi/bfa/bfad.c
+++ b/drivers/scsi/bfa/bfad.c
@@ -610,13 +610,12 @@ bfad_hal_mem_alloc(struct bfad_s *bfad)
/* Iterate through the KVA meminfo queue */
list_for_each(km_qe, &kva_info->qe) {
kva_elem = (struct bfa_mem_kva_s *) km_qe;
-   kva_elem->kva = vmalloc(kva_elem->mem_len);
+   kva_elem->kva = vzalloc(kva_elem->mem_len);
if (kva_elem->kva == NULL) {
bfad_hal_mem_release(bfad);
rc = BFA_STATUS_ENOMEM;
goto ext;
}
-   memset(kva_elem->kva, 0, kva_elem->mem_len);
}
 
/* Iterate through the DMA meminfo queue */ diff --git 
a/drivers/scsi/bfa/bfad_debugfs.c b/drivers/scsi/bfa/bfad_debugfs.c index 
05f5239..349cfe7 100644
--- a/drivers/scsi/bfa/bfad_debugfs.c
+++ b/drivers/scsi/bfa/bfad_debugfs.c
@@ -81,7 +81,7 @@ bfad_debugfs_open_fwtrc(struct inode *inode, struct file 
*file)
 
fw_debug->buffer_len = sizeof(struct bfa_trc_mod_s);
 
-   fw_debug->debug_buffer = vmalloc(fw_debug->buffer_len);
+   fw_debug->debug_buffer = vzalloc(fw_debug->buffer_len);
if (!fw_debug->debug_buffer) {
kfree(fw_debug);
printk(KERN_INFO "bfad[%d]: Failed to allocate fwtrc buffer\n", 
@@ -89,8 +89,6 @@ bfad_debugfs_open_fwtrc(struct inode *inode, struct file 
*file)
return -ENOMEM;
}
 
-   memset(fw_debug->debug_buffer, 0, fw_debug->buffer_len);
-
spin_lock_irqsave(&bfad->bfad_lock, flags);
rc = bfa_ioc_debug_fwtrc(&bfad->bfa.ioc,
fw_debug->debug_buffer,
@@ -125,7 +123,7 @@ bfad_debugfs_open_fwsave(struct inode *inode, struct file 
*file)
 
fw_debug->buffer_len = sizeof(struct bfa_trc_mod_s);
 
-   fw_debug->debug_buffer = vmalloc(fw_debug->buffer_len);
+   fw_debug->debug_buffer = vzalloc(fw_debug->buffer_len);
if (!fw_debug->debug_buffer) {
kfree(fw_debug);
printk(KERN_INFO "bfad[%d]: Failed to allocate fwsave 
buffer\n", @@ -133,8 +131,6 @@ bfad_debugfs_open_fwsave(struct inode *inode, 
struct file *file)
return -ENOMEM;
}
 
-   memset(fw_debug->debug_buffer, 0, fw_debug->buffer_len);
-
spin_lock_irqsave(&bfad->bfad_lock, flags);
rc = bfa_ioc_debug_fwsave(&bfad->bfa.ioc,
fw_debug->debug_buffer,
--
2.7.4

Acked by: Anil Gurumurthy 



RE: [PATCH v8 1/2] tpm_tis: Move ilb_base_addr to tpm_tis_data

2018-01-01 Thread Shaikh, Azhar


>-Original Message-
>From: linux-integrity-ow...@vger.kernel.org [mailto:linux-integrity-
>ow...@vger.kernel.org] On Behalf Of Shaikh, Azhar
>Sent: Monday, January 1, 2018 9:02 PM
>To: Jason Gunthorpe 
>Cc: jarkko.sakki...@linux.intel.com; peterhu...@gmx.de; linux-security-
>mod...@vger.kernel.org; linux-integr...@vger.kernel.org; linux-
>ker...@vger.kernel.org
>Subject: RE: [PATCH v8 1/2] tpm_tis: Move ilb_base_addr to tpm_tis_data
>
>
>
>>-Original Message-
>>From: Jason Gunthorpe [mailto:j...@ziepe.ca]
>>Sent: Monday, January 1, 2018 8:41 PM
>>To: Shaikh, Azhar 
>>Cc: jarkko.sakki...@linux.intel.com; peterhu...@gmx.de; linux-security-
>>mod...@vger.kernel.org; linux-integr...@vger.kernel.org; linux-
>>ker...@vger.kernel.org
>>Subject: Re: [PATCH v8 1/2] tpm_tis: Move ilb_base_addr to tpm_tis_data
>>
>>On Mon, Jan 01, 2018 at 08:05:43PM -0800, Azhar Shaikh wrote:
>>
>>> -   return tpm_chip_register(chip);
>>> +   rc = tpm_chip_register(chip);
>>> +   if (rc && is_bsw())
>>> +   iounmap(priv->ilb_base_addr);
>>> +
>>> +   return rc;
>>>  out_err:
>>> tpm_tis_remove(chip);
>>> +   if (is_bsw())
>>> +   iounmap(priv->ilb_base_addr);
>>> +
>>> return rc;
>>>  }
>>
>>I thought you were resending this to fix the above, why is is it still wonky?
>>
>
>Oh! I fixed it in the second patch ("tpm: Keep CLKRUN enabled throughout
>the duration of transmit_cmd()"). Should have fixed in this patch instead. My
>bad, didn't see it was introduced in this patch. I thought it was part of 
>second
>patch. Will fix this.
>

On checking, the ops->clk_enable is not still introduced yet. It is introduced 
in the second patch. The cleanup is done in the next patch.
So do you want me to still fix this here?

>>Jason

Regards,
Azhar Shaikh


[PATCH] cpu_cooling: Remove static-power related documentation

2018-01-01 Thread Viresh Kumar
commit 84fe2cab4859 ("cpu_cooling: Drop static-power related stuff")
removed support for static-power in kernel, but it missed reflecting the
same in documentation. Remove the static power related documentation
bits as well.

Reported-by: Javi Merino 
Signed-off-by: Viresh Kumar 
---
 Documentation/thermal/cpu-cooling-api.txt | 82 +--
 1 file changed, 2 insertions(+), 80 deletions(-)

diff --git a/Documentation/thermal/cpu-cooling-api.txt 
b/Documentation/thermal/cpu-cooling-api.txt
index 7a1c89db0419..7df567eaea1a 100644
--- a/Documentation/thermal/cpu-cooling-api.txt
+++ b/Documentation/thermal/cpu-cooling-api.txt
@@ -44,16 +44,14 @@ the user. The registration APIs returns the cooling device 
pointer.
 2. Power models
 
 The power API registration functions provide a simple power model for
-CPUs.  The current power is calculated as dynamic + (optionally)
-static power.  This power model requires that the operating-points of
+CPUs.  The current power is calculated as dynamic power (static power isn't
+supported currently).  This power model requires that the operating-points of
 the CPUs are registered using the kernel's opp library and the
 `cpufreq_frequency_table` is assigned to the `struct device` of the
 cpu.  If you are using CONFIG_CPUFREQ_DT then the
 `cpufreq_frequency_table` should already be assigned to the cpu
 device.
 
-2.1 Dynamic power
-
 The dynamic power consumption of a processor depends on many factors.
 For a given processor implementation the primary factors are:
 
@@ -92,79 +90,3 @@ mW/MHz/uVolt^2.  Typical values for mobile CPUs might lie in 
range
 from 100 to 500.  For reference, the approximate values for the SoC in
 ARM's Juno Development Platform are 530 for the Cortex-A57 cluster and
 140 for the Cortex-A53 cluster.
-
-
-2.2 Static power
-
-Static leakage power consumption depends on a number of factors.  For a
-given circuit implementation the primary factors are:
-
-- Time the circuit spends in each 'power state'
-- Temperature
-- Operating voltage
-- Process grade
-
-The time the circuit spends in each 'power state' for a given
-evaluation period at first order means OFF or ON.  However,
-'retention' states can also be supported that reduce power during
-inactive periods without loss of context.
-
-Note: The visibility of state entries to the OS can vary, according to
-platform specifics, and this can then impact the accuracy of a model
-based on OS state information alone.  It might be possible in some
-cases to extract more accurate information from system resources.
-
-The temperature, operating voltage and process 'grade' (slow to fast)
-of the circuit are all significant factors in static leakage power
-consumption.  All of these have complex relationships to static power.
-
-Circuit implementation specific factors include the chosen silicon
-process as well as the type, number and size of transistors in both
-the logic gates and any RAM elements included.
-
-The static power consumption modelling must take into account the
-power managed regions that are implemented.  Taking the example of an
-ARM processor cluster, the modelling would take into account whether
-each CPU can be powered OFF separately or if only a single power
-region is implemented for the complete cluster.
-
-In one view, there are others, a static power consumption model can
-then start from a set of reference values for each power managed
-region (e.g. CPU, Cluster/L2) in each state (e.g. ON, OFF) at an
-arbitrary process grade, voltage and temperature point.  These values
-are then scaled for all of the following: the time in each state, the
-process grade, the current temperature and the operating voltage.
-However, since both implementation specific and complex relationships
-dominate the estimate, the appropriate interface to the model from the
-cpu cooling device is to provide a function callback that calculates
-the static power in this platform.  When registering the cpu cooling
-device pass a function pointer that follows the `get_static_t`
-prototype:
-
-int plat_get_static(cpumask_t *cpumask, int interval,
-unsigned long voltage, u32 &power);
-
-`cpumask` is the cpumask of the cpus involved in the calculation.
-`voltage` is the voltage at which they are operating.  The function
-should calculate the average static power for the last `interval`
-milliseconds.  It returns 0 on success, -E* on error.  If it
-succeeds, it should store the static power in `power`.  Reading the
-temperature of the cpus described by `cpumask` is left for
-plat_get_static() to do as the platform knows best which thermal
-sensor is closest to the cpu.
-
-If `plat_static_func` is NULL, static power is considered to be
-negligible for this platform and only dynamic power is considered.
-
-The platform specific callback can then use any combination of tables
-and/or equations to permute the estimated value.  Process grade
-information is not passed to the model

[RFC PATCH 3/4] rtc: Add one offset seconds to expand RTC range

2018-01-01 Thread Baolin Wang
>From our investigation for all RTC drivers, 1 driver will be expired before
year 2017, 7 drivers will be expired before year 2038, 23 drivers will be
expired before year 2069, 72 drivers will be expired before 2100 and 104
drivers will be expired before 2106. Especially for these early expired
drivers, we need to expand the RTC range to make the RTC can still work
after the expired year.

So we can expand the RTC range by adding one offset to the time when reading
from hardware, and subtracting it when writing back. For example, if you have
an RTC that can do 100 years, and currently is configured to be based in
Jan 1 1970, so it can represents times from 1970 to 2069. Then if you change
the start year from 1970 to 2000, which means it can represents times from
2000 to 2099. By adding or subtracting the offset produced by moving the wrap
point, all times between 1970 and 1999 from RTC hardware could get interpreted
as times from 2070 to 2099, but the interpretation of dates between 2000 and
2069 would not change.

Signed-off-by: Baolin Wang 
---
 drivers/rtc/class.c |   53 +++
 drivers/rtc/interface.c |   53 +--
 include/linux/rtc.h |2 ++
 3 files changed, 106 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 31fc0f1..8e59cf0 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -211,6 +211,55 @@ static int rtc_device_get_id(struct device *dev)
return id;
 }
 
+static void rtc_device_get_offset(struct rtc_device *rtc)
+{
+   u32 start_year;
+   int ret;
+
+   rtc->offset_secs = 0;
+   rtc->start_secs = rtc->min_hw_secs;
+
+   /*
+* If RTC driver did not implement the range of RTC hardware device,
+* then we can not expand the RTC range by adding or subtracting one
+* offset.
+*/
+   if (!rtc->max_hw_secs)
+   return;
+
+   ret = device_property_read_u32(rtc->dev.parent, "start-year",
+  &start_year);
+   if (ret)
+   return;
+
+   /*
+* Record the start time values in seconds, which are used to valid if
+* the setting time values are in the new expanded range.
+*/
+   rtc->start_secs = max_t(time64_t, mktime64(start_year, 1, 1, 0, 0, 0),
+   rtc->min_hw_secs);
+
+   /*
+* If the start_secs is larger than the maximum seconds (max_hw_secs)
+* support by RTC hardware, which means the minimum seconds
+* (min_hw_secs) of RTC hardware will be mapped to start_secs by adding
+* one offset, so the offset seconds calculation formula should be:
+* rtc->offset_secs = rtc->start_secs - rtc->min_hw_secs;
+*
+* If the start_secs is less than max_hw_secs, then there is one region
+* is overlapped between the original RTC hardware range and the new
+* expanded range, and this overlapped region do not need to be mapped
+* into the new expanded range due to it is valid for RTC device. So
+* the minimum seconds of RTC hardware (min_hw_secs) should be mapped to
+* max_hw_secs + 1, then the offset seconds formula should be:
+* rtc->offset_secs = rtc->max_hw_secs - rtc->min_hw_secs + 1;
+*/
+   if (rtc->start_secs > rtc->max_hw_secs)
+   rtc->offset_secs = rtc->start_secs - rtc->min_hw_secs;
+   else
+   rtc->offset_secs = rtc->max_hw_secs - rtc->min_hw_secs + 1;
+}
+
 /**
  * rtc_device_register - register w/ RTC class
  * @dev: the device to register
@@ -253,6 +302,8 @@ struct rtc_device *rtc_device_register(const char *name, 
struct device *dev,
goto exit_ida;
}
 
+   rtc_device_get_offset(rtc);
+
/* Check to see if there is an ALARM already set in hw */
err = __rtc_read_alarm(rtc, &alrm);
 
@@ -449,6 +500,8 @@ int __rtc_register_device(struct module *owner, struct 
rtc_device *rtc)
return err;
}
 
+   rtc_device_get_offset(rtc);
+
/* Check to see if there is an ALARM already set in hw */
err = __rtc_read_alarm(rtc, &alrm);
if (!err && !rtc_valid_tm(&alrm.time))
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index c8090e3..eb96a90 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -20,6 +20,46 @@
 static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer);
 static void rtc_timer_remove(struct rtc_device *rtc, struct rtc_timer *timer);
 
+static void rtc_add_offset(struct rtc_device *rtc, struct rtc_time *tm)
+{
+   time64_t secs;
+
+   if (!rtc->offset_secs)
+   return;
+
+   secs = rtc_tm_to_time64(tm);
+   /*
+* Since the reading time values from RTC device are always less than
+* rtc->max_hw_secs, then if the reading time values are larger than
+ 

[RFC PATCH 2/4] rtc: sysfs: Export the valid range supported by RTC hardware

2018-01-01 Thread Baolin Wang
We have introduced one interface to get the RTC range, so this patch
exports the valid range supported by RTC hardware to userspace.

Signed-off-by: Baolin Wang 
---
 Documentation/rtc.txt   |2 ++
 drivers/rtc/rtc-sysfs.c |   30 ++
 2 files changed, 32 insertions(+)

diff --git a/Documentation/rtc.txt b/Documentation/rtc.txt
index c0c9774..4fe437b 100644
--- a/Documentation/rtc.txt
+++ b/Documentation/rtc.txt
@@ -164,6 +164,8 @@ offset   The amount which the rtc clock has 
been adjusted in firmware.
 which are added to or removed from the rtc's base clock per
 billion ticks. A positive value makes a day pass more slowly,
 longer, and a negative value makes a day pass more quickly.
+range_max   The maximum time values in seconds supported by RTC hardware.
+range_min   The minimum time values in seconds supported by RTC hardware.
 */nvmem The non volatile storage exported as a raw file, as 
described
 in Documentation/nvmem/nvmem.txt
  ==
diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c
index 92ff2ed..60e1f6c 100644
--- a/drivers/rtc/rtc-sysfs.c
+++ b/drivers/rtc/rtc-sysfs.c
@@ -248,6 +248,34 @@
 }
 static DEVICE_ATTR_RW(offset);
 
+static ssize_t
+range_max_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+   ssize_t retval;
+   time64_t max_hw_secs, min_hw_secs;
+
+   retval = rtc_read_range(to_rtc_device(dev), &max_hw_secs, &min_hw_secs);
+   if (retval == 0)
+   retval = sprintf(buf, "%lld\n", max_hw_secs);
+
+   return retval;
+}
+static DEVICE_ATTR_RO(range_max);
+
+static ssize_t
+range_min_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+   ssize_t retval;
+   time64_t max_hw_secs, min_hw_secs;
+
+   retval = rtc_read_range(to_rtc_device(dev), &max_hw_secs, &min_hw_secs);
+   if (retval == 0)
+   retval = sprintf(buf, "%lld\n", min_hw_secs);
+
+   return retval;
+}
+static DEVICE_ATTR_RO(range_min);
+
 static struct attribute *rtc_attrs[] = {
&dev_attr_name.attr,
&dev_attr_date.attr,
@@ -257,6 +285,8 @@
&dev_attr_hctosys.attr,
&dev_attr_wakealarm.attr,
&dev_attr_offset.attr,
+   &dev_attr_range_max.attr,
+   &dev_attr_range_min.attr,
NULL,
 };
 
-- 
1.7.9.5



[RFC PATCH 1/4] rtc: Introduce one interface to save the RTC hardware time range

2018-01-01 Thread Baolin Wang
In order to the setting time values are not beyond the limitation
supported by RTC hardware, we introduce one interface to tell the
hardware range to the RTC core, which are used to valid if the
setting time values are in the RTC hardware range.

Moreover we also need the RTC hardware range to expand the RTC
range in next patches by adding one offset.

Signed-off-by: Baolin Wang 
---
 drivers/rtc/class.c |   13 ++
 drivers/rtc/interface.c |   62 +++
 include/linux/rtc.h |9 +++
 3 files changed, 84 insertions(+)

diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 722d683..31fc0f1 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -247,6 +247,12 @@ struct rtc_device *rtc_device_register(const char *name, 
struct device *dev,
 
dev_set_name(&rtc->dev, "rtc%d", id);
 
+   err = rtc_read_range(rtc, &rtc->max_hw_secs, &rtc->min_hw_secs);
+   if (err) {
+   dev_err(&rtc->dev, "%s: failed to get RTC range\n", name);
+   goto exit_ida;
+   }
+
/* Check to see if there is an ALARM already set in hw */
err = __rtc_read_alarm(rtc, &alrm);
 
@@ -436,6 +442,13 @@ int __rtc_register_device(struct module *owner, struct 
rtc_device *rtc)
 
rtc->owner = owner;
 
+   err = rtc_read_range(rtc, &rtc->max_hw_secs, &rtc->min_hw_secs);
+   if (err) {
+   dev_err(&rtc->dev, "%s: failed to get RTC range\n",
+   dev_name(&rtc->dev));
+   return err;
+   }
+
/* Check to see if there is an ALARM already set in hw */
err = __rtc_read_alarm(rtc, &alrm);
if (!err && !rtc_valid_tm(&alrm.time))
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 672b192..c8090e3 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -65,6 +65,10 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
if (err != 0)
return err;
 
+   err = rtc_valid_range(rtc, tm);
+   if (err)
+   return err;
+
err = mutex_lock_interruptible(&rtc->ops_lock);
if (err)
return err;
@@ -329,6 +333,11 @@ static int __rtc_set_alarm(struct rtc_device *rtc, struct 
rtc_wkalrm *alarm)
err = rtc_valid_tm(&alarm->time);
if (err)
return err;
+
+   err = rtc_valid_range(rtc, &alarm->time);
+   if (err)
+   return err;
+
scheduled = rtc_tm_to_time64(&alarm->time);
 
/* Make sure we're not setting alarms in the past */
@@ -1027,3 +1036,56 @@ int rtc_set_offset(struct rtc_device *rtc, long offset)
mutex_unlock(&rtc->ops_lock);
return ret;
 }
+
+/* rtc_read_range - Read the max and min hardware count supported by RTC device
+ * @ rtc: rtc device to be used.
+ * @ max_hw_secs: maximum hardware count in seconds, which can represent
+ * the maximum time values in RTC hardware.
+ * @ min_hw_secs: minimum hardware count in seconds, which can represent
+ * the minimum time values in RTC hardware.
+ *
+ * The max_hw_secs and min_hw_secs implemented by user must represent the
+ * correct hardware start time and maximum time, which means the count
+ * will wrap around to min_hw_secs after the maximum count.
+ *
+ * If user did not implement the read_range() interface, we can set max_hw_secs
+ * and min_hw_secs to 0, which avoids validing the range.
+ */
+int rtc_read_range(struct rtc_device *rtc, time64_t *max_hw_secs,
+  time64_t *min_hw_secs)
+{
+   int ret;
+
+   if (!rtc->ops || !rtc->ops->read_range) {
+   *max_hw_secs = 0;
+   *min_hw_secs = 0;
+   return 0;
+   }
+
+   mutex_lock(&rtc->ops_lock);
+   ret = rtc->ops->read_range(rtc->dev.parent, max_hw_secs, min_hw_secs);
+   mutex_unlock(&rtc->ops_lock);
+
+   return ret;
+}
+
+/* rtc_valid_range - Valid if the setting time in the RTC range
+ * @ rtc: rtc device to be used.
+ * @ tm: time values need to valid.
+ *
+ * Only the rtc->max_hw_secs was set, then we can valid if the setting time
+ * values are beyond the RTC range.
+ */
+int rtc_valid_range(struct rtc_device *rtc, struct rtc_time *tm)
+{
+   time64_t secs;
+
+   if (!rtc->max_hw_secs)
+   return 0;
+
+   secs = rtc_tm_to_time64(tm);
+   if (secs < rtc->min_hw_secs || secs > rtc->max_hw_secs)
+   return -EINVAL;
+
+   return 0;
+}
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index 41319a2..19a8989 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -85,6 +85,8 @@ struct rtc_class_ops {
int (*alarm_irq_enable)(struct device *, unsigned int enabled);
int (*read_offset)(struct device *, long *offset);
int (*set_offset)(struct device *, long offset);
+   int (*read_range)(struct device *, time64_t *max_hw_secs,
+ time64_t *min_hw_secs);
 };
 
 #define RTC_DEVICE_NAM

[RFC PATCH 4/4] rtc: sc27xx: Add the get_range interface

2018-01-01 Thread Baolin Wang
Add the get_range interface for sc27xx RTC driver to tell the RTC
core what is the valid range for RTC hardware device.

Signed-off-by: Baolin Wang 
---
 drivers/rtc/rtc-sc27xx.c |   10 ++
 1 file changed, 10 insertions(+)

diff --git a/drivers/rtc/rtc-sc27xx.c b/drivers/rtc/rtc-sc27xx.c
index d544d52..97b1120 100644
--- a/drivers/rtc/rtc-sc27xx.c
+++ b/drivers/rtc/rtc-sc27xx.c
@@ -536,12 +536,22 @@ static int sprd_rtc_alarm_irq_enable(struct device *dev, 
unsigned int enabled)
return ret;
 }
 
+static int sprd_rtc_read_range(struct device *dev, time64_t *max_hw_secs,
+  time64_t *min_hw_secs)
+{
+   *min_hw_secs = 0;
+   *max_hw_secs = (((time64_t)(SPRD_RTC_DAY_MASK * 24) + 23) * 60 + 59) * 
60 + 59;
+
+   return 0;
+}
+
 static const struct rtc_class_ops sprd_rtc_ops = {
.read_time = sprd_rtc_read_time,
.set_time = sprd_rtc_set_time,
.read_alarm = sprd_rtc_read_alarm,
.set_alarm = sprd_rtc_set_alarm,
.alarm_irq_enable = sprd_rtc_alarm_irq_enable,
+   .read_range = sprd_rtc_read_range,
 };
 
 static irqreturn_t sprd_rtc_handler(int irq, void *dev_id)
-- 
1.7.9.5



RE: [PATCH v8 1/2] tpm_tis: Move ilb_base_addr to tpm_tis_data

2018-01-01 Thread Shaikh, Azhar


>-Original Message-
>From: Jason Gunthorpe [mailto:j...@ziepe.ca]
>Sent: Monday, January 1, 2018 8:41 PM
>To: Shaikh, Azhar 
>Cc: jarkko.sakki...@linux.intel.com; peterhu...@gmx.de; linux-security-
>mod...@vger.kernel.org; linux-integr...@vger.kernel.org; linux-
>ker...@vger.kernel.org
>Subject: Re: [PATCH v8 1/2] tpm_tis: Move ilb_base_addr to tpm_tis_data
>
>On Mon, Jan 01, 2018 at 08:05:43PM -0800, Azhar Shaikh wrote:
>
>> -return tpm_chip_register(chip);
>> +rc = tpm_chip_register(chip);
>> +if (rc && is_bsw())
>> +iounmap(priv->ilb_base_addr);
>> +
>> +return rc;
>>  out_err:
>>  tpm_tis_remove(chip);
>> +if (is_bsw())
>> +iounmap(priv->ilb_base_addr);
>> +
>>  return rc;
>>  }
>
>I thought you were resending this to fix the above, why is is it still wonky?
>

Oh! I fixed it in the second patch ("tpm: Keep CLKRUN enabled throughout the 
duration of transmit_cmd()"). Should have fixed in this patch instead. My bad, 
didn't see it was introduced in this patch. I thought it was part of second 
patch. Will fix this.

>Jason


Re: [RESEND PATCH v2 06/15] ASoC: qcom: qdsp6: Add support to Q6ASM

2018-01-01 Thread Bjorn Andersson
On Thu 14 Dec 09:33 PST 2017, srinivas.kandaga...@linaro.org wrote:

> From: Srinivas Kandagatla 
> 
> This patch adds basic support to Q6 ASM (Audio Stream Manager) module on
> Q6DSP. ASM supports up to 8 concurrent streams. each stream can be setup
> as playback/capture.

"...streams, each one setup as either playback or capture".

or "each" need to be capitalized.

> ASM provides top control functions like
> Pause/flush/resume for playback and record. ASM can Create/destroy encoder,

lower case p and c

> decoder and also provides POPP dynamic services.

Please describe what POPP is.

[..]
> +struct audio_client {
> + int session;
> + app_cb cb;
> + int cmd_state;
> + void *priv;
> + uint32_t io_mode;
> + uint64_t time_stamp;

Unused.

> + struct apr_device *adev;
> + struct mutex cmd_lock;
> + wait_queue_head_t cmd_wait;
> + int perf_mode;
> + int stream_id;
> + struct device *dev;
> +};
> +
> +struct q6asm {
> + struct apr_device *adev;
> + int mem_state;
> + struct device *dev;
> + wait_queue_head_t mem_wait;
> + struct mutexsession_lock;
> + struct platform_device *pcmdev;
> + struct audio_client *session[MAX_SESSIONS + 1];
> +};
> +
> +static int q6asm_session_alloc(struct audio_client *ac, struct q6asm *a)

Move the allocation of ac into this function, and return the newly
allocated ac - that way the name of this function makes more sense.

> +{
> + int n = -EINVAL;

You're returning MAX_SESSIONS if no free sessions are found, but are
checking for <= 0 in the caller.

> +
> + mutex_lock(&a->session_lock);
> + for (n = 1; n <= MAX_SESSIONS; n++) {

Is there an external reason for session 0 not being considered?

> + if (!a->session[n]) {
> + a->session[n] = ac;
> + break;
> + }
> + }

If you make session an idr this function would become idr_alloc(1,
MAX_SESSIONS + 1).

> + mutex_unlock(&a->session_lock);
> +
> + return n;
> +}
> +
> +static bool q6asm_is_valid_audio_client(struct audio_client *ac)
> +{
> + struct q6asm *a = dev_get_drvdata(ac->dev->parent);
> + int n;
> +
> + for (n = 1; n <= MAX_SESSIONS; n++) {
> + if (a->session[n] == ac)
> + return 1;

"true"

> + }
> +
> + return 0;

"false"

> +}
> +
> +static void q6asm_session_free(struct audio_client *ac)
> +{
> + struct q6asm *a = dev_get_drvdata(ac->dev->parent);
> +
> + if (!a)
> + return;
> +
> + mutex_lock(&a->session_lock);
> + a->session[ac->session] = 0;
> + ac->session = 0;
> + ac->perf_mode = LEGACY_PCM_MODE;

No need to update ac->*, as you kfree ac as soon as you return from
here.

> + mutex_unlock(&a->session_lock);
> +}
> +
> +/**
> + * q6asm_audio_client_free() - Freee allocated audio client
> + *
> + * @ac: audio client to free
> + */
> +void q6asm_audio_client_free(struct audio_client *ac)
> +{
> + q6asm_session_free(ac);

Inline q6asm_session_free() here.

> + kfree(ac);
> +}
> +EXPORT_SYMBOL_GPL(q6asm_audio_client_free);
> +
> +static struct audio_client *q6asm_get_audio_client(struct q6asm *a,
> +int session_id)
> +{
> + if ((session_id <= 0) || (session_id > MAX_SESSIONS)) {
> + dev_err(a->dev, "invalid session: %d\n", session_id);
> + goto err;

Just return NULL here instead.

> + }
> +
> + if (!a->session[session_id]) {
> + dev_err(a->dev, "session not active: %d\n", session_id);
> + goto err;

Dito

> + }

But this is another place where an idr would be preferable, as both
these cases would be covered with a call to idr_find()

> + return a->session[session_id];
> +err:
> + return NULL;
> +}
> +
> +static int q6asm_srvc_callback(struct apr_device *adev, struct 
> apr_client_data *data)
> +{
> + struct q6asm *q6asm = dev_get_drvdata(&adev->dev);
> + struct audio_client *ac = NULL;
> + uint32_t sid = 0;

This is 4 bits, so just use int.

> + uint32_t *payload;

payload is unused.

> +
> + if (!data) {
> + dev_err(&adev->dev, "%s: Invalid CB\n", __func__);
> + return 0;
> + }

Again, define the apr to never invoke the callback with data = NULL

> +
> + payload = data->payload;
> + sid = (data->token >> 8) & 0x0F;
> + ac = q6asm_get_audio_client(q6asm, sid);
> + if (!ac) {
> + dev_err(&adev->dev, "Audio Client not active\n");
> + return 0;
> + }
> +
> + if (ac->cb)
> + ac->cb(data->opcode, data->token, data->payload, ac->priv);
> + return 0;
> +}
> +
> +/**
> + * q6asm_get_session_id() - get session id for audio client
> + *
> + * @ac: audio client pointer
> + *
> + * Return: Will be an session id of the audio client.
> + */
> +int q6asm_get_session_id(struct audio_client *c)
> +{
> + return c->session;
> +}
> +EXPORT_SYMBOL

Re: [PATCH 9/9] scsi: bnx2i: Use zeroing allocator rather than allocator/memset

2018-01-01 Thread Rangankar, Manish


On 30/12/17 8:58 PM, "Himanshu Jha"  wrote:

>Use dma_zalloc_coherent instead of dma_alloc_coherent followed by
>memset 0.
>
>Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
>
>Suggested-by: Luis R. Rodriguez 
>Signed-off-by: Himanshu Jha 
>---
> drivers/scsi/bnx2i/bnx2i_hwi.c | 14 ++
> 1 file changed, 6 insertions(+), 8 deletions(-)
>
>diff --git a/drivers/scsi/bnx2i/bnx2i_hwi.c
>b/drivers/scsi/bnx2i/bnx2i_hwi.c
>index 9e3bf53..c6a0bd6 100644
>--- a/drivers/scsi/bnx2i/bnx2i_hwi.c
>+++ b/drivers/scsi/bnx2i/bnx2i_hwi.c
>@@ -1069,16 +1069,15 @@ int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba,
>struct bnx2i_endpoint *ep)
>   }
> 
>   /* Allocate memory area for actual SQ element */
>-  ep->qp.sq_virt =
>-  dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
>- &ep->qp.sq_phys, GFP_KERNEL);
>+  ep->qp.sq_virt =
>+  dma_zalloc_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
>+  &ep->qp.sq_phys, GFP_KERNEL);
>   if (!ep->qp.sq_virt) {
>   printk(KERN_ALERT "bnx2i: unable to alloc SQ BD memory %d\n",
> ep->qp.sq_mem_size);
>   goto mem_alloc_err;
>   }
> 
>-  memset(ep->qp.sq_virt, 0x00, ep->qp.sq_mem_size);
>   ep->qp.sq_first_qe = ep->qp.sq_virt;
>   ep->qp.sq_prod_qe = ep->qp.sq_first_qe;
>   ep->qp.sq_cons_qe = ep->qp.sq_first_qe;
>@@ -1106,15 +1105,14 @@ int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba,
>struct bnx2i_endpoint *ep)
>   }
> 
>   /* Allocate memory area for actual CQ element */
>-  ep->qp.cq_virt =
>-  dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
>- &ep->qp.cq_phys, GFP_KERNEL);
>+  ep->qp.cq_virt =
>+  dma_zalloc_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
>+  &ep->qp.cq_phys, GFP_KERNEL);
>   if (!ep->qp.cq_virt) {
>   printk(KERN_ALERT "bnx2i: unable to alloc CQ BD memory %d\n",
> ep->qp.cq_mem_size);
>   goto mem_alloc_err;
>   }
>-  memset(ep->qp.cq_virt, 0x00, ep->qp.cq_mem_size);
> 
>   ep->qp.cq_first_qe = ep->qp.cq_virt;
>   ep->qp.cq_prod_qe = ep->qp.cq_first_qe;
>-- 
>2.7.4

Acked-by: Manish Rangankar 


>



Re: [PATCH v8 1/2] tpm_tis: Move ilb_base_addr to tpm_tis_data

2018-01-01 Thread Jason Gunthorpe
On Mon, Jan 01, 2018 at 08:05:43PM -0800, Azhar Shaikh wrote:

> - return tpm_chip_register(chip);
> + rc = tpm_chip_register(chip);
> + if (rc && is_bsw())
> + iounmap(priv->ilb_base_addr);
> +
> + return rc;
>  out_err:
>   tpm_tis_remove(chip);
> + if (is_bsw())
> + iounmap(priv->ilb_base_addr);
> +
>   return rc;
>  }

I thought you were resending this to fix the above, why is is it still
wonky?

Jason


Re: [PATCH 3/9] scsi: qedi: Use zeroing allocator instead of allocator/memset

2018-01-01 Thread Rangankar, Manish


On 30/12/17 8:58 PM, "Himanshu Jha"  wrote:

>Use dma_zalloc_coherent instead of dma_alloc_coherent followed by memset
>0.
>
>Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
>
>Suggested-by: Luis R. Rodriguez 
>Signed-off-by: Himanshu Jha 
>---
> drivers/scsi/qedi/qedi_main.c | 42
>+++---
> 1 file changed, 15 insertions(+), 27 deletions(-)
>
>diff --git a/drivers/scsi/qedi/qedi_main.c b/drivers/scsi/qedi/qedi_main.c
>index 34a..5ef0b36 100644
>--- a/drivers/scsi/qedi/qedi_main.c
>+++ b/drivers/scsi/qedi/qedi_main.c
>@@ -1268,16 +1268,14 @@ static int qedi_alloc_bdq(struct qedi_ctx *qedi)
>   }
> 
>   /* Allocate list of PBL pages */
>-  qedi->bdq_pbl_list = dma_alloc_coherent(&qedi->pdev->dev,
>-  PAGE_SIZE,
>-  &qedi->bdq_pbl_list_dma,
>-  GFP_KERNEL);
>+  qedi->bdq_pbl_list = dma_zalloc_coherent(&qedi->pdev->dev, PAGE_SIZE,
>+   &qedi->bdq_pbl_list_dma,
>+   GFP_KERNEL);
>   if (!qedi->bdq_pbl_list) {
>   QEDI_ERR(&qedi->dbg_ctx,
>"Could not allocate list of PBL pages.\n");
>   return -ENOMEM;
>   }
>-  memset(qedi->bdq_pbl_list, 0, PAGE_SIZE);
> 
>   /*
>* Now populate PBL list with pages that contain pointers to the
>@@ -1367,11 +1365,10 @@ static int qedi_alloc_global_queues(struct
>qedi_ctx *qedi)
>   (qedi->global_queues[i]->cq_pbl_size +
>   (QEDI_PAGE_SIZE - 1));
> 
>-  qedi->global_queues[i]->cq =
>-  dma_alloc_coherent(&qedi->pdev->dev,
>- qedi->global_queues[i]->cq_mem_size,
>- &qedi->global_queues[i]->cq_dma,
>- GFP_KERNEL);
>+  qedi->global_queues[i]->cq =
>+  dma_zalloc_coherent(&qedi->pdev->dev,
>+  qedi->global_queues[i]->cq_mem_size,
>+  &qedi->global_queues[i]->cq_dma,
>+  GFP_KERNEL);
> 
>   if (!qedi->global_queues[i]->cq) {
>   QEDI_WARN(&qedi->dbg_ctx,
>@@ -1379,14 +1376,10 @@ static int qedi_alloc_global_queues(struct
>qedi_ctx *qedi)
>   status = -ENOMEM;
>   goto mem_alloc_failure;
>   }
>-  memset(qedi->global_queues[i]->cq, 0,
>- qedi->global_queues[i]->cq_mem_size);
>-
>-  qedi->global_queues[i]->cq_pbl =
>-  dma_alloc_coherent(&qedi->pdev->dev,
>- qedi->global_queues[i]->cq_pbl_size,
>- &qedi->global_queues[i]->cq_pbl_dma,
>- GFP_KERNEL);
>+  qedi->global_queues[i]->cq_pbl =
>+  dma_zalloc_coherent(&qedi->pdev->dev,
>+  qedi->global_queues[i]->cq_pbl_size,
>+  &qedi->global_queues[i]->cq_pbl_dma,
>+  GFP_KERNEL);
> 
>   if (!qedi->global_queues[i]->cq_pbl) {
>   QEDI_WARN(&qedi->dbg_ctx,
>@@ -1394,8 +1387,6 @@ static int qedi_alloc_global_queues(struct qedi_ctx
>*qedi)
>   status = -ENOMEM;
>   goto mem_alloc_failure;
>   }
>-  memset(qedi->global_queues[i]->cq_pbl, 0,
>- qedi->global_queues[i]->cq_pbl_size);
> 
>   /* Create PBL */
>   num_pages = qedi->global_queues[i]->cq_mem_size /
>@@ -1456,25 +1447,22 @@ int qedi_alloc_sq(struct qedi_ctx *qedi, struct
>qedi_endpoint *ep)
>   ep->sq_pbl_size = (ep->sq_mem_size / QEDI_PAGE_SIZE) * sizeof(void *);
>   ep->sq_pbl_size = ep->sq_pbl_size + QEDI_PAGE_SIZE;
> 
>-  ep->sq = dma_alloc_coherent(&qedi->pdev->dev, ep->sq_mem_size,
>-  &ep->sq_dma, GFP_KERNEL);
>+  ep->sq = dma_zalloc_coherent(&qedi->pdev->dev, ep->sq_mem_size,
>+   &ep->sq_dma, GFP_KERNEL);
>   if (!ep->sq) {
>   QEDI_WARN(&qedi->dbg_ctx,
> "Could not allocate send queue.\n");
>   rval = -ENOMEM;
>   goto out;
>   }
>-  memset(ep->sq, 0, ep->sq_mem_size);
>-
>-  ep->sq_pbl = dma_alloc_coherent(&qedi->pdev->dev, ep->sq_pbl_size,
>-  &ep->sq_pbl_dma, GFP_KERNEL);
>+  ep->sq_pbl = dma_zalloc_coherent(&qedi->pdev->dev, ep->sq_pbl_size,
>+   &ep->sq_pbl_dma, GFP_KERNEL);
>   if (!ep->sq_pbl) {
>   QEDI_WARN(&qedi->dbg_ctx,
>  

Re: [PATCH 1/9] scsi: qla4xxx: Use zeroing allocator rather than allocator/memset

2018-01-01 Thread Rangankar, Manish


On 30/12/17 8:58 PM, "Himanshu Jha"  wrote:

>Use dma_zalloc_coherent instead of dma_alloc_coherent followed by memset
>0.
>
>Generated-by: scripts/coccinelle/api/alloc/kzalloc-simple.cocci
>
>Suggested-by: Luis R. Rodriguez 
>Signed-off-by: Himanshu Jha 
>---
> drivers/scsi/qla4xxx/ql4_init.c |  5 ++---
> drivers/scsi/qla4xxx/ql4_mbx.c  | 21 +
> drivers/scsi/qla4xxx/ql4_nx.c   |  5 ++---
> drivers/scsi/qla4xxx/ql4_os.c   | 12 +---
> 4 files changed, 18 insertions(+), 25 deletions(-)
>
>diff --git a/drivers/scsi/qla4xxx/ql4_init.c
>b/drivers/scsi/qla4xxx/ql4_init.c
>index 5d6d158..52b1a0b 100644
>--- a/drivers/scsi/qla4xxx/ql4_init.c
>+++ b/drivers/scsi/qla4xxx/ql4_init.c
>@@ -153,15 +153,14 @@ int qla4xxx_get_sys_info(struct scsi_qla_host *ha)
>   dma_addr_t sys_info_dma;
>   int status = QLA_ERROR;
> 
>-  sys_info = dma_alloc_coherent(&ha->pdev->dev, sizeof(*sys_info),
>-&sys_info_dma, GFP_KERNEL);
>+  sys_info = dma_zalloc_coherent(&ha->pdev->dev, sizeof(*sys_info),
>+ &sys_info_dma, GFP_KERNEL);
>   if (sys_info == NULL) {
>   DEBUG2(printk("scsi%ld: %s: Unable to allocate dma buffer.\n",
> ha->host_no, __func__));
> 
>   goto exit_get_sys_info_no_free;
>   }
>-  memset(sys_info, 0, sizeof(*sys_info));
> 
>   /* Get flash sys info */
>   if (qla4xxx_get_flash(ha, sys_info_dma, FLASH_OFFSET_SYS_INFO,
>diff --git a/drivers/scsi/qla4xxx/ql4_mbx.c
>b/drivers/scsi/qla4xxx/ql4_mbx.c
>index 1da04f3..bda2e64 100644
>--- a/drivers/scsi/qla4xxx/ql4_mbx.c
>+++ b/drivers/scsi/qla4xxx/ql4_mbx.c
>@@ -625,15 +625,14 @@ int qla4xxx_initialize_fw_cb(struct scsi_qla_host *
>ha)
>   uint32_t mbox_sts[MBOX_REG_COUNT];
>   int status = QLA_ERROR;
> 
>-  init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
>-  sizeof(struct addr_ctrl_blk),
>-  &init_fw_cb_dma, GFP_KERNEL);
>+  init_fw_cb = dma_zalloc_coherent(&ha->pdev->dev,
>+   sizeof(struct addr_ctrl_blk),
>+   &init_fw_cb_dma, GFP_KERNEL);
>   if (init_fw_cb == NULL) {
>   DEBUG2(printk("scsi%ld: %s: Unable to alloc init_cb\n",
> ha->host_no, __func__));
>   goto exit_init_fw_cb_no_free;
>   }
>-  memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
> 
>   /* Get Initialize Firmware Control Block. */
>   memset(&mbox_cmd, 0, sizeof(mbox_cmd));
>@@ -710,9 +709,9 @@ int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host
>* ha)
>   uint32_t mbox_cmd[MBOX_REG_COUNT];
>   uint32_t mbox_sts[MBOX_REG_COUNT];
> 
>-  init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
>-  sizeof(struct addr_ctrl_blk),
>-  &init_fw_cb_dma, GFP_KERNEL);
>+  init_fw_cb = dma_zalloc_coherent(&ha->pdev->dev,
>+   sizeof(struct addr_ctrl_blk),
>+   &init_fw_cb_dma, GFP_KERNEL);
>   if (init_fw_cb == NULL) {
>   printk("scsi%ld: %s: Unable to alloc init_cb\n", ha->host_no,
>  __func__);
>@@ -720,7 +719,6 @@ int qla4xxx_get_dhcp_ip_address(struct scsi_qla_host
>* ha)
>   }
> 
>   /* Get Initialize Firmware Control Block. */
>-  memset(init_fw_cb, 0, sizeof(struct addr_ctrl_blk));
>   if (qla4xxx_get_ifcb(ha, &mbox_cmd[0], &mbox_sts[0], init_fw_cb_dma) !=
>   QLA_SUCCESS) {
>   DEBUG2(printk("scsi%ld: %s: Failed to get init_fw_ctrl_blk\n",
>@@ -1342,16 +1340,15 @@ int qla4xxx_about_firmware(struct scsi_qla_host
>*ha)
>   uint32_t mbox_sts[MBOX_REG_COUNT];
>   int status = QLA_ERROR;
> 
>-  about_fw = dma_alloc_coherent(&ha->pdev->dev,
>-sizeof(struct about_fw_info),
>-&about_fw_dma, GFP_KERNEL);
>+  about_fw = dma_zalloc_coherent(&ha->pdev->dev,
>+ sizeof(struct about_fw_info),
>+ &about_fw_dma, GFP_KERNEL);
>   if (!about_fw) {
>   DEBUG2(ql4_printk(KERN_ERR, ha, "%s: Unable to alloc memory "
> "for about_fw\n", __func__));
>   return status;
>   }
> 
>-  memset(about_fw, 0, sizeof(struct about_fw_info));
>   memset(&mbox_cmd, 0, sizeof(mbox_cmd));
>   memset(&mbox_sts, 0, sizeof(mbox_sts));
> 
>diff --git a/drivers/scsi/qla4xxx/ql4_nx.c b/drivers/scsi/qla4xxx/ql4_nx.c
>index e91abb3..968bd85 100644
>--- a/drivers/scsi/qla4xxx/ql4_nx.c
>+++ b/drivers/scsi/qla4xxx/ql4_nx.c
>@@ -4050,15 +4050,14 @@ int qla4_8xxx_get_sys_info(struct scsi_qla_host
>*ha)
>   dma_addr_t sys_info_dma;
>   int status = QLA_ERROR;
> 
>-  sys_info = dma_al

[PATCH v8 2/2] tpm: Keep CLKRUN enabled throughout the duration of transmit_cmd()

2018-01-01 Thread Azhar Shaikh
Commit 5e572cab92f0bb5 ("tpm: Enable CLKRUN protocol for Braswell
systems") disabled CLKRUN protocol during TPM transactions and re-enabled
once the transaction is completed. But there were still some corner cases
observed where, reading of TPM header failed for savestate command
while going to suspend, which resulted in suspend failure.
To fix this issue keep the CLKRUN protocol disabled for the entire
duration of a single TPM command and not disabling and re-enabling
again for every TPM transaction. For the other TPM accesses outside
TPM command flow, add a higher level of disabling and re-enabling
the CLKRUN protocol, instead of doing for every TPM transaction.

Fixes: 5e572cab92f0bb5 ("tpm: Enable CLKRUN protocol for Braswell systems")

Signed-off-by: Azhar Shaikh 
Reviewed-by: Jarkko Sakkinen  
Tested-by: Jarkko Sakkinen  
Signed-off-by: Jarkko Sakkinen  
---
 drivers/char/tpm/tpm-interface.c |   6 +++
 drivers/char/tpm/tpm_tis.c   |  94 --
 drivers/char/tpm/tpm_tis_core.c  | 108 +++
 drivers/char/tpm/tpm_tis_core.h  |   4 ++
 include/linux/tpm.h  |   1 +
 5 files changed, 119 insertions(+), 94 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index af355bd97bea..76df4fbcf089 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -425,6 +425,9 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct 
tpm_space *space,
if (chip->dev.parent)
pm_runtime_get_sync(chip->dev.parent);
 
+   if (chip->ops->clk_enable != NULL)
+   chip->ops->clk_enable(chip, true);
+
/* Store the decision as chip->locality will be changed. */
need_locality = chip->locality == -1;
 
@@ -501,6 +504,9 @@ ssize_t tpm_transmit(struct tpm_chip *chip, struct 
tpm_space *space,
chip->locality = -1;
}
 out_no_locality:
+   if (chip->ops->clk_enable != NULL)
+   chip->ops->clk_enable(chip, false);
+
if (chip->dev.parent)
pm_runtime_put_sync(chip->dev.parent);
 
diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index 923f8f2cbaca..1bcbf355141e 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -133,79 +133,17 @@ static int check_acpi_tpm2(struct device *dev)
 }
 #endif
 
-#ifdef CONFIG_X86
-#define LPC_CNTRL_OFFSET   0x84
-#define LPC_CLKRUN_EN  (1 << 2)
-
-/**
- * tpm_platform_begin_xfer() - clear LPC CLKRUN_EN i.e. clocks will be running
- */
-static void tpm_platform_begin_xfer(struct tpm_tis_data *data)
-{
-   u32 clkrun_val;
-
-   if (!is_bsw())
-   return;
-
-   clkrun_val = ioread32(data->ilb_base_addr + LPC_CNTRL_OFFSET);
-
-   /* Disable LPC CLKRUN# */
-   clkrun_val &= ~LPC_CLKRUN_EN;
-   iowrite32(clkrun_val, data->ilb_base_addr + LPC_CNTRL_OFFSET);
-
-   /*
-* Write any random value on port 0x80 which is on LPC, to make
-* sure LPC clock is running before sending any TPM command.
-*/
-   outb(0xCC, 0x80);
-
-}
-
-/**
- * tpm_platform_end_xfer() - set LPC CLKRUN_EN i.e. clocks can be turned off
- */
-static void tpm_platform_end_xfer(struct tpm_tis_data *data)
-{
-   u32 clkrun_val;
-
-   if (!is_bsw())
-   return;
-
-   clkrun_val = ioread32(data->ilb_base_addr + LPC_CNTRL_OFFSET);
-
-   /* Enable LPC CLKRUN# */
-   clkrun_val |= LPC_CLKRUN_EN;
-   iowrite32(clkrun_val, data->ilb_base_addr + LPC_CNTRL_OFFSET);
-
-   /*
-* Write any random value on port 0x80 which is on LPC, to make
-* sure LPC clock is running before sending any TPM command.
-*/
-   outb(0xCC, 0x80);
-
-}
-#else
-static void tpm_platform_begin_xfer(struct tpm_tis_data *data)
-{
-}
-
-static void tpm_platform_end_xfer(struct tpm_tis_data *data)
-{
-}
-#endif
-
 static int tpm_tcg_read_bytes(struct tpm_tis_data *data, u32 addr, u16 len,
  u8 *result)
 {
struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
 
-   tpm_platform_begin_xfer(data);
+   if (is_bsw() && !(data->flags & TPM_TIS_CLK_ENABLE))
+   WARN(1, "CLKRUN not enabled!\n");
 
while (len--)
*result++ = ioread8(phy->iobase + addr);
 
-   tpm_platform_end_xfer(data);
-
return 0;
 }
 
@@ -214,13 +152,12 @@ static int tpm_tcg_write_bytes(struct tpm_tis_data *data, 
u32 addr, u16 len,
 {
struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
 
-   tpm_platform_begin_xfer(data);
+   if (is_bsw() && !(data->flags & TPM_TIS_CLK_ENABLE))
+   WARN(1, "CLKRUN not enabled!\n");
 
while (len--)
iowrite8(*value++, phy->iobase + addr);
 
-   tpm_platform_end_xfer(data);
-
return 0;
 }
 
@@ -228,12 +165,11 @@ static int tpm_tcg_read16(struct tpm_tis_data *data, u32 
addr, u16 *resul

[PATCH v8 0/2] Fix corner cases with disabling CLKRUN in tpm_tis

2018-01-01 Thread Azhar Shaikh
Changes from v1:
- Patch 1: "tpm: Keep CLKRUN enabled throughout the duration of transmit_cmd()"
  - Add NULL checks before calling clk_toggle callback
  - Use IS_ENABLED instead of ifdef in tpm_tis_clkrun_toggle()
  - Do not call tpm_platform_begin_xfer() and tpm_platform_end_xfer()
from tpm_tis_clkrun_toggle(). Make them static again.

- Patch 2: "tpm_tis: Move ilb_base_addr to tpm_tis_tcg_phy"
  - This is a new patch in this series as per suggestion from Jason.
  - Is the current implementation ok or I should move the code in 
tpm_tis_pnp_remove()
and tpm_tis_plat_remove() inside tpm_tis_remove(). That way all the 
unmapping
can be done in one place, instead of 3 different places now. Also the 
unmapping
in tpm_tis_init() can be moved to tpm_tis_remove(), since in case of error
tpm_tis_core_init() calls tpm_tis_remove(). Kindly suggest.

Changes from v2:
- Patch 1: "tpm: Keep CLKRUN enabled throughout the duration of transmit_cmd()"
  - No changes

- Patch 2: "tpm_tis: Move ilb_base_addr to tpm_tis_tcg_phy"
  - Updated is_bsw() function to have the #ifdef CONFIG_X86 check within the 
function
itself. Also removed the #ifdef CONFIG_X86 from all other places around 
is_bsw()

Changes from v3:
- Patch 1: "tpm: Keep CLKRUN enabled throughout the duration of transmit_cmd()"
  - Change function name from clk_toggle to clk_enable
  - Update the commit message.

- Patch 2: "tpm_tis: Move ilb_base_addr to tpm_tis_tcg_phy"
  - No changes

Changes from v4:
- The numbering of patches is now interchanged.

- Patch 1: "tpm_tis: Move ilb_base_addr to tpm_tis_data"
  - Had to move ilb_base_addr to tpm_tis_data, from tpm_tis_tcg_phy.
Since the ioremapping of ilb_base_addr had to be done before any TPM access,
hence moved the variable to tpm_tis_data.
  - Also move the ioremapping of ilb_base_addr from tpm_tis_init() to
tpm_tis_core_init() i.e. before any TPM access is done.
  - Rename marco LPC_CNTRL_REG_OFFSET to LPC_CNTRL_OFFSET
  - Update the commit message.

- Patch 2: "tpm: Keep CLKRUN enabled throughout the duration of transmit_cmd()"
  - Remove the functions tpm_platform_begin_xfer() and tpm_platform_end_xfer()
  - Move the code from these functions to tpm_tis_clkrun_enable().

Changes from v5:
- Patch 1: "tpm_tis: Move ilb_base_addr to tpm_tis_data"
  - No changes

- Patch 2: "tpm: Keep CLKRUN enabled throughout the duration of transmit_cmd()"
  - Update the commit message.

Changes from v6:
- - Patch 1: "tpm_tis: Move ilb_base_addr to tpm_tis_data"
  - No changes

- Patch 2: "tpm: Keep CLKRUN enabled throughout the duration of transmit_cmd()"
  - chip->ops was set to NULL in tpm_del_char_device() called from 
tpm_chip_unregister() in
error/driver exit path. Fix this code. (Suggested by Javier Martinez 
Canillas and Jason Gunthorpe)
  - Add a comment in tpm_tis_clkrun_enable() function.

Changes from v7:
- Patch 1: "tpm_tis: Move ilb_base_addr to tpm_tis_data"
  - No changes

- Patch 2: "tpm: Keep CLKRUN enabled throughout the duration of transmit_cmd()"
  - Remove unused variables warnings from tpm_tis_pnp_remove() and 
tpm_tis_plat_remove()
(Suggested by Stephen Rothwell )

Azhar Shaikh (2):
  tpm_tis: Move ilb_base_addr to tpm_tis_data
  tpm: Keep CLKRUN enabled throughout the duration of transmit_cmd()

 drivers/char/tpm/tpm-interface.c |   6 +++
 drivers/char/tpm/tpm_tis.c   | 113 --
 drivers/char/tpm/tpm_tis_core.c  | 114 ---
 drivers/char/tpm/tpm_tis_core.h  |  17 ++
 include/linux/tpm.h  |   1 +
 5 files changed, 142 insertions(+), 109 deletions(-)

-- 
1.9.1



RE: linux-next: build warning after merge of the tpmdd tree

2018-01-01 Thread Shaikh, Azhar
Hi Stephen,

Thanks for reporting this.

I have uploaded new patchset to tpmdd mailing list.

Regards,
Azhar Shaikh

>-Original Message-
>From: Stephen Rothwell [mailto:s...@canb.auug.org.au]
>Sent: Monday, January 1, 2018 6:51 PM
>To: Jarkko Sakkinen 
>Cc: Linux-Next Mailing List ; Linux Kernel Mailing
>List ; Shaikh, Azhar 
>Subject: linux-next: build warning after merge of the tpmdd tree
>
>Hi Jarkko,
>
>After merging the tpmdd tree, today's linux-next build (x86_64
>allmodconfig) produced this warning:
>
>drivers/char/tpm/tpm_tis.c: In function 'tpm_tis_pnp_remove':
>drivers/char/tpm/tpm_tis.c:274:23: warning: unused variable 'priv' [-
>Wunused-variable]
>  struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
>   ^
>drivers/char/tpm/tpm_tis.c: In function 'tpm_tis_plat_remove':
>drivers/char/tpm/tpm_tis.c:324:23: warning: unused variable 'priv' [-
>Wunused-variable]
>  struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
>   ^
>
>Introduced by commit
>
>  6d0866cbc2d3 ("tpm: Keep CLKRUN enabled throughout the duration of
>transmit_cmd()")
>
>--
>Cheers,
>Stephen Rothwell


[PATCH v8 1/2] tpm_tis: Move ilb_base_addr to tpm_tis_data

2018-01-01 Thread Azhar Shaikh
Move static variable ilb_base_addr to tpm_tis_data.

Signed-off-by: Azhar Shaikh 
Reviewed-by: Jarkko Sakkinen  
Tested-by: Jarkko Sakkinen  
Signed-off-by: Jarkko Sakkinen  
---
 drivers/char/tpm/tpm_tis.c  | 75 +++--
 drivers/char/tpm/tpm_tis_core.c | 16 -
 drivers/char/tpm/tpm_tis_core.h | 13 +++
 3 files changed, 56 insertions(+), 48 deletions(-)

diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index e2d1055fb814..923f8f2cbaca 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -134,33 +134,24 @@ static int check_acpi_tpm2(struct device *dev)
 #endif
 
 #ifdef CONFIG_X86
-#define INTEL_LEGACY_BLK_BASE_ADDR  0xFED08000
-#define ILB_REMAP_SIZE 0x100
-#define LPC_CNTRL_REG_OFFSET0x84
-#define LPC_CLKRUN_EN   (1 << 2)
-
-static void __iomem *ilb_base_addr;
-
-static inline bool is_bsw(void)
-{
-   return ((boot_cpu_data.x86_model == INTEL_FAM6_ATOM_AIRMONT) ? 1 : 0);
-}
+#define LPC_CNTRL_OFFSET   0x84
+#define LPC_CLKRUN_EN  (1 << 2)
 
 /**
  * tpm_platform_begin_xfer() - clear LPC CLKRUN_EN i.e. clocks will be running
  */
-static void tpm_platform_begin_xfer(void)
+static void tpm_platform_begin_xfer(struct tpm_tis_data *data)
 {
u32 clkrun_val;
 
if (!is_bsw())
return;
 
-   clkrun_val = ioread32(ilb_base_addr + LPC_CNTRL_REG_OFFSET);
+   clkrun_val = ioread32(data->ilb_base_addr + LPC_CNTRL_OFFSET);
 
/* Disable LPC CLKRUN# */
clkrun_val &= ~LPC_CLKRUN_EN;
-   iowrite32(clkrun_val, ilb_base_addr + LPC_CNTRL_REG_OFFSET);
+   iowrite32(clkrun_val, data->ilb_base_addr + LPC_CNTRL_OFFSET);
 
/*
 * Write any random value on port 0x80 which is on LPC, to make
@@ -173,18 +164,18 @@ static void tpm_platform_begin_xfer(void)
 /**
  * tpm_platform_end_xfer() - set LPC CLKRUN_EN i.e. clocks can be turned off
  */
-static void tpm_platform_end_xfer(void)
+static void tpm_platform_end_xfer(struct tpm_tis_data *data)
 {
u32 clkrun_val;
 
if (!is_bsw())
return;
 
-   clkrun_val = ioread32(ilb_base_addr + LPC_CNTRL_REG_OFFSET);
+   clkrun_val = ioread32(data->ilb_base_addr + LPC_CNTRL_OFFSET);
 
/* Enable LPC CLKRUN# */
clkrun_val |= LPC_CLKRUN_EN;
-   iowrite32(clkrun_val, ilb_base_addr + LPC_CNTRL_REG_OFFSET);
+   iowrite32(clkrun_val, data->ilb_base_addr + LPC_CNTRL_OFFSET);
 
/*
 * Write any random value on port 0x80 which is on LPC, to make
@@ -194,16 +185,11 @@ static void tpm_platform_end_xfer(void)
 
 }
 #else
-static inline bool is_bsw(void)
-{
-   return false;
-}
-
-static void tpm_platform_begin_xfer(void)
+static void tpm_platform_begin_xfer(struct tpm_tis_data *data)
 {
 }
 
-static void tpm_platform_end_xfer(void)
+static void tpm_platform_end_xfer(struct tpm_tis_data *data)
 {
 }
 #endif
@@ -213,12 +199,12 @@ static int tpm_tcg_read_bytes(struct tpm_tis_data *data, 
u32 addr, u16 len,
 {
struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
 
-   tpm_platform_begin_xfer();
+   tpm_platform_begin_xfer(data);
 
while (len--)
*result++ = ioread8(phy->iobase + addr);
 
-   tpm_platform_end_xfer();
+   tpm_platform_end_xfer(data);
 
return 0;
 }
@@ -228,12 +214,12 @@ static int tpm_tcg_write_bytes(struct tpm_tis_data *data, 
u32 addr, u16 len,
 {
struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
 
-   tpm_platform_begin_xfer();
+   tpm_platform_begin_xfer(data);
 
while (len--)
iowrite8(*value++, phy->iobase + addr);
 
-   tpm_platform_end_xfer();
+   tpm_platform_end_xfer(data);
 
return 0;
 }
@@ -242,11 +228,11 @@ static int tpm_tcg_read16(struct tpm_tis_data *data, u32 
addr, u16 *result)
 {
struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
 
-   tpm_platform_begin_xfer();
+   tpm_platform_begin_xfer(data);
 
*result = ioread16(phy->iobase + addr);
 
-   tpm_platform_end_xfer();
+   tpm_platform_end_xfer(data);
 
return 0;
 }
@@ -255,11 +241,11 @@ static int tpm_tcg_read32(struct tpm_tis_data *data, u32 
addr, u32 *result)
 {
struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
 
-   tpm_platform_begin_xfer();
+   tpm_platform_begin_xfer(data);
 
*result = ioread32(phy->iobase + addr);
 
-   tpm_platform_end_xfer();
+   tpm_platform_end_xfer(data);
 
return 0;
 }
@@ -268,11 +254,11 @@ static int tpm_tcg_write32(struct tpm_tis_data *data, u32 
addr, u32 value)
 {
struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
 
-   tpm_platform_begin_xfer();
+   tpm_platform_begin_xfer(data);
 
iowrite32(value, phy->iobase + addr);
 
-   tpm_platform_end_xfer();
+   tpm_platform_end_xfer(data);
 
return 0;
 }
@@ -351,9 +337,13 @@ sta

[PATCH -next] tee: shm: make local function __tee_shm_alloc() static

2018-01-01 Thread Wei Yongjun
Fixes the following sparse warnings:

drivers/tee/tee_shm.c:115:16: warning:
 symbol '__tee_shm_alloc' was not declared. Should it be static?

Signed-off-by: Wei Yongjun 
---
 drivers/tee/tee_shm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c
index 04e1b8b..13b4de1 100644
--- a/drivers/tee/tee_shm.c
+++ b/drivers/tee/tee_shm.c
@@ -112,9 +112,9 @@ static int tee_shm_op_mmap(struct dma_buf *dmabuf, struct 
vm_area_struct *vma)
.mmap = tee_shm_op_mmap,
 };
 
-struct tee_shm *__tee_shm_alloc(struct tee_context *ctx,
-   struct tee_device *teedev,
-   size_t size, u32 flags)
+static struct tee_shm *__tee_shm_alloc(struct tee_context *ctx,
+  struct tee_device *teedev,
+  size_t size, u32 flags)
 {
struct tee_shm_pool_mgr *poolm = NULL;
struct tee_shm *shm;



[PATCH -next] soundwire: Fix typo in return value check of sdw_read()

2018-01-01 Thread Wei Yongjun
Fix the typo, 'status' should be instead of 'status2'.

Fixes: b0a9c37b0178 ("soundwire: Add slave status handling")
Signed-off-by: Wei Yongjun 
---
 drivers/soundwire/bus.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
index 4c34519..266d2b3 100644
--- a/drivers/soundwire/bus.c
+++ b/drivers/soundwire/bus.c
@@ -671,8 +671,8 @@ static int sdw_handle_dp0_interrupt(struct sdw_slave 
*slave, u8 *slave_status)
status2 = sdw_read(slave, SDW_DP0_INT);
if (status2 < 0) {
dev_err(slave->bus->dev,
-   "SDW_DP0_INT read failed:%d", status);
-   return status;
+   "SDW_DP0_INT read failed:%d", status2);
+   return status2;
}
status &= status2;
 
@@ -741,10 +741,10 @@ static int sdw_handle_port_interrupt(struct sdw_slave 
*slave,
 
/* Read DPN interrupt again */
status2 = sdw_read(slave, addr);
-   if (status < 0) {
+   if (status2 < 0) {
dev_err(slave->bus->dev,
-   "SDW_DPN_INT read failed:%d", status);
-   return status;
+   "SDW_DPN_INT read failed:%d", status2);
+   return status2;
}
status &= status2;



Re: [PATCH net-next 2/2] tuntap: XDP transmission

2018-01-01 Thread Jason Wang



On 2018年01月01日 11:55, Joe Perches wrote:

On Mon, 2018-01-01 at 11:48 +0800, kbuild test robot wrote:

Hi Jason,

I love your patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:
https://github.com/0day-ci/linux/commits/Jason-Wang/XDP-transmission-for-tuntap/20180101-105946
config: i386-randconfig-x072-201800 (attached as .config)
compiler: gcc-7 (Debian 7.2.0-12) 7.2.1 20171025
reproduce:
 # save the attached .config to linux build tree
 make ARCH=i386

All warnings (new ones prefixed by >>):

drivers//net/tun.c: In function 'tun_xdp_to_ptr':

drivers//net/tun.c:251:9: warning: cast to pointer from integer of different 
size [-Wint-to-pointer-cast]

  return (void *)((unsigned long)ptr | TUN_XDP_FLAG);
 ^
drivers//net/tun.c: In function 'tun_ptr_to_xdp':
drivers//net/tun.c:257:9: warning: cast to pointer from integer of 
different size [-Wint-to-pointer-cast]
  return (void *)((unsigned long)ptr & ~TUN_XDP_FLAG);
 ^

vim +251 drivers//net/tun.c

248 
249 void *tun_xdp_to_ptr(void *ptr)
250 {
  > 251  return (void *)((unsigned long)ptr | TUN_XDP_FLAG);

Does TUN_XDP_FLAG really need to be 0x1ULL?
Wouldn't 0x1UL suffice?



0x1UL should be fine.

Thanks



Re: [PATCH v2] f2fs: add an ioctl to disable GC for specific file

2018-01-01 Thread Chao Yu
On 2018/1/1 9:07, Jaegeuk Kim wrote:
> On 12/29, Chao Yu wrote:
>> On 2017/12/28 11:40, Jaegeuk Kim wrote:
>>> This patch gives a flag to disable GC on given file, which would be useful, 
>>> when
>>> user wants to keep its block map. It also conducts in-place-update for 
>>> dontmove
>>> file.
>>
>> One question, we may encounter out-of-space during foreground GC if there
>> is too many data blocks of pinned files as they are removable.
>>
>> Do we need to record all segments which contain block of pinned file? and
>> then trigger foreground GC more early by adjust threshold in
>> has_not_enough_free_secs.
> 
> This should be used only when application knows how this works. If not, I 
> wanted
> to just unset the flag as much as possible, as foreground GCs have been done 
> for

Well, how can we unset that flag? do we need an extra ioctl interface like
F2FS_IOC_UNPIN_FILE? so that user can keep its data in unpinned file by
calling that interface. Or user can only drop the flag by unlinking pinned
file?

Thanks,

> pinned file too frequently. I expect the usecase must be quite unusual with 
> just
> small number of files in short period likewise atomic files.
> 
> Thanks,
> 
>>
>> Thanks,
>>
>>>
>>> Signed-off-by: Jaegeuk Kim 
>>> ---
>>>
>>> Change log from v2:
>>>  - change the naming from dontmove to pin_file
>>>  - do in-place-update for pinned files
>>>  - use union for i_current_depth with i_gc_failures
>>>  - pass increasing i_gc_failures
>>>
>>>  fs/f2fs/data.c  |  2 ++
>>>  fs/f2fs/f2fs.h  | 29 +-
>>>  fs/f2fs/file.c  | 54 
>>> +
>>>  fs/f2fs/gc.c| 11 ++
>>>  fs/f2fs/gc.h|  2 ++
>>>  fs/f2fs/sysfs.c |  2 ++
>>>  include/linux/f2fs_fs.h |  9 -
>>>  7 files changed, 107 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
>>> index 7aca6ccd01f6..b9fab6186f28 100644
>>> --- a/fs/f2fs/data.c
>>> +++ b/fs/f2fs/data.c
>>> @@ -1394,6 +1394,8 @@ static inline bool need_inplace_update(struct 
>>> f2fs_io_info *fio)
>>>  {
>>> struct inode *inode = fio->page->mapping->host;
>>>  
>>> +   if (f2fs_is_pinned_file(inode))
>>> +   return true;
>>> if (S_ISDIR(inode->i_mode) || f2fs_is_atomic_file(inode))
>>> return false;
>>> if (is_cold_data(fio->page))
>>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
>>> index 65a51b941146..398ed95d4036 100644
>>> --- a/fs/f2fs/f2fs.h
>>> +++ b/fs/f2fs/f2fs.h
>>> @@ -376,6 +376,8 @@ static inline bool __has_cursum_space(struct 
>>> f2fs_journal *journal,
>>>  #define F2FS_IOC_FSGETXATTRFS_IOC_FSGETXATTR
>>>  #define F2FS_IOC_FSSETXATTRFS_IOC_FSSETXATTR
>>>  
>>> +#define F2FS_IOC_PIN_FILE  _IO(F2FS_IOCTL_MAGIC, 13)
>>> +
>>>  struct f2fs_gc_range {
>>> u32 sync;
>>> u64 start;
>>> @@ -586,7 +588,10 @@ struct f2fs_inode_info {
>>> unsigned long i_flags;  /* keep an inode flags for ioctl */
>>> unsigned char i_advise; /* use to give file attribute hints */
>>> unsigned char i_dir_level;  /* use for dentry level for large dir */
>>> -   unsigned int i_current_depth;   /* use only in directory structure */
>>> +   union {
>>> +   unsigned int i_current_depth;   /* only for directory depth */
>>> +   unsigned short i_gc_failures;   /* only for regular file */
>>> +   };
>>> unsigned int i_pino;/* parent inode number */
>>> umode_t i_acl_mode; /* keep file acl mode temporarily */
>>>  
>>> @@ -1130,6 +1135,9 @@ struct f2fs_sb_info {
>>> /* threshold for converting bg victims for fg */
>>> u64 fggc_threshold;
>>>  
>>> +   /* threshold for gc trials on pinned files */
>>> +   u64 gc_pin_file_threshold;
>>> +
>>> /* maximum # of trials to find a victim segment for SSR and GC */
>>> unsigned int max_victim_search;
>>>  
>>> @@ -2119,6 +2127,7 @@ enum {
>>> FI_HOT_DATA,/* indicate file is hot */
>>> FI_EXTRA_ATTR,  /* indicate file has extra attribute */
>>> FI_PROJ_INHERIT,/* indicate file inherits projectid */
>>> +   FI_PIN_FILE,/* indicate file should not be gced */
>>>  };
>>>  
>>>  static inline void __mark_inode_dirty_flag(struct inode *inode,
>>> @@ -2132,6 +2141,7 @@ static inline void __mark_inode_dirty_flag(struct 
>>> inode *inode,
>>> return;
>>> case FI_DATA_EXIST:
>>> case FI_INLINE_DOTS:
>>> +   case FI_PIN_FILE:
>>> f2fs_mark_inode_dirty_sync(inode, true);
>>> }
>>>  }
>>> @@ -2212,6 +,13 @@ static inline void f2fs_i_depth_write(struct inode 
>>> *inode, unsigned int depth)
>>> f2fs_mark_inode_dirty_sync(inode, true);
>>>  }
>>>  
>>> +static inline void f2fs_i_gc_failures_write(struct inode *inode,
>>> +   unsigned int count)
>>> +{
>>> +   F2FS_I(inode)->i_gc_failures = count;
>>> +   f2fs

Re: [PATCH net-next 2/2] tun: allow to attach ebpf socket filter

2018-01-01 Thread Jason Wang



On 2017年12月31日 18:14, Willem de Bruijn wrote:

On Fri, Dec 29, 2017 at 3:44 AM, Jason Wang  wrote:

This patch allows userspace to attach eBPF filter to tun. This will
allow to implement VM dataplane filtering in a more efficient way
compared to cBPF filter.

Is the idea to allow the trusted hypervisor to install these programs,
or the untrusted guests?


Not from guest (but I'm really considering bpf/XDP offload in the 
future, as you suggested in the pass, we probably need a new type other 
than socket filter), the main motivation is to implement vhost-net 
filtering. The idea is let qemu to attach eBPF socket filter to tun.





eBPF privilege escalations like those recently described in
https://lwn.net/Articles/742170/ would give me pause to expose
this to guests.


Right, if underprivileged bpf is disabled by the distribution, it would 
be hard (but still possible):


- Qemu will notify libvirt about rx filter changes of virtio-net
- Libvirt will reprogram the ebpf filter




Signed-off-by: Jason Wang 
---
  drivers/net/tun.c   | 26 ++
  include/uapi/linux/if_tun.h |  1 +
  2 files changed, 27 insertions(+)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 0853829..6e9452b 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -238,6 +238,7 @@ struct tun_struct {
 struct tun_pcpu_stats __percpu *pcpu_stats;
 struct bpf_prog __rcu *xdp_prog;
 struct tun_prog __rcu *steering_prog;
+   struct tun_prog __rcu *filter_prog;
  };

  static int tun_napi_receive(struct napi_struct *napi, int budget)
@@ -984,12 +985,25 @@ static void tun_automq_xmit(struct tun_struct *tun, 
struct sk_buff *skb)
  #endif
  }

+static unsigned int run_ebpf_filter(struct tun_struct *tun,
+   struct sk_buff *skb,
+   int len)
+{
+   struct tun_prog *prog = rcu_dereference(tun->filter_prog);
+
+   if (prog)
+   len = bpf_prog_run_clear_cb(prog->prog, skb);
+
+   return len;
+}
+
  /* Net device start xmit */
  static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev)
  {
 struct tun_struct *tun = netdev_priv(dev);
 int txq = skb->queue_mapping;
 struct tun_file *tfile;
+   int len = skb->len;

 rcu_read_lock();
 tfile = rcu_dereference(tun->tfiles[txq]);
@@ -1015,9 +1029,16 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, 
struct net_device *dev)
 sk_filter(tfile->socket.sk, skb))
 goto drop;

+   len = run_ebpf_filter(tun, skb, len);
+   if (!len)
+   goto drop;
+

This adds a second filter step independent of the sk_filter call above.
Perhaps the two filter interfaces can map onto to the same instance.
I imagine that qemu never programs SO_ATTACH_FILTER.


I think you mean TUNATTACHFILTER here (and we could not assume the tun 
is only used by qemu). A quick glance does not give any idea on how to 
reuse it for eBPF or differ eBPF from cBPF.


Btw, there're other differences. TUNATTACHBPF attach the prog to tun 
which means it simplifies lots of things e.g persist devices or queue 
enabling/disabling.  But TUNATTACHFILTER attach the prog to socket.




More importantly, should this program just return a boolean pass or
drop. Taking a length and trimming may introduce bugs later on if the
stack parses the packet unconditionally, expecting a minimum size
to be present.

This was the reason for introducing sk_filter_trim_cap and using that
in other sk_filter sites.

A quick scan shows that tun_put_user expects a full vlan tag to exist
if skb_vlan_tag_present(skb), for instance. If trimmed to below this
length the final call to skb_copy_datagram_iter may have negative
length.

This is an issue with the existing sk_filter call as much as with the
new run_ebpf_filter call.


Good point, so consider it was used by sk_filter too, we need to fix it 
anyway. Actually, I've considered the boolean return value but finally I 
decide to obey the style of sk filter. Maybe the trimming has real user. 
e.g high speed header recoding/analysis? Consider it's not hard to fix, 
how about just keep that?


Thanks




 if (unlikely(skb_orphan_frags_rx(skb, GFP_ATOMIC)))
 goto drop;

+   if (pskb_trim(skb, len))
+   goto drop;
+
 skb_tx_timestamp(skb);




Re: [PATCH V1 3/4] usb: serial: f81534: add output pin control

2018-01-01 Thread Ji-Ze Hong (Peter Hong)

Hi Johan,


In this code, I'm only read/write 3 registers of 0x2ae8, 0x2a90, 0x2a80,
but some register will read/write more than once. Should I change the
code from port_probe() to attach() and re-write it as:
1: read the 3 register
2: change them will 12 pin desire value
3: write it back
Is it ok?


Do you expect these pins to ever be changed after probe? If not, then
perhaps it can be moved to attach(), but otherwise I guess they should
be set at port_probe(). By using shadow registers, you should be able to
reduce the number of device accesses, but perhaps it's not worth the
complexity.

Do you have a rough idea about how long these register updates take? I
was just worried that these changes will add up to really long probe
times.



I had measured the time of the loop in f81534_set_port_output_pin() via
getnstimeofday() with 685.410 ~ 3681.682us per port, but normally with
600~800us per port. So I prefer remain the current method of
f81534_set_port_output_pin(). Is it ok?

Thanks
--
With Best Regards,
Peter Hong


RE: [PATCH] drm/ttm: optimize errors checking and free _manager when finishing

2018-01-01 Thread He, Roger


-Original Message-
From: Xiongwei Song [mailto:sxwj...@gmail.com] 
Sent: Sunday, December 31, 2017 7:40 PM
To: Koenig, Christian ; He, Roger 
; airl...@linux.ie
Cc: dri-de...@lists.freedesktop.org; linux-kernel@vger.kernel.org
Subject: [PATCH] drm/ttm: optimize errors checking and free _manager when 
finishing

In the function ttm_page_alloc_init, kzalloc call is made for variable 
_manager, we need to check its return value, it may return NULL.

In the function ttm_page_alloc_fini, we need to call kfree for variable 
_manager, instead of make _manager NULL directly.

Signed-off-by: Xiongwei Song 
---
 drivers/gpu/drm/ttm/ttm_page_alloc.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c 
b/drivers/gpu/drm/ttm/ttm_page_alloc.c
index b5ba6441489f..e20a0b8e352b 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
@@ -1007,6 +1007,10 @@ int ttm_page_alloc_init(struct ttm_mem_global *glob, 
unsigned max_pages)
pr_info("Initializing pool allocator\n");
 
_manager = kzalloc(sizeof(*_manager), GFP_KERNEL);
+   if (!_manager) {
+   ret = -ENOMEM;
+   goto out;
+   }
Seems we only need above here for this patch I think. 
The rest is no need, because ttm_pool_kobj_release will kfree _manager.


Thanks
Roger(Hongbo.He)

ttm_page_pool_init_locked(&_manager->wc_pool, GFP_HIGHUSER, "wc", 0);
 
@@ -1034,13 +1038,17 @@ int ttm_page_alloc_init(struct ttm_mem_global *glob, 
unsigned max_pages)
   &glob->kobj, "pool");
if (unlikely(ret != 0)) {
kobject_put(&_manager->kobj);
-   _manager = NULL;
-   return ret;
+   goto out_free_mgr;
}
 
ttm_pool_mm_shrink_init(_manager);
 
return 0;
+out_free_mgr:
+   kfree(_manager);
+   _manager = NULL;
+out:
+   return ret;
 }
 
 void ttm_page_alloc_fini(void)
@@ -1055,6 +1063,7 @@ void ttm_page_alloc_fini(void)
ttm_page_pool_free(&_manager->pools[i], FREE_ALL_PAGES, true);
 
kobject_put(&_manager->kobj);
+   kfree(_manager);
_manager = NULL;
 }
 
--
2.15.1



Re: [PATCH net-next 2/2] tuntap: XDP transmission

2018-01-01 Thread Jason Wang



On 2017年12月29日 20:32, Jesper Dangaard Brouer wrote:

On Fri, 29 Dec 2017 18:00:04 +0800
Jason Wang  wrote:


This patch implements XDP transmission for TAP. Since we can't create
new queues for TAP during XDP set, exist ptr_ring was reused for
queuing XDP buffers. To differ xdp_buff from sk_buff, TUN_XDP_FLAG
(0x1ULL) was encoded into lowest bit of xpd_buff pointer during
ptr_ring_produce, and was decoded during consuming. XDP metadata was
stored in the headroom of the packet which should work in most of
cases since driver usually reserve enough headroom. Very minor changes
were done for vhost_net: it just need to peek the length depends on
the type of pointer.

Tests was done on two Intel E5-2630 2.40GHz machines connected back to
back through two 82599ES. Traffic were generated through MoonGen and
testpmd(rxonly) in guest reports 2.97Mpps when xdp_redirect_map is
doing redirection from ixgbe to TAP.

IMHO a performance measurement without something to compare against is
useless.  What was the performance before?


Forgot to mention, skb mode of xdp_redirect_map gives us 2.5Mpps, so we 
get about 20% improvements.






Cc: Jesper Dangaard Brouer 
Signed-off-by: Jason Wang 
---
  drivers/net/tun.c  | 205 -
  drivers/vhost/net.c|  13 +++-
  include/linux/if_tun.h |  17 
  3 files changed, 197 insertions(+), 38 deletions(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 2c89efe..be6d993 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -240,6 +240,24 @@ struct tun_struct {
struct tun_steering_prog __rcu *steering_prog;
  };
  
+bool tun_is_xdp_buff(void *ptr)

+{
+   return (unsigned long)ptr & TUN_XDP_FLAG;
+}
+EXPORT_SYMBOL(tun_is_xdp_buff);
+
+void *tun_xdp_to_ptr(void *ptr)
+{
+   return (void *)((unsigned long)ptr | TUN_XDP_FLAG);
+}
+EXPORT_SYMBOL(tun_xdp_to_ptr);
+
+void *tun_ptr_to_xdp(void *ptr)
+{
+   return (void *)((unsigned long)ptr & ~TUN_XDP_FLAG);
+}
+EXPORT_SYMBOL(tun_ptr_to_xdp);
+
  static int tun_napi_receive(struct napi_struct *napi, int budget)
  {
struct tun_file *tfile = container_of(napi, struct tun_file, napi);
@@ -630,12 +648,25 @@ static struct tun_struct *tun_enable_queue(struct 
tun_file *tfile)
return tun;
  }
  
+static void tun_ptr_free(void *ptr)

+{
+   if (!ptr)
+   return;
+   if (tun_is_xdp_buff(ptr)) {
+   struct xdp_buff *xdp = tun_ptr_to_xdp(ptr);
+
+   put_page(virt_to_head_page(xdp->data));

(Yet another XDP-free call point, I need to convert to use an accessor
later to transition driver into an xdp_buff return API)


That would be very useful if we can reuse driver specific recycling 
method. (We probably still need some synchronization since tun_ptr_free 
is called in different contexts).





+   } else {
+   __skb_array_destroy_skb(ptr);
+   }
+}
+
  static void tun_queue_purge(struct tun_file *tfile)
  {
-   struct sk_buff *skb;
+   void *ptr;
  
-	while ((skb = ptr_ring_consume(&tfile->tx_ring)) != NULL)

-   kfree_skb(skb);
+   while ((ptr = ptr_ring_consume(&tfile->tx_ring)) != NULL)
+   tun_ptr_free(ptr);
  
  	skb_queue_purge(&tfile->sk.sk_write_queue);

skb_queue_purge(&tfile->sk.sk_error_queue);
@@ -688,8 +719,7 @@ static void __tun_detach(struct tun_file *tfile, bool clean)
unregister_netdevice(tun->dev);
}
if (tun)
-   ptr_ring_cleanup(&tfile->tx_ring,
-__skb_array_destroy_skb);
+   ptr_ring_cleanup(&tfile->tx_ring, tun_ptr_free);
sock_put(&tfile->sk);
}
  }
@@ -1201,6 +1231,54 @@ static const struct net_device_ops tun_netdev_ops = {
.ndo_get_stats64= tun_net_get_stats64,
  };
  
+static int tun_xdp_xmit(struct net_device *dev, struct xdp_buff *xdp)

+{
+   struct tun_struct *tun = netdev_priv(dev);
+   struct xdp_buff *buff = xdp->data_hard_start;
+   int headroom = xdp->data - xdp->data_hard_start;
+   struct tun_file *tfile;
+   u32 numqueues;
+   int ret = 0;
+
+   /* Assure headroom is available and buff is properly aligned */
+   if (unlikely(headroom < sizeof(*xdp) || tun_is_xdp_buff(xdp)))
+   return -ENOSPC;
+
+   *buff = *xdp;
+
+   rcu_read_lock();
+
+   numqueues = READ_ONCE(tun->numqueues);
+   if (!numqueues) {
+   ret = -ENOSPC;
+   goto out;
+   }
+   tfile = rcu_dereference(tun->tfiles[smp_processor_id() %
+   numqueues]);

Several concurrent CPUs can get the same 'tfile'.


Yes, but I believe we don't have better solution here since we can do 
per-cpu queues without notifying guest (userspace).





+   /* Encode the XDP flag into lowest bit for consumer to differ
+* XDP buffer from sk_buff

Re: ACPI issues on cold power on [bisected]

2018-01-01 Thread Joonsoo Kim
On Fri, Dec 29, 2017 at 04:36:59PM +, Jonathan McDowell wrote:
> On Fri, Dec 22, 2017 at 09:21:09AM +0900, Joonsoo Kim wrote:
> > On Fri, Dec 08, 2017 at 03:11:59PM +, Jonathan McDowell wrote:
> > > I've been sitting on this for a while and should have spent time to
> > > investigate sooner, but it's been an odd failure mode that wasn't quite
> > > obvious.
> > > 
> > > In 4.9 if I cold power on my laptop (Dell E7240) it fails to boot - I
> > > don't see anything after grub says its booting. In 4.10 onwards the
> > > laptop boots, but I get an Oops as part of the boot and ACPI is unhappy
> > > (no suspend, no clean poweroff, no ACPI buttons). The Oops is below;
> > > taken from 4.12 as that's the most recent error dmesg I have saved but
> > > also seen back in 4.10. It's always address 0x30 for the dereference.
> > > 
> > > Rebooting the laptop does not lead to these problems; it's *only* from a
> > > complete cold boot that they arise (which didn't help me in terms of
> > > being able to reliably bisect). Once I realised that I was able to
> > > bisect, but it leads me to an odd commit:
> > > 
> > > 86d9f48534e800e4d62cdc1b5aaf539f4c1d47d6
> > > (mm/slab: fix kmemcg cache creation delayed issue)
> > > 
> > > If I revert this then I can cold boot without problems.
> > > 
> > > Also I don't see the problem with a stock Debian kernel, I think because
> > > the ACPI support is modularised.
> > 
> > Sorry for late response. I was on a long vacation.
> 
> No problem. I've been trying to get around to diagnosing this for a
> while now anyway and this isn't a great time of year for fast responses.
> 
> > I have tried to solve the problem however I don't find any clue yet.
> > 
> > >From my analysis, oops report shows that 'struct sock *ssk' passed to
> > netlink_broadcast_filtered() is NULL. It means that some of
> > netlink_kernel_create() returns NULL. Maybe, it is due to slab
> > allocation failure. Could you check it by inserting some log on that
> > part? The issue cannot be reproducible in my side so I need your help.
> 
> I've added some debug in acpi_bus_generate_netlink_event +
> genlmsg_multicast and the problem seems to be that genlmsg_multicast is
> getting called when init_net.genl_sock has not yet been initialised,
> leading to the NULL deference.
> 
> Full dmesg output from a cold 4.14.8 boot at:
> 
> https://the.earth.li/~noodles/acpi-problem/dmesg-4.14.8-broken
> 
> And the same kernel after a reboot ("shutdown -r now"):
> 
> https://the.earth.li/~noodles/acpi-problem/dmesg-4.14.8-working
> 
> Patch that I've applied is at
> 
> https://the.earth.li/~noodles/acpi-problem/debug-acpi.diff
> 

Thanks for testing! It's very helpful.

> The interesting difference seems to be:
> 
>  PCI: Using ACPI for IRQ routing
> +ACPI: Generating event type 208 (:9DBB5994-A997-11DA-B012-B622A1EF5492)
> +ERROR: init_net.genl_sock is NULL
> +BUG: unable to handle kernel NULL pointer dereference at 0030
> +IP: netlink_broadcast_filtered+0x20/0x3d0
> +PGD 0 P4D 0 
> +Oops:  [#1] SMP
> +Modules linked in:
> +CPU: 0 PID: 29 Comm: kworker/0:1 Not tainted 4.14.8+ #1
> +Hardware name: Dell Inc. Latitude E7240/07RPNV, BIOS A22 10/18/2017
> +Workqueue: kacpi_notify acpi_os_execute_deferred
> 
> 9DBB5994-A997-11DA-B012-B622A1EF5492 is the Dell WMI event GUID and
> there's no visible event for it on a reboot, just on a cold power on.
> Some sort of ordering issues such that genl_sock is being initialised
> later with the slab change?

I have checked that there is an ordering issue.

genl_init() which initializes init_net->genl_sock is called on
subsys_initcall().

acpi_wmi_init() which schedules acpi_wmi_notify_handler() to the
workqueue is called on subsys_initcall(), too.
(acpi_wmi_notify_handler() -> acpi_bus_generate_netlink_event() ->
netlink_broadcast())

In my system, acpi_wmi_init() is called before the genl_init().
Therefore, if the worker is scheduled before genl_init() is done, NULL
derefence would happen.

Although slab change revealed this problem, I think that problem is on
ACPI side and need to be fixed there.

Anyway, I'm not sure why it doesn't happen before. These ACPI
initialization code looks not changed for a long time. Could you test
this problem with the slub?

Thanks.


linux-next: build warning after merge of the tpmdd tree

2018-01-01 Thread Stephen Rothwell
Hi Jarkko,

After merging the tpmdd tree, today's linux-next build (x86_64
allmodconfig) produced this warning:

drivers/char/tpm/tpm_tis.c: In function 'tpm_tis_pnp_remove':
drivers/char/tpm/tpm_tis.c:274:23: warning: unused variable 'priv' 
[-Wunused-variable]
  struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
   ^
drivers/char/tpm/tpm_tis.c: In function 'tpm_tis_plat_remove':
drivers/char/tpm/tpm_tis.c:324:23: warning: unused variable 'priv' 
[-Wunused-variable]
  struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
   ^

Introduced by commit

  6d0866cbc2d3 ("tpm: Keep CLKRUN enabled throughout the duration of 
transmit_cmd()")

-- 
Cheers,
Stephen Rothwell


linux-next: manual merge of the integrity tree with the iversion tree

2018-01-01 Thread Stephen Rothwell
Hi all,

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

  security/integrity/ima/ima_main.c

between commits:

  ac0bf025d2c0 ("ima: Use i_version only when filesystem supports it")
  57fe39d33423 ("IMA: switch IMA over to new i_version API")

from the iversion tree and commit:

  0d73a55208e9 ("ima: re-introduce own integrity cache lock")
  a2a2c3c8580a ("ima: Use i_version only when filesystem supports it")

from the integrity tree.

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

-- 
Cheers,
Stephen Rothwell

diff --cc security/integrity/ima/ima_main.c
index 06a70c5a2329,6d78cb26784d..
--- a/security/integrity/ima/ima_main.c
+++ b/security/integrity/ima/ima_main.c
@@@ -126,10 -129,12 +130,12 @@@ static void ima_check_last_writer(struc
if (!(mode & FMODE_WRITE))
return;
  
-   inode_lock(inode);
+   mutex_lock(&iint->mutex);
if (atomic_read(&inode->i_writecount) == 1) {
+   update = test_and_clear_bit(IMA_UPDATE_XATTR,
+   &iint->atomic_flags);
if (!IS_I_VERSION(inode) ||
 -  (iint->version != inode->i_version) ||
 +  inode_cmp_iversion(inode, iint->version) ||
(iint->flags & IMA_NEW_FILE)) {
iint->flags &= ~(IMA_DONE_MASK | IMA_NEW_FILE);
iint->measured_pcrs = 0;


[PATCH] Bluetooth: btusb: Add support for 0cf3:e010

2018-01-01 Thread AceLan Kao
Device 0cf3:e010 is one of the QCA ROME family.

T:  Bus=01 Lev=01 Prnt=01 Port=13 Cnt=03 Dev#=  4 Spd=12  MxCh= 0
D:  Ver= 2.01 Cls=e0(wlcon) Sub=01 Prot=01 MxPS=64 #Cfgs=  1
P:  Vendor=0cf3 ProdID=e010 Rev=00.01
C:  #Ifs= 2 Cfg#= 1 Atr=e0 MxPwr=100mA
I:  If#= 0 Alt= 0 #EPs= 3 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb
I:  If#= 1 Alt= 0 #EPs= 2 Cls=e0(wlcon) Sub=01 Prot=01 Driver=btusb

Signed-off-by: AceLan Kao 
---
 drivers/bluetooth/btusb.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index f7120c9..9136edb 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -263,6 +263,7 @@ static const struct usb_device_id blacklist_table[] = {
/* QCA ROME chipset */
{ USB_DEVICE(0x0cf3, 0xe007), .driver_info = BTUSB_QCA_ROME },
{ USB_DEVICE(0x0cf3, 0xe009), .driver_info = BTUSB_QCA_ROME },
+   { USB_DEVICE(0x0cf3, 0xe010), .driver_info = BTUSB_QCA_ROME },
{ USB_DEVICE(0x0cf3, 0xe300), .driver_info = BTUSB_QCA_ROME },
{ USB_DEVICE(0x0cf3, 0xe301), .driver_info = BTUSB_QCA_ROME },
{ USB_DEVICE(0x0cf3, 0xe360), .driver_info = BTUSB_QCA_ROME },
-- 
2.7.4



Re: [patch V5 01/11] Documentation: Add license-rules.rst to describe how to properly identify file licenses

2018-01-01 Thread Andreas Dilger
On Dec 29, 2017, at 9:15 PM, Theodore Ts'o  wrote:
> 
> On Fri, Dec 29, 2017 at 11:17:54PM +0100, Philippe Ombredanne wrote:
>>> As far as I know, none of the licenses explicitly say
>>> copyright license must be on each file.  Just that the distribution of
>>> source must include the copyright and license statement.  Exactly how
>>> that is done is not explicitly specified.
>> 
>> This is also my take. What is done here is not much different than
>> refactoring duplicated code so it leaves in a single place:
>> 
>> - by "value" at the root in COPYING and in the Documentation.
>> - by "reference" in the code proper as SPDX ids.
>> 
>> Therefore essential and common requirements to include the license
>> text is fulfilled in the kernel.
>> 
>> Note that there are a few offenders that will need to clean up their
>> acts as they came up will both long and "un-removable and
>> un-alterable" crazy legalese blurbs [1] prefix this:
>> 
>> "DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER"
>> 
>> These will have to be taken care on a case by case basis. These are
>> pretty stupid and IMHO should have never been allowed to be added to
>> the kernel in the first place and are ugly warts. It could very well
>> be that these are not really GPL-compliant notices FWIW: keeping
>> notices and copyrights is quite different from a restriction of
>> altering things by moving them around which is exactly what is
>> happening with the SPDX-ification here.
>> 
>> [1] 
>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/staging/lustre/include/linux/libcfs/libcfs.h?h=v4.15-rc5#n5
> 
> Lustre is now owned by Intel so I suspect that some throat clearing
> noises in the right direction could easily take care of the issue with
> those files

To correct this, the copyright on the Lustre code is not owned by Intel.
The copyright on the original Lustre code was transferred from Oracle to
Seagate a few years ago, but the code that Whamcloud->Intel used for their
release (which is what the kernel client is based on) was forked many years
ago from the Oracle version (all under GPL).  There is no single copyright
holder anymore, since there is no copyright assignment for new contributions
and it is copyright by whomever contributed it, as with the kernel itself.

I don't see any issue with leaving those header blocks as-is?

Cheers, Andreas







Re: [PATCHv2 1/8] MIPS: Loongson64: cleanup all cs5536 files to use SPDX Identifier

2018-01-01 Thread Huacai Chen
Zhangjin Wu (wuzhang...@gmail.com) is the original author, I hope he
can give a signed-off. I can only give an ack.

Huacai

On Sun, Dec 31, 2017 at 9:54 PM, Philippe Ombredanne
 wrote:
> On Sun, Dec 31, 2017 at 2:14 PM, Jiaxun Yang  wrote:
>> On 2017-12-31 Sun 12:17 +0100,Philippe Ombredanne wrote:
>>> Did you CC the original authors? You would need their signoff or at
>>> least an ack IMHO
>>
>> Yeah, I CC Huacai Chen in v1 as the Lemote staff who in charge of
>> Loongson's mainline kernel. Can he sign-off for all the original
>> authors who were from ICT and Lemote?
>> As far as I know, some authors are no longer working in Lemote. And I
>> can't see their new email addresses so it may hard to get their ack or
>> sign-off.
>> Thanks for your adivce.
>>
>> --
>> Best Regards
>> Jiaxun Yang
>
> It would best if you can get all acks, at least one authoritative from
> each org involved or from each individual involved if not part of an
> org. I reckon it may be difficult. But then you can document with your
> patch set who you contacted, who you got ack from and who you did not.
>
> Then again you are not changing anything about the licensing: just
> replacing licensing by value (e.g. a full notice) by a license by
> reference (e.g. an SPDX tag that references the full text).
>
> --
> Cordially
> Philippe Ombredanne
>


[PATCH 2/2] phy: rockchip-emmc: use regmap_read_poll_timeout to poll dllrdy

2018-01-01 Thread Shawn Lin
Just use the API instead of open-coding it, no functional change
intended.

Signed-off-by: Shawn Lin 
---

 drivers/phy/rockchip/phy-rockchip-emmc.c | 21 +++--
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/drivers/phy/rockchip/phy-rockchip-emmc.c 
b/drivers/phy/rockchip/phy-rockchip-emmc.c
index 512a6ef..c65979b 100644
--- a/drivers/phy/rockchip/phy-rockchip-emmc.c
+++ b/drivers/phy/rockchip/phy-rockchip-emmc.c
@@ -79,6 +79,9 @@
 #define PHYCTRL_IS_CALDONE(x) \
x) >> PHYCTRL_CALDONE_SHIFT) & \
  PHYCTRL_CALDONE_MASK) == PHYCTRL_CALDONE_DONE)
+#define PHYCTRL_IS_DLLRDY(x) \
+   x) >> PHYCTRL_DLLRDY_SHIFT) & \
+ PHYCTRL_DLLRDY_MASK) == PHYCTRL_DLLRDY_DONE)
 
 struct rockchip_emmc_phy {
unsigned intreg_offset;
@@ -93,7 +96,6 @@ static int rockchip_emmc_phy_power(struct phy *phy, bool 
on_off)
unsigned int dllrdy;
unsigned int freqsel = PHYCTRL_FREQSEL_200M;
unsigned long rate;
-   unsigned long timeout;
 
/*
 * Keep phyctrl_pdb and phyctrl_endll low to allow
@@ -222,19 +224,10 @@ static int rockchip_emmc_phy_power(struct phy *phy, bool 
on_off)
 *   only at boot / resume.  In both cases, eMMC is probably on the
 *   critical path so busy waiting a little extra time should be OK.
 */
-   timeout = jiffies + msecs_to_jiffies(50);
-   do {
-   udelay(1);
-
-   regmap_read(rk_phy->reg_base,
-   rk_phy->reg_offset + GRF_EMMCPHY_STATUS,
-   &dllrdy);
-   dllrdy = (dllrdy >> PHYCTRL_DLLRDY_SHIFT) & PHYCTRL_DLLRDY_MASK;
-   if (dllrdy == PHYCTRL_DLLRDY_DONE)
-   break;
-   } while (!time_after(jiffies, timeout));
-
-   if (dllrdy != PHYCTRL_DLLRDY_DONE) {
+   if (regmap_read_poll_timeout(rk_phy->reg_base,
+rk_phy->reg_offset + GRF_EMMCPHY_STATUS,
+dllrdy, PHYCTRL_IS_DLLRDY(dllrdy),
+1, 50 * USEC_PER_MSEC)) {
pr_err("rockchip_emmc_phy_power: dllrdy timeout.\n");
return -ETIMEDOUT;
}
-- 
1.9.1




Re: [PATCH v5 7/9] arm64: Topology, rename cluster_id

2018-01-01 Thread Xiongfeng Wang
Hi,

On 2017/12/18 20:42, Morten Rasmussen wrote:
> On Fri, Dec 15, 2017 at 10:36:35AM -0600, Jeremy Linton wrote:
>> Hi,
>>
>> On 12/13/2017 12:02 PM, Lorenzo Pieralisi wrote:
>>> [+Morten, Dietmar]
>>>
>>> $SUBJECT should be:
>>>
>>> arm64: topology: rename cluster_id
>>
[cut]
>>
>> I was hoping someone else would comment here, but my take at this point is
>> that it doesn't really matter in a functional sense at the moment.
>> Like the chiplet discussion it can be the subject of a future patch along
>> with the patches which tweak the scheduler to understand the split.
>>
>> BTW, given that i'm OoO next week, and the following that are the holidays,
>> I don't intend to repost this for a couple weeks. I don't think there are
>> any issues with this set.
>>
>>>
>>> There is also arch/arm to take into account, again, this patch is
>>> just renaming (as it should have named since the beginning) a
>>> topology level but we should consider everything from a legacy
>>> perspective.
> 
> arch/arm has gone for thread/core/socket for the three topology levels
> it supports.
> 
> I'm not sure what short term value keeping cluster_id has? Isn't it just
> about where we make the package = cluster assignment? Currently it is in
> the definition of topology_physical_package_id. If we keep cluster_id
> and add package_id, it gets moved into the MPIDR/DT parsing code. 
> 
> Keeping cluster_id and introducing a topology_cluster_id function could
> help cleaning up some of the users of topology_physical_package_id that
> currently assumes package_id == cluster_id though.

I think we still need the information describing which cores are in one cluster.
Many arm64 chips have the architecture core/cluster/socket. Cores in one 
cluster may
share a same L2 cache. That information can be used to build the sched_domain. 
If we put
cores in one cluster in one sched_domain, the performance will be 
better.(please see
kernel/sched/topology.c:1197, cpu_coregroup_mask() uses 'core_sibling' to build 
a multi-core
sched_domain)
So I think we still need variable to record which cores are in one sched_domain 
for future use.

Thanks,
Xiongfeng

> 
> Morten
> 
> .
> 



[PATCH 1/2] phy: rockchip-emmc: retry calpad busy trimming

2018-01-01 Thread Shawn Lin
It turns out that 5us isn't enough for all cases, so let's
retry some more times to wait for caldone.

Signed-off-by: Shawn Lin 
---

 drivers/phy/rockchip/phy-rockchip-emmc.c | 21 +
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/phy/rockchip/phy-rockchip-emmc.c 
b/drivers/phy/rockchip/phy-rockchip-emmc.c
index f1b24f1..512a6ef 100644
--- a/drivers/phy/rockchip/phy-rockchip-emmc.c
+++ b/drivers/phy/rockchip/phy-rockchip-emmc.c
@@ -76,6 +76,10 @@
 #define PHYCTRL_OTAPDLYSEL_MASK0xf
 #define PHYCTRL_OTAPDLYSEL_SHIFT   0x7
 
+#define PHYCTRL_IS_CALDONE(x) \
+   x) >> PHYCTRL_CALDONE_SHIFT) & \
+ PHYCTRL_CALDONE_MASK) == PHYCTRL_CALDONE_DONE)
+
 struct rockchip_emmc_phy {
unsigned intreg_offset;
struct regmap   *reg_base;
@@ -160,15 +164,16 @@ static int rockchip_emmc_phy_power(struct phy *phy, bool 
on_off)
   PHYCTRL_PDB_SHIFT));
 
/*
-* According to the user manual, it asks driver to
-* wait 5us for calpad busy trimming
+* According to the user manual, it asks driver to wait 5us for
+* calpad busy trimming. However it is documented that this value is
+* PVT(A.K.A process,voltage and temperature) relevant, so some
+* failure cases are found which indicates we should be more tolerant
+* to calpad busy trimming.
 */
-   udelay(5);
-   regmap_read(rk_phy->reg_base,
-   rk_phy->reg_offset + GRF_EMMCPHY_STATUS,
-   &caldone);
-   caldone = (caldone >> PHYCTRL_CALDONE_SHIFT) & PHYCTRL_CALDONE_MASK;
-   if (caldone != PHYCTRL_CALDONE_DONE) {
+   if (regmap_read_poll_timeout(rk_phy->reg_base,
+rk_phy->reg_offset + GRF_EMMCPHY_STATUS,
+caldone, PHYCTRL_IS_CALDONE(caldone),
+5, 50)) {
pr_err("rockchip_emmc_phy_power: caldone timeout.\n");
return -ETIMEDOUT;
}
-- 
1.9.1




[PATCH] nvme: check ctrl.tagset before start ns scan

2018-01-01 Thread Jianchao Wang
ctrl.tagset maybe NULL due to failure of io queue setup or blk-mq
tagset allocation in nvme_reset_work. Then panic would come up.
To fix this, just add ctrl.tagset check in nvme_scan_work.

Signed-off-by: Jianchao Wang 
---
 drivers/nvme/host/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 1e46e60..1ed593d 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3071,7 +3071,7 @@ static void nvme_scan_work(struct work_struct *work)
struct nvme_id_ctrl *id;
unsigned nn;
 
-   if (ctrl->state != NVME_CTRL_LIVE)
+   if ((ctrl->state != NVME_CTRL_LIVE) || !ctrl->tagset)
return;
 
if (nvme_identify_ctrl(ctrl, &id))
-- 
2.7.4



Re: [PATCH] ARM: sunxi_defconfig: Enable SUNXI_CCU

2018-01-01 Thread Chen-Yu Tsai
On Tue, Jan 2, 2018 at 3:22 AM, Corentin Labbe
 wrote:
> While looking for missing symbol by diffing sunxi_defconfig and my
> .config, I just found that no CLK symbol are present in sunxi_defconfig.

This does not take into account default values in Kconfig. Use
`make savedefconfg` then compare the resulting defconfig file.

>
> This patch add the missing CONFIG_SUNXI_CCU in sunxi_defconfig.
> All other symbol will be automatically selected via their default value.
>
> Signed-off-by: Corentin Labbe 
> ---
>  arch/arm/configs/sunxi_defconfig | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/arch/arm/configs/sunxi_defconfig 
> b/arch/arm/configs/sunxi_defconfig
> index 5caaf971fb50..5ed920e75842 100644
> --- a/arch/arm/configs/sunxi_defconfig
> +++ b/arch/arm/configs/sunxi_defconfig
> @@ -16,6 +16,7 @@ CONFIG_CPU_FREQ=y
>  CONFIG_CPUFREQ_DT=y
>  CONFIG_VFP=y
>  CONFIG_NEON=y
> +CONFIG_SUNXI_CCU=y

Not needed. See the last line of:

config SUNXI_CCU
bool "Clock support for Allwinner SoCs"
depends on ARCH_SUNXI || COMPILE_TEST
select RESET_CONTROLLER
default ARCH_SUNXI

Surely kernelci hasn't been broken since the introduction of
sunxi-ng. :)

ChenYu

>  CONFIG_NET=y
>  CONFIG_PACKET=y
>  CONFIG_UNIX=y
> --
> 2.13.6
>


Re: [RFC PATCH] memory-hotplug: add sysfs immovable_mem attribute

2018-01-01 Thread Chao Fan
On Fri, Dec 29, 2017 at 01:23:05PM +0100, Michal Hocko wrote:

Hi Michal,

>Always make sure to CC linux-api mailing list when proposing user
>visible API patches.

Sorry for that, since scripts/get_maintainer.pl didn't show that,
so I don't know should Cc that.

>
>On Wed 27-12-17 20:30:12, Chao Fan wrote:
>> In sometimes users specify the memory region in immovable node in
>> some kernel commandline, such as "kernel_core" or the "immovable_mem="
>> in the patchset that I have send. But users don't know the memory
>> region. So add this interface to print it.
>> 
>> It will show like this: "nn@ss,nn@ss,...". "nn" means the size of memory
>> region, "ss" means the start position of this region.
>
>The patch doesn't explain who is going to use this information and what
>for. Moreover we already do have removable which tells whether the given
>memblock is movable.
>

Thanks for your review, and sorry for my bad explain.
Since my patchset has not neen merged, so I didn't explain the details.
https://patchwork.kernel.org/patch/10106787/
Here is a my patchset. I was trying to add a new parameter to specify
the memory region in immovable node, so that kaslr can work well with
memory hotplug. So we need something can show the immovable memory
regions.
Yes, as you said the removable is based on memblock. But as for this
issue, I want to specify the regions based on node. The memory region
in a NUMA node just contain one or two acpi_srat_mem_affinity in acpi.
But the memblock may have an intersection with two NUMA nodes.
So the data in acpi table is exactly suitable for this issue.
So I write the patch like this.

Thanks,
Chao Fan

>Finally you are pulling an ACPI specific code into a generic code which
>is not acceptable.
>
>Based on all this
>Nacked-by: Michal Hocko 
>
>> 
>> Signed-off-by: Chao Fan 
>> ---
>>  drivers/base/memory.c | 50 
>> ++
>>  1 file changed, 50 insertions(+)
>> 
>> diff --git a/drivers/base/memory.c b/drivers/base/memory.c
>> index 1d60b58a8c19..9cadf1a9dccb 100644
>> --- a/drivers/base/memory.c
>> +++ b/drivers/base/memory.c
>> @@ -25,6 +25,7 @@
>>  
>>  #include 
>>  #include 
>> +#include 
>>  
>>  static DEFINE_MUTEX(mem_sysfs_mutex);
>>  
>> @@ -389,6 +390,52 @@ static ssize_t show_phys_device(struct device *dev,
>>  }
>>  
>>  #ifdef CONFIG_MEMORY_HOTREMOVE
>> +/*
>> + * Immovable memory region
>> + */
>> +
>> +static ssize_t
>> +show_immovable_mem(struct device *dev, struct device_attribute *attr,
>> +   char *buf)
>> +{
>> +struct acpi_table_header *table_header = NULL;
>> +struct acpi_srat_mem_affinity *ma;
>> +struct acpi_subtable_header *th;
>> +unsigned long long table_size;
>> +unsigned long long table_end;
>> +char pbuf[35], *p = buf;
>> +int len;
>> +
>> +acpi_get_table(ACPI_SIG_SRAT, 0, &table_header);
>> +
>> +table_size = sizeof(struct acpi_table_srat);
>> +table_end = (unsigned long)table_header + table_header->length;
>> +th = (struct acpi_subtable_header *)((unsigned long)
>> +  table_header + table_size);
>> +
>> +while (((unsigned long)th) +
>> +   sizeof(struct acpi_subtable_header) < table_end) {
>> +if (th->type == 1) {
>> +ma = (struct acpi_srat_mem_affinity *)th;
>> +if (ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE)
>> +continue;
>> +len = sprintf(pbuf, "%llx@%llx",
>> +   ma->length, ma->base_address);
>> +if (p != buf) {
>> +*p = ',';
>> +p++;
>> +}
>> +memcpy(p, pbuf, len);
>> +p = p + len;
>> +}
>> +th = (struct acpi_subtable_header *)((unsigned long)
>> +  th + th->length);
>> +}
>> +return sprintf(buf, "%s\n", buf);
>> +}
>> +
>> +static DEVICE_ATTR(immovable_mem, 0444, show_immovable_mem, NULL);
>> +
>>  static void print_allowed_zone(char *buf, int nid, unsigned long start_pfn,
>>  unsigned long nr_pages, int online_type,
>>  struct zone *default_zone)
>> @@ -798,6 +845,9 @@ static struct attribute *memory_root_attrs[] = {
>>  #endif
>>  
>>  &dev_attr_block_size_bytes.attr,
>> +#ifdef CONFIG_MEMORY_HOTREMOVE
>> +&dev_attr_immovable_mem.attr,
>> +#endif
>>  &dev_attr_auto_online_blocks.attr,
>>  NULL
>>  };
>> -- 
>> 2.14.3
>> 
>> 
>
>-- 
>Michal Hocko
>SUSE Labs
>
>




Re: [RESEND PATCH v2 05/15] ASoC: qcom: qdsp6: Add support to Q6ADM

2018-01-01 Thread Bjorn Andersson
On Thu 14 Dec 09:33 PST 2017, srinivas.kandaga...@linaro.org wrote:

> From: Srinivas Kandagatla 
> 
> This patch adds support to q6 ADM (Audio Device Manager) module in
> q6dsp. ADM performs routing between audio streams and AFE ports.
> It does Rate matching for streams going to devices driven by

lower case "Rate"

> different clocks, it handles volume ramping, Mixing with channel

and "Mixing"

> and bit-width. ADM creates and destroys dynamic COPP services
> for device-related audio processing as needed.

What's a "copp"?

> 
> This patch adds basic support to ADM.

Wouldn't s/to/for/ be better?

[..]
> +struct copp {
> + int afe_port;
> + int copp_idx;
> + int id;
> + int cnt;

Please rename this "refcnt" to match other kernel code.

> + int topology;
> + int mode;
> + int stat;
> + int rate;
> + int bit_width;
> + int channels;
> + int app_type;
> + int acdb_id;
> + wait_queue_head_t wait;
> + struct list_head node;
> + struct q6adm *adm;
> +};
> +
> +struct q6adm {
> + struct apr_device *apr;
> + struct device *dev;
> + unsigned long copp_bitmap[AFE_MAX_PORTS];
> + struct list_head copps_list;
> + spinlock_t copps_list_lock;
> + int matrix_map_stat;
> + struct platform_device *routing_dev;
> +
> + wait_queue_head_t matrix_map_wait;
> +};
> +
> +static struct copp *adm_find_copp(struct q6adm *adm, int port_idx, int 
> copp_idx)
> +{
> + struct copp *c;
> +
> + spin_lock(&adm->copps_list_lock);
> + list_for_each_entry(c, &adm->copps_list, node) {
> + if ((port_idx == c->afe_port) && (copp_idx == c->copp_idx)) {
> + spin_unlock(&adm->copps_list_lock);
> + return c;
> + }
> + }
> +
> + spin_unlock(&adm->copps_list_lock);
> + return NULL;
> +
> +}
> +
> +static struct copp *adm_find_matching_copp(struct q6adm *adm,
> +int port_idx, int topology,
> +int mode, int rate,
> +int bit_width, int app_type)
> +{
> + struct copp *c;
> +
> + spin_lock(&adm->copps_list_lock);
> +
> + list_for_each_entry(c, &adm->copps_list, node) {
> + if ((port_idx == c->afe_port) && (topology == c->topology) &&
> + (mode == c->mode) && (rate == c->rate) &&
> + (bit_width == c->bit_width) && (app_type == c->app_type)) {
> + spin_unlock(&adm->copps_list_lock);
> + return c;
> + }
> + }
> + spin_unlock(&adm->copps_list_lock);
> +
> + return NULL;
> +
> +}
> +
> +static int adm_callback(struct apr_device *adev, struct apr_client_data 
> *data)
> +{
> + uint32_t *payload;
> + int port_idx, copp_idx;
> + struct copp *copp;
> + struct q6adm *adm = dev_get_drvdata(&adev->dev);
> +
> + payload = data->payload;
> +
> + if (data->payload_size) {

Bail if you don't have a payload and save yourself one indentation
level.

> + copp_idx = (data->token) & 0XFF;
> + port_idx = ((data->token) >> 16) & 0xFF;
> + if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) {
> + dev_err(&adev->dev, "Invalid port idx %d token %d\n",
> +port_idx, data->token);
> + return 0;
> + }
> + if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) {
> + dev_err(&adev->dev, "Invalid copp idx %d token %d\n",
> + copp_idx, data->token);
> + return 0;
> + }
> +
> + if (data->opcode == APR_BASIC_RSP_RESULT) {

This is a case in the following switch statement.

> + if (payload[1] != 0) {
> + dev_err(&adev->dev, "cmd = 0x%x returned error 
> = 0x%x\n",
> + payload[0], payload[1]);

This would again benefit from a small struct...

> + }
> + switch (payload[0]) {
> + case ADM_CMD_DEVICE_OPEN_V5:
> + case ADM_CMD_DEVICE_CLOSE_V5:
> + copp = adm_find_copp(adm, port_idx, copp_idx);
> + if (IS_ERR_OR_NULL(copp))
> + return 0;
> +
> + copp->stat = payload[1];
> + wake_up(&copp->wait);
> + break;
> + case ADM_CMD_MATRIX_MAP_ROUTINGS_V5:
> + adm->matrix_map_stat = payload[1];
> + wake_up(&adm->matrix_map_wait);
> + break;
> +
> + default:
> + dev_err(&adev->dev, "Unknown Cmd: 0x%x\n",
> + payload[0]);
> +   

linux-next: build failure after merge of the drm tree

2018-01-01 Thread Stephen Rothwell
Hi all,

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

drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_mst_types.c:219:6: 
error: redefinition of 'dm_dp_mst_dc_sink_create'
 void dm_dp_mst_dc_sink_create(struct drm_connector *connector)
  ^
drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_mst_types.c:183:6: 
note: previous definition of 'dm_dp_mst_dc_sink_create' was here
 void dm_dp_mst_dc_sink_create(struct drm_connector *connector)
  ^

Caused by commit

  391ef035200f ("drm/amd/display: Fix rehook MST display not light back on")

automatically mergeing badly with commit

  becd0875f439 ("drm/amd/display: Fix rehook MST display not light back on")

from Linus' tree.

I applied this merge fix patch (to remove the second copy of
dm_dp_mst_dc_sink_create):

From: Stephen Rothwell 
Date: Tue, 2 Jan 2018 12:43:32 +1100
Subject: [PATCH] drm/amd/display: fix mismerge of identical patches

Signed-off-by: Stephen Rothwell 
---
 .../amd/display/amdgpu_dm/amdgpu_dm_mst_types.c| 36 --
 1 file changed, 36 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
index 7ace4dd302c1..f3d87f418d2e 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
@@ -216,42 +216,6 @@ void dm_dp_mst_dc_sink_create(struct drm_connector 
*connector)
&aconnector->base, aconnector->edid);
 }
 
-void dm_dp_mst_dc_sink_create(struct drm_connector *connector)
-{
-   struct amdgpu_dm_connector *aconnector = 
to_amdgpu_dm_connector(connector);
-   struct edid *edid;
-   struct dc_sink *dc_sink;
-   struct dc_sink_init_data init_params = {
-   .link = aconnector->dc_link,
-   .sink_signal = SIGNAL_TYPE_DISPLAY_PORT_MST };
-
-   edid = drm_dp_mst_get_edid(connector, &aconnector->mst_port->mst_mgr, 
aconnector->port);
-
-   if (!edid) {
-   drm_mode_connector_update_edid_property(
-   &aconnector->base,
-   NULL);
-   return;
-   }
-
-   aconnector->edid = edid;
-
-   dc_sink = dc_link_add_remote_sink(
-   aconnector->dc_link,
-   (uint8_t *)aconnector->edid,
-   (aconnector->edid->extensions + 1) * EDID_LENGTH,
-   &init_params);
-
-   dc_sink->priv = aconnector;
-   aconnector->dc_sink = dc_sink;
-
-   amdgpu_dm_add_sink_to_freesync_module(
-   connector, aconnector->edid);
-
-   drm_mode_connector_update_edid_property(
-   &aconnector->base, aconnector->edid);
-}
-
 static int dm_dp_mst_get_modes(struct drm_connector *connector)
 {
struct amdgpu_dm_connector *aconnector = 
to_amdgpu_dm_connector(connector);
-- 
2.15.0

-- 
Cheers,
Stephen Rothwell


[PATCH -next] slimbus: qcom: Make some local functions static

2018-01-01 Thread Wei Yongjun
Fixes the following sparse warnings:

drivers/slimbus/qcom-ctrl.c:151:6: warning:
 symbol 'slim_ack_txn' was not declared. Should it be static?
drivers/slimbus/qcom-ctrl.c:304:6: warning:
 symbol 'slim_alloc_txbuf' was not declared. Should it be static?

Signed-off-by: Wei Yongjun 
---
 drivers/slimbus/qcom-ctrl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/slimbus/qcom-ctrl.c b/drivers/slimbus/qcom-ctrl.c
index 35ad70d..600f62d 100644
--- a/drivers/slimbus/qcom-ctrl.c
+++ b/drivers/slimbus/qcom-ctrl.c
@@ -148,7 +148,7 @@ static void *slim_alloc_rxbuf(struct qcom_slim_ctrl *ctrl)
return ctrl->rx.base + (idx * ctrl->rx.sl_sz);
 }
 
-void slim_ack_txn(struct qcom_slim_ctrl *ctrl, int err)
+static void slim_ack_txn(struct qcom_slim_ctrl *ctrl, int err)
 {
struct completion *comp;
unsigned long flags;
@@ -301,8 +301,8 @@ static int qcom_clk_pause_wakeup(struct slim_controller 
*sctrl)
return 0;
 }
 
-void *slim_alloc_txbuf(struct qcom_slim_ctrl *ctrl, struct slim_msg_txn *txn,
-  struct completion *done)
+static void *slim_alloc_txbuf(struct qcom_slim_ctrl *ctrl,
+ struct slim_msg_txn *txn, struct completion *done)
 {
unsigned long flags;
int idx;



Re: [PATCH 1/3] phy: phy-mtk-tphy: use auto instead of force to bypass utmi signals

2018-01-01 Thread Chunfeng Yun
On Thu, 2017-12-28 at 16:44 +0530, Kishon Vijay Abraham I wrote:
> 
> On Thursday 07 December 2017 05:23 PM, Chunfeng Yun wrote:
> > When system is running, if usb2 phy is forced to bypass utmi signals,
> > all PLL will be turned off, and it can't detect device connection
> > anymore, so replace force mode with auto mode which can bypass utmi
> > signals automatically if no device attached for normal flow.
> > But keep the force mode to fix RX sensitivity degradation issue.
> > 
> > Signed-off-by: Chunfeng Yun 
> 
> merged this series.
Thanks a lot
> 
> Thanks
> Kishon
> > ---
> >  drivers/phy/mediatek/phy-mtk-tphy.c | 19 +++
> >  1 file changed, 7 insertions(+), 12 deletions(-)
> > 
> > diff --git a/drivers/phy/mediatek/phy-mtk-tphy.c 
> > b/drivers/phy/mediatek/phy-mtk-tphy.c
> > index fb8aba4..5d9d7f3 100644
> > --- a/drivers/phy/mediatek/phy-mtk-tphy.c
> > +++ b/drivers/phy/mediatek/phy-mtk-tphy.c
> > @@ -440,9 +440,9 @@ static void u2_phy_instance_init(struct mtk_tphy *tphy,
> > u32 index = instance->index;
> > u32 tmp;
> >  
> > -   /* switch to USB function. (system register, force ip into usb mode) */
> > +   /* switch to USB function, and enable usb pll */
> > tmp = readl(com + U3P_U2PHYDTM0);
> > -   tmp &= ~P2C_FORCE_UART_EN;
> > +   tmp &= ~(P2C_FORCE_UART_EN | P2C_FORCE_SUSPENDM);
> > tmp |= P2C_RG_XCVRSEL_VAL(1) | P2C_RG_DATAIN_VAL(0);
> > writel(tmp, com + U3P_U2PHYDTM0);
> >  
> > @@ -502,10 +502,8 @@ static void u2_phy_instance_power_on(struct mtk_tphy 
> > *tphy,
> > u32 index = instance->index;
> > u32 tmp;
> >  
> > -   /* (force_suspendm=0) (let suspendm=1, enable usb 480MHz pll) */
> > tmp = readl(com + U3P_U2PHYDTM0);
> > -   tmp &= ~(P2C_FORCE_SUSPENDM | P2C_RG_XCVRSEL);
> > -   tmp &= ~(P2C_RG_DATAIN | P2C_DTM0_PART_MASK);
> > +   tmp &= ~(P2C_RG_XCVRSEL | P2C_RG_DATAIN | P2C_DTM0_PART_MASK);
> > writel(tmp, com + U3P_U2PHYDTM0);
> >  
> > /* OTG Enable */
> > @@ -540,7 +538,6 @@ static void u2_phy_instance_power_off(struct mtk_tphy 
> > *tphy,
> >  
> > tmp = readl(com + U3P_U2PHYDTM0);
> > tmp &= ~(P2C_RG_XCVRSEL | P2C_RG_DATAIN);
> > -   tmp |= P2C_FORCE_SUSPENDM;
> > writel(tmp, com + U3P_U2PHYDTM0);
> >  
> > /* OTG Disable */
> > @@ -548,18 +545,16 @@ static void u2_phy_instance_power_off(struct mtk_tphy 
> > *tphy,
> > tmp &= ~PA6_RG_U2_OTG_VBUSCMP_EN;
> > writel(tmp, com + U3P_USBPHYACR6);
> >  
> > -   /* let suspendm=0, set utmi into analog power down */
> > -   tmp = readl(com + U3P_U2PHYDTM0);
> > -   tmp &= ~P2C_RG_SUSPENDM;
> > -   writel(tmp, com + U3P_U2PHYDTM0);
> > -   udelay(1);
> > -
> > tmp = readl(com + U3P_U2PHYDTM1);
> > tmp &= ~(P2C_RG_VBUSVALID | P2C_RG_AVALID);
> > tmp |= P2C_RG_SESSEND;
> > writel(tmp, com + U3P_U2PHYDTM1);
> >  
> > if (tphy->pdata->avoid_rx_sen_degradation && index) {
> > +   tmp = readl(com + U3P_U2PHYDTM0);
> > +   tmp &= ~(P2C_RG_SUSPENDM | P2C_FORCE_SUSPENDM);
> > +   writel(tmp, com + U3P_U2PHYDTM0);
> > +
> > tmp = readl(com + U3D_U2PHYDCR0);
> > tmp &= ~P2C_RG_SIF_U2PLL_FORCE_ON;
> > writel(tmp, com + U3D_U2PHYDCR0);
> > 




[PATCH -next] slimbus: Use GFP_ATOMIC under spin lock

2018-01-01 Thread Wei Yongjun
A spin lock is taken here so we should use GFP_ATOMIC.

Fixes: afbdcc7c384b ("slimbus: Add messaging APIs to slimbus framework")
Signed-off-by: Wei Yongjun 
---
 drivers/slimbus/messaging.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/slimbus/messaging.c b/drivers/slimbus/messaging.c
index 755462a..ef54ea1 100644
--- a/drivers/slimbus/messaging.c
+++ b/drivers/slimbus/messaging.c
@@ -98,7 +98,7 @@ int slim_do_transfer(struct slim_controller *ctrl, struct 
slim_msg_txn *txn)
if (need_tid) {
spin_lock_irqsave(&ctrl->txn_lock, flags);
tid = idr_alloc(&ctrl->tid_idr, txn, 0,
-   SLIM_MAX_TIDS, GFP_KERNEL);
+   SLIM_MAX_TIDS, GFP_ATOMIC);
txn->tid = tid;
 
if (!txn->msg->comp)



[PATCH -next] slimbus: qcom: Fix return value check in qcom_slim_probe()

2018-01-01 Thread Wei Yongjun
In case of error, the function devm_ioremap_resource() returns ERR_PTR()
and never returns NULL. The NULL test in the return value check should
be replaced with IS_ERR().

Fixes: ad7fcbc308b0 ("slimbus: qcom: Add Qualcomm Slimbus controller driver")
Signed-off-by: Wei Yongjun 
---
 drivers/slimbus/qcom-ctrl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/slimbus/qcom-ctrl.c b/drivers/slimbus/qcom-ctrl.c
index 35ad70d..96fefd6 100644
--- a/drivers/slimbus/qcom-ctrl.c
+++ b/drivers/slimbus/qcom-ctrl.c
@@ -530,9 +530,9 @@ static int qcom_slim_probe(struct platform_device *pdev)
 
slim_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "ctrl");
ctrl->base = devm_ioremap_resource(ctrl->dev, slim_mem);
-   if (!ctrl->base) {
+   if (IS_ERR(ctrl->base)) {
dev_err(&pdev->dev, "IOremap failed\n");
-   return -ENOMEM;
+   return PTR_ERR(ctrl->base);
}
 
sctrl->set_laddr = qcom_set_laddr;



Re: [RFC] does ioremap() cause memory leak?

2018-01-01 Thread Hanjun Guo
On 2017/12/23 13:32, Xishi Qiu wrote:
> On 2017/12/21 16:55, Xishi Qiu wrote:
> 
>> When we use iounmap() to free the mapping, it calls unmap_vmap_area() to 
>> clear page table,
>> but do not free the memory of page table, right?
>>
>> So when use ioremap() to mapping another area(incluce the area before), it 
>> may use
>> large mapping(e.g. ioremap_pmd_enabled()), so the original page table 
>> memory(e.g. pte memory)
>> will be lost, it cause memory leak, right?
> 
>  
> 
> So I have two questions for this scene.
> 
> 1. When the same virtual address allocated from ioremap, first is 4K size, 
> second is 2M size, if Kernel would leak memory.
> 
> 2. Kernel modifies the old invalid 4K pagetable to 2M, but doesn`t follow the 
> ARM break-before-make flow, CPU maybe get the old invalid 4K pagetable 
> information, then Kernel would panic.

I sent a RFC patch for this one [1].

[1]: https://patchwork.kernel.org/patch/10134581/

Thanks
Hanjun



[PATCH -next] slimbus: Fix missing unlock on error in slim_msg_response()

2018-01-01 Thread Wei Yongjun
Add the missing unlock before return from function slim_msg_response()
in the error handling case.

Fixes: afbdcc7c384b ("slimbus: Add messaging APIs to slimbus framework")
Signed-off-by: Wei Yongjun 
---
 drivers/slimbus/messaging.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/slimbus/messaging.c b/drivers/slimbus/messaging.c
index 755462a..a1328ac 100644
--- a/drivers/slimbus/messaging.c
+++ b/drivers/slimbus/messaging.c
@@ -38,6 +38,7 @@ void slim_msg_response(struct slim_controller *ctrl, u8 
*reply, u8 tid, u8 len)
if (msg == NULL || msg->rbuf == NULL) {
dev_err(ctrl->dev, "Got response to invalid TID:%d, len:%d\n",
tid, len);
+   spin_unlock_irqrestore(&ctrl->txn_lock, flags);
return;
}



Re: [PATCH v5] x86/microcode/intel: Blacklist the specific BDW-EP for late loading

2018-01-01 Thread Jia Zhang
Thanks for your comments. Happy new year!

Jia

在 2018/1/2 上午6:10, Borislav Petkov 写道:
> On Mon, Jan 01, 2018 at 10:04:47AM +0800, Jia Zhang wrote:
>> Instead of blacklisting all types of Broadwell processor when running
>> a late loading, only BDW-EP (signature 0x406f1, aka family 6, model 79,
>> stepping 1) with the microcode version less than 0x0b21 needs to
>> be blacklisted.
>>
>> The erratum is documented in the the public documentation #334165 (See
>> the item BDF90 for details).
>>
>> Signed-off-by: Jia Zhang 
>> ---
>>  arch/x86/kernel/cpu/microcode/intel.c | 14 +++---
>>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> Ok, I went and massaged your version, here's what I committed:
> 
> ---
> From: Jia Zhang 
> Date: Mon, 1 Jan 2018 10:04:47 +0800
> Subject: [PATCH] x86/microcode/intel: Extend BDW late-loading with a revision
>  check
> 
> Instead of blacklisting all model 79 CPUs when attempting a late
> microcode loading, limit that only to CPUs with microcode revisions <
> 0x0b21 because only on those late loading may cause a system hang.
> 
> For such processors either:
> 
> a) a BIOS update which might contain a newer microcode revision
> 
> or
> 
> b) the early microcode loading method
> 
> should be considered.
> 
> Processors with revisions 0x0b21 or higher will not experience such
> hangs.
> 
> For more details, see erratum BDF90 in document #334165 (Intel Xeon
> Processor E7-8800/4800 v4 Product Family Specification Update) from
> September 2017.
> 
> Signed-off-by: Jia Zhang 
> Acked-by: Tony Luck 
> Cc: x86-ml 
> Link: 
> http://lkml.kernel.org/r/1514772287-92959-1-git-send-email-qianyue...@alibaba-inc.com
> [ Heavily massage commit message and pr_* statements. ]
> Signed-off-by: Borislav Petkov 
> ---
>  arch/x86/kernel/cpu/microcode/intel.c | 13 +++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kernel/cpu/microcode/intel.c 
> b/arch/x86/kernel/cpu/microcode/intel.c
> index 8ccdca6d3f9e..d9e460fc7a3b 100644
> --- a/arch/x86/kernel/cpu/microcode/intel.c
> +++ b/arch/x86/kernel/cpu/microcode/intel.c
> @@ -910,8 +910,17 @@ static bool is_blacklisted(unsigned int cpu)
>  {
>   struct cpuinfo_x86 *c = &cpu_data(cpu);
>  
> - if (c->x86 == 6 && c->x86_model == INTEL_FAM6_BROADWELL_X) {
> - pr_err_once("late loading on model 79 is disabled.\n");
> + /*
> +  * Late loading on model 79 with microcode revision less than 0x0b21
> +  * may result in a system hang. This behavior is documented in item
> +  * BDF90, #334165 (Intel Xeon Processor E7-8800/4800 v4 Product Family).
> +  */
> + if (c->x86 == 6 &&
> + c->x86_model == INTEL_FAM6_BROADWELL_X &&
> + c->x86_mask == 0x01 &&
> + c->microcode < 0x0b21) {
> + pr_err_once("Erratum BDF90: late loading with revision < 
> 0x0b21 (0x%x) disabled.\n", c->microcode);
> + pr_err_once("Please consider either early loading through 
> initrd/built-in or a potential BIOS update.\n");
>   return true;
>   }
>  
> 


linux-next: build warning after merge of the netfilter-next tree

2018-01-01 Thread Stephen Rothwell
Hi all,

After merging the netfilter-next tree, today's linux-next build (arm
multi_v7_defconfig) produced this warning:

In file included from net/ipv6/af_inet6.c:45:0:
include/linux/netfilter_ipv6.h:38:51: warning: 'struct nf_queue_entry' declared 
inside parameter list
  int (*reroute)(struct sk_buff *skb, const struct nf_queue_entry *entry);
   ^
include/linux/netfilter_ipv6.h:38:51: warning: its scope is only this 
definition or declaration, which is probably not what you want
In file included from net/ipv4/route.c:87:0:
include/linux/netfilter_ipv4.h:29:53: warning: 'struct nf_queue_entry' declared 
inside parameter list
 int nf_ip_reroute(struct sk_buff *skb, const struct nf_queue_entry *entry);
 ^
include/linux/netfilter_ipv4.h:29:53: warning: its scope is only this 
definition or declaration, which is probably not what you want
In file included from net/ipv6/ip6_input.c:34:0:
include/linux/netfilter_ipv6.h:38:51: warning: 'struct nf_queue_entry' declared 
inside parameter list
  int (*reroute)(struct sk_buff *skb, const struct nf_queue_entry *entry);
   ^
include/linux/netfilter_ipv6.h:38:51: warning: its scope is only this 
definition or declaration, which is probably not what you want
In file included from net/ipv4/ip_input.c:145:0:
include/linux/netfilter_ipv4.h:29:53: warning: 'struct nf_queue_entry' declared 
inside parameter list
 int nf_ip_reroute(struct sk_buff *skb, const struct nf_queue_entry *entry);
 ^
include/linux/netfilter_ipv4.h:29:53: warning: its scope is only this 
definition or declaration, which is probably not what you want
In file included from net/ipv4/ip_fragment.c:50:0:
include/linux/netfilter_ipv4.h:29:53: warning: 'struct nf_queue_entry' declared 
inside parameter list
 int nf_ip_reroute(struct sk_buff *skb, const struct nf_queue_entry *entry);
 ^
include/linux/netfilter_ipv4.h:29:53: warning: its scope is only this 
definition or declaration, which is probably not what you want
In file included from net/ipv6/ip6_output.c:44:0:
include/linux/netfilter_ipv6.h:38:51: warning: 'struct nf_queue_entry' declared 
inside parameter list
  int (*reroute)(struct sk_buff *skb, const struct nf_queue_entry *entry);
   ^
include/linux/netfilter_ipv6.h:38:51: warning: its scope is only this 
definition or declaration, which is probably not what you want
In file included from net/ipv4/ip_forward.c:37:0:
include/linux/netfilter_ipv4.h:29:53: warning: 'struct nf_queue_entry' declared 
inside parameter list
 int nf_ip_reroute(struct sk_buff *skb, const struct nf_queue_entry *entry);
 ^
include/linux/netfilter_ipv4.h:29:53: warning: its scope is only this 
definition or declaration, which is probably not what you want
In file included from net/ipv6/ndisc.c:74:0:
include/linux/netfilter_ipv6.h:38:51: warning: 'struct nf_queue_entry' declared 
inside parameter list
  int (*reroute)(struct sk_buff *skb, const struct nf_queue_entry *entry);
   ^
include/linux/netfilter_ipv6.h:38:51: warning: its scope is only this 
definition or declaration, which is probably not what you want
In file included from net/ipv4/ip_output.c:79:0:
include/linux/netfilter_ipv4.h:29:53: warning: 'struct nf_queue_entry' declared 
inside parameter list
 int nf_ip_reroute(struct sk_buff *skb, const struct nf_queue_entry *entry);
 ^
include/linux/netfilter_ipv4.h:29:53: warning: its scope is only this 
definition or declaration, which is probably not what you want
In file included from net/ipv6/raw.c:32:0:
include/linux/netfilter_ipv6.h:38:51: warning: 'struct nf_queue_entry' declared 
inside parameter list
  int (*reroute)(struct sk_buff *skb, const struct nf_queue_entry *entry);
   ^
include/linux/netfilter_ipv6.h:38:51: warning: its scope is only this 
definition or declaration, which is probably not what you want
In file included from net/ipv6/xfrm6_state.c:18:0:
include/linux/netfilter_ipv6.h:38:51: warning: 'struct nf_queue_entry' declared 
inside parameter list
  int (*reroute)(struct sk_buff *skb, const struct nf_queue_entry *entry);
   ^
include/linux/netfilter_ipv6.h:38:51: warning: its scope is only this 
definition or declaration, which is probably not what you want
In file included from net/ipv6/mcast.c:51:0:
include/linux/netfilter_ipv6.h:38:51: warning: 'struct nf_queue_entry' declared 
inside parameter list
  int (*reroute)(struct sk_buff *skb, const struct nf_queue_entry *entry);
   ^
include/linux/netfilter_ipv6.h:38:51

Re: [PATCH 0/4] KVM: nVMX: prepare_vmcs02 optimizations

2018-01-01 Thread Wanpeng Li
2018-01-02 7:01 GMT+08:00 Paolo Bonzini :
> On 01/01/2018 10:36, Paolo Bonzini wrote:
>> On 28/12/2017 09:39, Wanpeng Li wrote:
>>> 2017-12-27 22:28 GMT+08:00 Paolo Bonzini :
 On 25/12/2017 11:08, Wanpeng Li wrote:
>> I observe L1(latest kvm/queue) panic and L0(latest kvm/queue)
>> calltrace, I'm not sure whether it is caused by this patchset.
> It can be reproduced steadily by running kvm-unit-tests in L1.

 It works here, can you show the L0 call trace and/or bisect it?
>>>
>>> L0 call trace has already been posted here.
>>> https://lkml.org/lkml/2017/12/25/53 In addition, the splatting is
>>> still there after I revert the last 9 nVMX optimization patches in
>>> kvm/queue. So it is not caused by this patchset. :)
>>
>> Hmm, maybe you're using "-cpu host,+umip"?  I'll check when I get back
>> to work tomorrow.
>
> Yeah, I think this could be it:
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 30e6115d4f09..6404e96179b4 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -10780,6 +10780,7 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, 
> struct vmcs12 *vmcs12,
> exec_control &= ~(SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES |
>   SECONDARY_EXEC_ENABLE_INVPCID |
>   SECONDARY_EXEC_RDTSCP |
> + SECONDARY_EXEC_DESC |
>   SECONDARY_EXEC_XSAVES |
>   SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY |
>   SECONDARY_EXEC_APIC_REGISTER_VIRT |

The issue is still there after applying this to both L0 and L1,
actually, I can observe a vmentry fail just before the splatting in L0
w/ and w/o the above code. In addition, I comment out the other
testcases in unittests.cfg except vmx_controls, then run
./run_tests.sh.

 [334079.689931] nested_vmx_exit_reflected failed vm entry 7
 [334079.689980] WARNING: CPU: 6 PID: 6911 at
/home/kernel/data/kvm/arch/x86/kvm//vmx.c:6376 handle_desc+0x2d/0x40
[kvm_intel]
 [334079.689982] Modules linked in: kvm_intel(OE) kvm(OE) binfmt_misc
nls_iso8859_1 snd_hda_codec_hdmi snd_hda_codec_realtek
snd_hda_codec_generic snd_hda_intel snd_hda_codec snd_hda_core
snd_hwdep x86_pkg_temp_thermal snd_pcm intel_powerclamp coretemp
crc32_pclmul snd_seq_midi pcbc snd_seq_midi_event snd_rawmidi
aesni_intel snd_seq aes_x86_64 crypto_simd cryptd glue_helper joydev
input_leds wmi_bmof snd_seq_device snd_timer mei_me snd mei shpchp
lpc_ich soundcore mac_hid irqbypass parport_pc ppdev lp parport
autofs4 hid_generic usbhid hid i915 i2c_algo_bit drm_kms_helper
syscopyarea sysfillrect sysimgblt fb_sys_fops drm e1000e ahci ptp
libahci pps_core wmi video [last unloaded: kvm]
 [334079.690080] CPU: 6 PID: 6911 Comm: qemu-system-x86 Tainted: G
  OE4.15.0-rc3+ #1
 [334079.690082] Hardware name: LENOVO ThinkCentre
M8500t-N000/SHARKBAY, BIOS FBKTC1AUS 02/16/2016
 [334079.690086] RIP: 0010:handle_desc+0x2d/0x40 [kvm_intel]
 [334079.690088] RSP: 0018:af010029bca0 EFLAGS: 00010246
 [334079.690091] RAX: c0785160 RBX: 002e RCX:
0001
 [334079.690093] RDX:  RSI:  RDI:
a0512c74
 [334079.690094] RBP: af010029bca0 R08: c61dd84f R09:
1e890e04
 [334079.690096] R10:  R11: 0001 R12:
a051aa6c
 [334079.690098] R13:  R14: 0001 R15:
a0512c74
 [334079.690100] FS:  7f1cf5450700() GS:a051ce00()
knlGS:
 [334079.690102] CS:  0010 DS:  ES:  CR0: 80050033
 [334079.690104] CR2:  CR3: 0003eb98d006 CR4:
001626e0
 [334079.690106] Call Trace:
 [334079.690111]  vmx_handle_exit+0xbd/0xe20 [kvm_intel]
 [334079.690131]  ? kvm_arch_vcpu_ioctl_run+0xcea/0x1c20 [kvm]
 [334079.690144]  kvm_arch_vcpu_ioctl_run+0xd66/0x1c20 [kvm]
 [334079.690159]  kvm_vcpu_ioctl+0x3e9/0x720 [kvm]
 [334079.690167]  ? kvm_vcpu_ioctl+0x3e9/0x720 [kvm]
 [334079.690173]  ? __fget+0xfc/0x210
 [334079.690176]  ? __fget+0xfc/0x210
 [334079.690181]  do_vfs_ioctl+0xa4/0x6a0
 [334079.690184]  ? __fget+0x11d/0x210
 [334079.690190]  SyS_ioctl+0x79/0x90
 [334079.690195]  entry_SYSCALL_64_fastpath+0x1f/0x96
 [334079.690197] RIP: 0033:0x7f1d01faef07
 [334079.690199] RSP: 002b:7f1cf544f8b8 EFLAGS: 0246 ORIG_RAX:
0010
 [334079.690203] RAX: ffda RBX: ae80 RCX:
7f1d01faef07
 [334079.690204] RDX:  RSI: ae80 RDI:
0011
 [334079.690206] RBP: 561713c40f70 R08:  R09:
0001
 [334079.690208] R10: 0058 R11: 0246 R12:

 [334079.690209] R13: 7f1d0468d000 R14:  R15:
561713c40f70
 [334079.690218] Code: 44 00 00 f6 87 f1 03 00 00 08 55 48 89 e5 74 1b
45 31 c0 31 c9 31 f6 ba 10 00 00 00 e8 2d 4e dc ff 85 c0 0f 94 c0 0f
b6 c0 5d c3 <

[PATCH] PM / runtime: Rework pm_runtime_force_suspend/resume()

2018-01-01 Thread Rafael J. Wysocki
From: Rafael J. Wysocki 

One of the limitations of pm_runtime_force_suspend/resume() is that
if a parent driver wants to use these functions, all of its child
drivers have to do that too because of the parent usage counter
manipulations necessary to get the correct state of the parent during
system-wide transitions to the working state (system resume).
However, that limitation turns out to be artificial, so remove it.

First, notice that it is not really necessary to change the device's
runtime PM status in pm_runtime_force_suspend().  Moreover, if
pm_runtime_set_suspended() is not called for a device, the children
counter of its parent (if there is a parent) will not drop, so it
is not necessary to increment the parent's usage counter in that
case, as long as the children counters of devices are checked
along with their usage counters in order to decide whether or not
the devices may be left in suspend on the way out (that is, during
the subsequent system-wide transition to the working state).

Accordingly, modify pm_runtime_force_suspend() to only call
pm_runtime_set_suspended() for devices whose usage and children
counters are at the "no references" level and drop the parent usage
counter incrementation from it.

Second, notice that with the above change in pm_runtime_force_suspend(),
if the runtime PM status of the device in pm_runtime_force_resume() is
"suspended", then either the device had remained in runtime suspend
before pm_runtime_force_suspend() was called for it (in which case it
is safe to leave it in suspend), or its runtime PM status has been
changed by pm_runtime_force_suspend() itself.  Of course, the latter
case is only possible if the usage and children counters of the device
are at the "no reference" levels, so the device may be left in suspend
then.

In turn, if the runtime PM status of the device in
pm_runtime_force_resume() is "active", pm_runtime_force_suspend()
called for it previously found active references to it, so it needs
to be resumed.

Hence, with the above change in pm_runtime_force_suspend(),
pm_runtime_force_resume() only needs to check the device's runtime PM
status to decide whether or not to resume it and it doesn't need to
manipulate the device parent's usage counter any more, so modify it
accordingly.

Signed-off-by: Rafael J. Wysocki 
---
 drivers/base/power/runtime.c |   61 +--
 1 file changed, 19 insertions(+), 42 deletions(-)

Index: linux-pm/drivers/base/power/runtime.c
===
--- linux-pm.orig/drivers/base/power/runtime.c
+++ linux-pm/drivers/base/power/runtime.c
@@ -1618,12 +1618,15 @@ void pm_runtime_drop_link(struct device
  * @dev: Device to suspend.
  *
  * Disable runtime PM so we safely can check the device's runtime PM status and
- * if it is active, invoke it's .runtime_suspend callback to bring it into
- * suspend state. Keep runtime PM disabled to preserve the state unless we
- * encounter errors.
+ * if it is active, invoke it's ->runtime_suspend callback to suspend it.  
Also,
+ * if the device's usage and children counters don't indicate that the device
+ * was in use before the system-wide transition under way, change its runtime 
PM
+ * status to suspended after suspending it.  Keep runtime PM disabled to
+ * preserve the state unless we encounter errors.
  *
  * Typically this function may be invoked from a system suspend callback to 
make
- * sure the device is put into low power state.
+ * sure the device is put into low power state.  It assumes that the analogous
+ * pm_runtime_force_resume() will be used to resume the device.
  */
 int pm_runtime_force_suspend(struct device *dev)
 {
@@ -1645,18 +1648,12 @@ int pm_runtime_force_suspend(struct devi
if (ret)
goto err;
 
-   /*
-* Increase the runtime PM usage count for the device's parent, in case
-* when we find the device being used when system suspend was invoked.
-* This informs pm_runtime_force_resume() to resume the parent
-* immediately, which is needed to be able to resume its children,
-* when not deferring the resume to be managed via runtime PM.
-*/
-   if (dev->parent && atomic_read(&dev->power.usage_count) > 1)
-   pm_runtime_get_noresume(dev->parent);
+   if (atomic_read(&dev->power.usage_count) <= 1 &&
+   atomic_read(&dev->power.child_count) == 0)
+   pm_runtime_set_suspended(dev);
 
-   pm_runtime_set_suspended(dev);
return 0;
+
 err:
pm_runtime_enable(dev);
return ret;
@@ -1669,13 +1666,9 @@ EXPORT_SYMBOL_GPL(pm_runtime_force_suspe
  *
  * Prior invoking this function we expect the user to have brought the device
  * into low power state by a call to pm_runtime_force_suspend(). Here we 
reverse
- * those actions and brings the device into full power, if it is expected to be
- * used on system resume. To distinguish that, we check wh

Re: [PATCH 3/4] extcon: axp288: Redo charger type dection a couple of seconds after probe()

2018-01-01 Thread Chanwoo Choi
Hi Hans,

s/dection/detection on patch title.

On 2017년 12월 22일 21:36, Hans de Goede wrote:
> The axp288 extcon code depends on other drivers to do things like mux the
> data lines, enable/disable vbus based on the id-pin, etc.
> 
> Sometimes the BIOS has not set these things up correctly resulting in the
> initial charger cable type detection giving a wrong result and we end up
> not charging or charging at only 0.5A.
> 
> This commit starts a second charger-detection cycle a couple of seconds
> after the first one finishes, giving the other drivers time to load and
> do their thing.
> 
> Signed-off-by: Hans de Goede 
> ---
>  drivers/extcon/extcon-axp288.c | 32 ++--
>  1 file changed, 30 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c
> index 386afb7d1160..cc7c35c7ff02 100644
> --- a/drivers/extcon/extcon-axp288.c
> +++ b/drivers/extcon/extcon-axp288.c
> @@ -1,6 +1,7 @@
>  /*
>   * extcon-axp288.c - X-Power AXP288 PMIC extcon cable detection driver
>   *
> + * Copyright (C) 2016-2017 Hans de Goede 
>   * Copyright (C) 2015 Intel Corporation
>   * Author: Ramakrishna Pallala 
>   *
> @@ -97,9 +98,11 @@ struct axp288_extcon_info {
>   struct device *dev;
>   struct regmap *regmap;
>   struct regmap_irq_chip_data *regmap_irqc;
> + struct delayed_work det_work;
>   int irq[EXTCON_IRQ_END];
>   struct extcon_dev *edev;
>   unsigned int previous_cable;
> + bool first_detect_done;

The first_detect_done is used only one time in the 
axp288_handle_chrg_det_event().
The other function don't use it. So, you better to define and use
'static bool first_detect_done' in the axp288_handle_chrg_det_event()
instead of defining the 'first_detect_done' in the struct axp288_extcon_info.

>  };
>  
>  /* Power up/down reason string array */
> @@ -137,6 +140,25 @@ static void axp288_extcon_log_rsi(struct 
> axp288_extcon_info *info)
>   regmap_write(info->regmap, AXP288_PS_BOOT_REASON_REG, clear_mask);
>  }
>  
> +static void axp288_chrg_detect_complete(struct axp288_extcon_info *info)
> +{
> + /*
> +  * We depend on other drivers to do things like mux the data lines,
> +  * enable/disable vbus based on the id-pin, etc. Sometimes the BIOS has
> +  * not set these things up correctly resulting in the initial charger
> +  * cable type detection giving a wrong result and we end up not charging
> +  * or charging at only 0.5A.
> +  *
> +  * So we schedule a second cable type detection after 2 seconds to
> +  * give the other drivers time to load and do their thing.
> +  */
> + if (!info->first_detect_done) {
> + queue_delayed_work(system_wq, &info->det_work,
> +msecs_to_jiffies(2000));
> + info->first_detect_done = true;
> + }
> +}

The axp288_chrg_detect_complete() is only used in the 
axp288_handle_chrg_det_event()
and axp288_chrg_detect_complete() is not a complicate. I think that you don't 
need
to make the separate function. I'd like you to add the 

> +
>  static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
>  {
>   int ret, stat, cfg, pwr_stat;
> @@ -201,6 +223,8 @@ static int axp288_handle_chrg_det_event(struct 
> axp288_extcon_info *info)
>   info->previous_cable = cable;
>   }
>  
> + axp288_chrg_detect_complete(info);

As I commented, you better to add the code directly instead of separate 
function.

> +
>   return 0;
>  
>  dev_det_ret:
> @@ -222,8 +246,11 @@ static irqreturn_t axp288_extcon_isr(int irq, void *data)
>   return IRQ_HANDLED;
>  }
>  
> -static void axp288_extcon_enable(struct axp288_extcon_info *info)
> +static void axp288_extcon_det_work(struct work_struct *work)
>  {
> + struct axp288_extcon_info *info =
> + container_of(work, struct axp288_extcon_info, det_work.work);
> +
>   regmap_update_bits(info->regmap, AXP288_BC_GLOBAL_REG,
>   BC_GLOBAL_RUN, 0);
>   /* Enable the charger detection logic */
> @@ -245,6 +272,7 @@ static int axp288_extcon_probe(struct platform_device 
> *pdev)
>   info->regmap = axp20x->regmap;
>   info->regmap_irqc = axp20x->regmap_irqc;
>   info->previous_cable = EXTCON_NONE;
> + INIT_DELAYED_WORK(&info->det_work, axp288_extcon_det_work);
>  
>   platform_set_drvdata(pdev, info);
>  
> @@ -287,7 +315,7 @@ static int axp288_extcon_probe(struct platform_device 
> *pdev)
>   }
>  
>   /* Start charger cable type detection */
> - axp288_extcon_enable(info);
> + queue_delayed_work(system_wq, &info->det_work, 0);
>  
>   return 0;
>  }
> 


-- 
Best Regards,
Chanwoo Choi
Samsung Electronics


Re: [PATCH 4/4] extcon: axp288: Handle reserved charger-type values better

2018-01-01 Thread Chanwoo Choi
Hi Hans,

On 2017년 12월 22일 21:36, Hans de Goede wrote:
> According to the data sheets all the values not handled in the
> switch-case are "reserved". Update the dev_warn message to reflect
> this and set the cable-type to EXTCON_CHG_USB_SDP (so max 500mA
> current draw) as safe default.
> 
> Signed-off-by: Hans de Goede 
> ---
>  drivers/extcon/extcon-axp288.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c
> index cc7c35c7ff02..d60c615f709f 100644
> --- a/drivers/extcon/extcon-axp288.c
> +++ b/drivers/extcon/extcon-axp288.c
> @@ -205,8 +205,8 @@ static int axp288_handle_chrg_det_event(struct 
> axp288_extcon_info *info)
>   cable = EXTCON_CHG_USB_DCP;
>   break;
>   default:
> - dev_warn(info->dev,
> - "disconnect or unknown or ID event\n");
> + dev_warn(info->dev, "unknown (reserved) bc detect result\n");
> + cable = EXTCON_CHG_USB_SDP;
>   }
>  
>  no_vbus:
> 

Looks good to me.
Reviewed-by: Chanwoo Choi 

-- 
Best Regards,
Chanwoo Choi
Samsung Electronics


Re: [RESEND PATCH v2 04/15] ASoC: qcom: qdsp6: Add support to Q6AFE

2018-01-01 Thread Bjorn Andersson
On Thu 14 Dec 09:33 PST 2017, srinivas.kandaga...@linaro.org wrote:

[..]
> +
> +config SND_SOC_QDSP6_AFE
> + tristate
> + default n

Do you see a particular benefit of having one kernel module per
function? Why not just compile them all into the same q6dsp.ko?

> +
> +config SND_SOC_QDSP6
> + tristate "SoC ALSA audio driver for QDSP6"
> + select SND_SOC_QDSP6_AFE
> + help
> +  To add support for MSM QDSP6 Soc Audio.
> +  This will enable sound soc platform specific
> +  audio drivers. This includes q6asm, q6adm,
> +  q6afe interfaces to DSP using apr.
[..]
> +struct q6afev2 {
> + void *apr;

apr has a type, even if it's definition is hidden you should use the
proper type here.

> + struct device *dev;
> + int state;
> + int status;
> + struct platform_device *daidev;
> +
> + struct mutex afe_cmd_lock;

You shouldn't need to include afe_ in this name.

> + struct list_head port_list;
> + spinlock_t port_list_lock;
> + struct list_head node;
> +};
> +
[..]
> +/* Port map of index vs real hw port ids */
> +static struct afe_port_map port_maps[AFE_PORT_MAX] = {
> + [AFE_PORT_HDMI_RX] = { AFE_PORT_ID_MULTICHAN_HDMI_RX,

Looks like you have an extra tab here, consider breaking the 80 char
"rule" to not have to wrap these.

> +AFE_PORT_HDMI_RX, 1},
> +};
> +
> +static struct q6afe_port *afe_find_port(struct q6afev2 *afe, int token)
> +{
> + struct q6afe_port *p = NULL;
> +
> + spin_lock(&afe->port_list_lock);
> + list_for_each_entry(p, &afe->port_list, node)
> + if (p->token == token)
> + break;
> +
> + spin_unlock(&afe->port_list_lock);
> + return p;
> +}

Make port_list an idr and you can just use idr_find() instead of rolling
your own search function.

> +
> +static int afe_callback(struct apr_device *adev, struct apr_client_data 
> *data)
> +{
> + struct q6afev2 *afe = dev_get_drvdata(&adev->dev);//priv;

This is perfectly fine, no need to extend the interface with a priv (so
drop the comment).

> + struct q6afe_port *port;
> +
> + if (!data) {
> + dev_err(afe->dev, "%s: Invalid param data\n", __func__);
> + return -EINVAL;
> + }

Just define on in the apr layer that data will never be NULL, that will
save you 4 lines of code in every apr client.

> +
> + if (data->payload_size) {
> + uint32_t *payload = data->payload;

So the payload is 2 ints, where the first is a command and the second is
the status of it. This you can express in a simple struct to make the
code even easier on the eye.

> +
> + if (data->opcode == APR_BASIC_RSP_RESULT) {
> + if (payload[1] != 0) {
> + afe->status = payload[1];
> + dev_err(afe->dev,
> + "cmd = 0x%x returned error = 0x%x\n",
> + payload[0], payload[1]);
> + }
> + switch (payload[0]) {
> + case AFE_PORT_CMD_SET_PARAM_V2:
> + case AFE_PORT_CMD_DEVICE_STOP:
> + case AFE_PORT_CMD_DEVICE_START:
> + afe->state = AFE_CMD_RESP_AVAIL;
> + port = afe_find_port(afe, data->token);
> + if (port)
> + wake_up(&port->wait);
> +
> + break;
> + default:
> + dev_err(afe->dev, "Unknown cmd 0x%x\n",
> + payload[0]);

If you flip the check for payload_size to return early if there isn't a
payload then you can reduce the indentation level one step and probably
doesn't have to wrap this line.

> + break;
> + }
> + }
> + }
> + return 0;
> +}
> +/**
> + * q6afe_get_port_id() - Get port id from a given port index
> + *
> + * @index: port index
> + *
> + * Return: Will be an negative on error or valid port_id on success
> + */
> +int q6afe_get_port_id(int index)
> +{
> + if (index < 0 || index > AFE_PORT_MAX)
> + return -EINVAL;
> +
> + return port_maps[index].port_id;
> +}
> +EXPORT_SYMBOL_GPL(q6afe_get_port_id);
> +
> +static int afe_apr_send_pkt(struct q6afev2 *afe, void *data,
> + wait_queue_head_t *wait)

Rather than conditionally passing the wait, split this function in
afe_send_sync(*afe, *data, wait) and afe_send_async(*afe, *data).

> +{
> + int ret;
> +
> + if (wait)
> + afe->state = AFE_CMD_RESP_NONE;
> +
> + afe->status = 0;
> + ret = apr_send_pkt(afe->apr, data);
> + if (ret > 0) {

Check ret < 0 and return here, this saves you one indentation level in
the following chunk.

If you then check !wait and return early you can reduce another leve

Re: [PATCH] KVM: nVMX: remove unnecessary vmwrite from L2->L1 vmexit

2018-01-01 Thread Jim Mattson
Reviewed-by: Jim Mattson 

On Mon, Jan 1, 2018 at 2:58 PM, Paolo Bonzini  wrote:
> The POSTED_INTR_NV field is constant (though it differs between the vmcs01 and
> vmcs02), there is no need to reload it on vmexit to L1.
>
> Signed-off-by: Paolo Bonzini 
> ---
>  arch/x86/kvm/vmx.c | 3 ---
>  1 file changed, 3 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index e6223fe8faa1..1e184830a295 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -11610,9 +11610,6 @@ static void load_vmcs12_host_state(struct kvm_vcpu 
> *vcpu,
>  */
> vmx_flush_tlb(vcpu, true);
> }
> -   /* Restore posted intr vector. */
> -   if (nested_cpu_has_posted_intr(vmcs12))
> -   vmcs_write16(POSTED_INTR_NV, POSTED_INTR_VECTOR);
>
> vmcs_write32(GUEST_SYSENTER_CS, vmcs12->host_ia32_sysenter_cs);
> vmcs_writel(GUEST_SYSENTER_ESP, vmcs12->host_ia32_sysenter_esp);
> --
> 1.8.3.1
>


[PATCH] PM / wakeup: Drop redundant check from device_init_wakeup()

2018-01-01 Thread Rafael J. Wysocki
From: Rafael J. Wysocki 

Since device_wakeup_disable() checks the device's power.can_wakeup 
flag, device_init_wakeup() doesn't need to do that before calling it,
so drop that redundant check from device_init_wakeup().

No intentional changes in functionality.

Signed-off-by: Rafael J. Wysocki 
---
 drivers/base/power/wakeup.c |4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Index: linux-pm/drivers/base/power/wakeup.c
===
--- linux-pm.orig/drivers/base/power/wakeup.c
+++ linux-pm/drivers/base/power/wakeup.c
@@ -448,9 +448,7 @@ int device_init_wakeup(struct device *de
device_set_wakeup_capable(dev, true);
ret = device_wakeup_enable(dev);
} else {
-   if (dev->power.can_wakeup)
-   device_wakeup_disable(dev);
-
+   device_wakeup_disable(dev);
device_set_wakeup_capable(dev, false);
}
 



  1   2   3   4   5   6   7   >