[PATCH v2 2/8] staging: rtl8188eu: remove unnecessary parentheses

2018-09-18 Thread Michael Straube
Remove unnecessary parentheses as reported by checkpatch
and from conditionals.

Signed-off-by: Michael Straube 
---
 .../staging/rtl8188eu/core/rtw_ioctl_set.c| 50 +--
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c 
b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
index 0880f18520a0..9b67f33cb568 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
@@ -17,11 +17,11 @@ u8 rtw_do_join(struct adapter *padapter)
 {
struct list_head *plist, *phead;
u8 *pibss = NULL;
-   struct  mlme_priv   *pmlmepriv = &(padapter->mlmepriv);
-   struct __queue *queue   = &(pmlmepriv->scanned_queue);
+   struct  mlme_priv   *pmlmepriv = >mlmepriv;
+   struct __queue *queue   = >scanned_queue;
u8 ret = _SUCCESS;
 
-   spin_lock_bh(&(pmlmepriv->scanned_queue.lock));
+   spin_lock_bh(>scanned_queue.lock);
phead = get_list_head(queue);
plist = phead->next;
 
@@ -36,7 +36,7 @@ u8 rtw_do_join(struct adapter *padapter)
pmlmepriv->to_join = true;
 
if (list_empty(>queue)) {
-   spin_unlock_bh(&(pmlmepriv->scanned_queue.lock));
+   spin_unlock_bh(>scanned_queue.lock);
_clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
 
/* when set_ssid/set_bssid for rtw_do_join(), but scanning 
queue is empty */
@@ -60,7 +60,7 @@ u8 rtw_do_join(struct adapter *padapter)
} else {
int select_ret;
 
-   spin_unlock_bh(&(pmlmepriv->scanned_queue.lock));
+   spin_unlock_bh(>scanned_queue.lock);
select_ret = rtw_select_and_join_from_scanned_queue(pmlmepriv);
if (select_ret == _SUCCESS) {
pmlmepriv->to_join = false;
@@ -71,7 +71,7 @@ u8 rtw_do_join(struct adapter *padapter)
/*  submit createbss_cmd to change to a 
ADHOC_MASTER */
 
/* pmlmepriv->lock has been acquired by 
caller... */
-   struct wlan_bssid_ex*pdev_network = 
&(padapter->registrypriv.dev_network);
+   struct wlan_bssid_ex*pdev_network = 
>registrypriv.dev_network;
 
pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE;
 
@@ -172,7 +172,7 @@ u8 rtw_set_802_11_bssid(struct adapter *padapter, u8 *bssid)
if (padapter->securitypriv.btkip_countermeasure) {
cur_time = jiffies;
 
-   if ((cur_time - 
padapter->securitypriv.btkip_countermeasure_time) > 60 * HZ) {
+   if (cur_time - padapter->securitypriv.btkip_countermeasure_time 
> 60 * HZ) {
padapter->securitypriv.btkip_countermeasure = false;
padapter->securitypriv.btkip_countermeasure_time = 0;
} else {
@@ -229,8 +229,8 @@ u8 rtw_set_802_11_ssid(struct adapter *padapter, struct 
ndis_802_11_ssid *ssid)
RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
 ("set_ssid: _FW_LINKED||WIFI_ADHOC_MASTER_STATE\n"));
 
-   if ((pmlmepriv->assoc_ssid.SsidLength == ssid->SsidLength) &&
-   (!memcmp(>assoc_ssid.Ssid, ssid->Ssid, 
ssid->SsidLength))) {
+   if (pmlmepriv->assoc_ssid.SsidLength == ssid->SsidLength &&
+   !memcmp(>assoc_ssid.Ssid, ssid->Ssid, 
ssid->SsidLength)) {
if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == 
false)) {
RT_TRACE(_module_rtl871x_ioctl_set_c_, 
_drv_err_,
 ("Set SSID is the same ssid, fw_state 
= 0x%08x\n",
@@ -279,7 +279,7 @@ u8 rtw_set_802_11_ssid(struct adapter *padapter, struct 
ndis_802_11_ssid *ssid)
if (padapter->securitypriv.btkip_countermeasure) {
cur_time = jiffies;
 
-   if ((cur_time - 
padapter->securitypriv.btkip_countermeasure_time) > 60 * HZ) {
+   if (cur_time - padapter->securitypriv.btkip_countermeasure_time 
> 60 * HZ) {
padapter->securitypriv.btkip_countermeasure = false;
padapter->securitypriv.btkip_countermeasure_time = 0;
} else {
@@ -310,7 +310,7 @@ u8 rtw_set_802_11_infrastructure_mode(struct adapter 
*padapter,
 {
struct  mlme_priv   *pmlmepriv = >mlmepriv;
struct  wlan_network*cur_network = >cur_network;
-   enum ndis_802_11_network_infra *pold_state = 
&(cur_network->network.InfrastructureMode);
+   enum ndis_802_11_network_infra *pold_state = 
_network->network.InfrastructureMode;
 
RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_notice_,
 ("+rtw_set_802_11_infrastructure_mode: old =%d new =%d 
fw_state = 0x%08x\n",
@@ -331,15 +331,15 @@ u8 rtw_set_802_11_infrastructure_mode(struct adapter 
*padapter,
 #endif

[PATCH v2 4/8] staging: rtl8188eu: fix comparsions to true

2018-09-18 Thread Michael Straube
Use if(x) instead of if(x == true).

Signed-off-by: Michael Straube 
---
 .../staging/rtl8188eu/core/rtw_ioctl_set.c| 26 +--
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c 
b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
index a00272540846..bd82de044bba 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
@@ -67,7 +67,7 @@ u8 rtw_do_join(struct adapter *padapter)
mod_timer(>assoc_timer,
  jiffies + msecs_to_jiffies(MAX_JOIN_TIMEOUT));
} else {
-   if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) 
{
+   if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) {
/*  submit createbss_cmd to change to a 
ADHOC_MASTER */
 
/* pmlmepriv->lock has been acquired by 
caller... */
@@ -136,7 +136,7 @@ u8 rtw_set_802_11_bssid(struct adapter *padapter, u8 *bssid)
spin_lock_bh(>lock);
 
DBG_88E("Set BSSID under fw_state = 0x%08x\n", get_fwstate(pmlmepriv));
-   if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == true)
+   if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
goto handle_tkip_countermeasure;
else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
goto release_mlme_lock;
@@ -154,12 +154,12 @@ u8 rtw_set_802_11_bssid(struct adapter *padapter, u8 
*bssid)
 
rtw_disassoc_cmd(padapter, 0, true);
 
-   if (check_fwstate(pmlmepriv, _FW_LINKED) == true)
+   if (check_fwstate(pmlmepriv, _FW_LINKED))
rtw_indicate_disconnect(padapter);
 
rtw_free_assoc_resources(padapter);
 
-   if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) 
== true)) {
+   if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
_clr_fwstate_(pmlmepriv, 
WIFI_ADHOC_MASTER_STATE);
set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
}
@@ -220,9 +220,9 @@ u8 rtw_set_802_11_ssid(struct adapter *padapter, struct 
ndis_802_11_ssid *ssid)
spin_lock_bh(>lock);
 
DBG_88E("Set SSID under fw_state = 0x%08x\n", get_fwstate(pmlmepriv));
-   if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == true)
+   if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
goto handle_tkip_countermeasure;
-   else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == true)
+   else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
goto release_mlme_lock;
 
if (check_fwstate(pmlmepriv, _FW_LINKED|WIFI_ADHOC_MASTER_STATE)) {
@@ -240,12 +240,12 @@ u8 rtw_set_802_11_ssid(struct adapter *padapter, struct 
ndis_802_11_ssid *ssid)
/* if in WIFI_ADHOC_MASTER_STATE | 
WIFI_ADHOC_STATE, create bss or rejoin again */
rtw_disassoc_cmd(padapter, 0, true);
 
-   if (check_fwstate(pmlmepriv, 
_FW_LINKED) == true)
+   if (check_fwstate(pmlmepriv, 
_FW_LINKED))

rtw_indicate_disconnect(padapter);
 
rtw_free_assoc_resources(padapter);
 
-   if (check_fwstate(pmlmepriv, 
WIFI_ADHOC_MASTER_STATE) == true) {
+   if (check_fwstate(pmlmepriv, 
WIFI_ADHOC_MASTER_STATE)) {
_clr_fwstate_(pmlmepriv, 
WIFI_ADHOC_MASTER_STATE);
set_fwstate(pmlmepriv, 
WIFI_ADHOC_STATE);
}
@@ -262,12 +262,12 @@ u8 rtw_set_802_11_ssid(struct adapter *padapter, struct 
ndis_802_11_ssid *ssid)
 
rtw_disassoc_cmd(padapter, 0, true);
 
-   if (check_fwstate(pmlmepriv, _FW_LINKED) == true)
+   if (check_fwstate(pmlmepriv, _FW_LINKED))
rtw_indicate_disconnect(padapter);
 
rtw_free_assoc_resources(padapter);
 
-   if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) 
== true) {
+   if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
_clr_fwstate_(pmlmepriv, 
WIFI_ADHOC_MASTER_STATE);
set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
}
@@ -291,7 +291,7 @@ u8 rtw_set_802_11_ssid(struct adapter *padapter, struct 
ndis_802_11_ssid *ssid)
memcpy(>assoc_ssid, ssid, sizeof(struct ndis_802_11_ssid));
pmlmepriv->assoc_by_bssid = false;
 
-   if (check_fwstate(pmlmepriv, 

[PATCH v2 5/8] staging: rtl8188eu: fix comparsions to false

2018-09-18 Thread Michael Straube
Use if(!x) instead of if(x == false).

Signed-off-by: Michael Straube 
---
 drivers/staging/rtl8188eu/core/rtw_ioctl_set.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c 
b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
index bd82de044bba..db983f15ddd6 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
@@ -145,7 +145,7 @@ u8 rtw_set_802_11_bssid(struct adapter *padapter, u8 *bssid)
RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_, ("set_bssid: 
_FW_LINKED||WIFI_ADHOC_MASTER_STATE\n"));
 
if (!memcmp(>cur_network.network.MacAddress, bssid, 
ETH_ALEN)) {
-   if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == 
false)
+   if (!check_fwstate(pmlmepriv, WIFI_STATION_STATE))
goto release_mlme_lock;/* it means driver is in 
WIFI_ADHOC_MASTER_STATE, we needn't create bss again. */
} else {
RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_, 
("Set BSSID not the same bssid\n"));
@@ -231,7 +231,7 @@ u8 rtw_set_802_11_ssid(struct adapter *padapter, struct 
ndis_802_11_ssid *ssid)
 
if (pmlmepriv->assoc_ssid.SsidLength == ssid->SsidLength &&
!memcmp(>assoc_ssid.Ssid, ssid->Ssid, 
ssid->SsidLength)) {
-   if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == 
false)) {
+   if (!check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
RT_TRACE(_module_rtl871x_ioctl_set_c_, 
_drv_err_,
 ("Set SSID is the same ssid, fw_state 
= 0x%08x\n",
  get_fwstate(pmlmepriv)));
-- 
2.19.0



[PATCH v2 3/8] staging: rtl8188eu: remove whitespace

2018-09-18 Thread Michael Straube
Replace tabs with spaces or just remove spaces in declarations.

Signed-off-by: Michael Straube 
---
 .../staging/rtl8188eu/core/rtw_ioctl_set.c| 34 +--
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c 
b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
index 9b67f33cb568..a00272540846 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
@@ -17,8 +17,8 @@ u8 rtw_do_join(struct adapter *padapter)
 {
struct list_head *plist, *phead;
u8 *pibss = NULL;
-   struct  mlme_priv   *pmlmepriv = >mlmepriv;
-   struct __queue *queue   = >scanned_queue;
+   struct mlme_priv *pmlmepriv = >mlmepriv;
+   struct __queue *queue = >scanned_queue;
u8 ret = _SUCCESS;
 
spin_lock_bh(>scanned_queue.lock);
@@ -308,8 +308,8 @@ u8 rtw_set_802_11_ssid(struct adapter *padapter, struct 
ndis_802_11_ssid *ssid)
 u8 rtw_set_802_11_infrastructure_mode(struct adapter *padapter,
enum ndis_802_11_network_infra networktype)
 {
-   struct  mlme_priv   *pmlmepriv = >mlmepriv;
-   struct  wlan_network*cur_network = >cur_network;
+   struct mlme_priv *pmlmepriv = >mlmepriv;
+   struct wlan_network *cur_network = >cur_network;
enum ndis_802_11_network_infra *pold_state = 
_network->network.InfrastructureMode;
 
RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_notice_,
@@ -394,8 +394,8 @@ u8 rtw_set_802_11_disassociate(struct adapter *padapter)
 
 u8 rtw_set_802_11_bssid_list_scan(struct adapter *padapter, struct 
ndis_802_11_ssid *pssid, int ssid_max_num)
 {
-   struct  mlme_priv   *pmlmepriv = >mlmepriv;
-   u8  res = true;
+   struct mlme_priv *pmlmepriv = >mlmepriv;
+   u8 res = true;
 
RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_, ("+%s(), fw_state 
=%x\n", __func__, get_fwstate(pmlmepriv)));
 
@@ -467,9 +467,9 @@ u8 rtw_set_802_11_authentication_mode(struct adapter 
*padapter, enum ndis_802_11
 
 u8 rtw_set_802_11_add_wep(struct adapter *padapter, struct ndis_802_11_wep 
*wep)
 {
-   int keyid, res;
+   int keyid, res;
struct security_priv *psecuritypriv = >securitypriv;
-   u8  ret = _SUCCESS;
+   u8 ret = _SUCCESS;
 
keyid = wep->KeyIndex & 0x3fff;
 
@@ -535,16 +535,16 @@ u8 rtw_set_802_11_add_wep(struct adapter *padapter, 
struct ndis_802_11_wep *wep)
 */
 u16 rtw_get_cur_max_rate(struct adapter *adapter)
 {
-   int i = 0;
-   u8  *p;
-   u16 rate = 0, max_rate = 0;
-   struct mlme_ext_priv*pmlmeext = >mlmeextpriv;
-   struct mlme_ext_info*pmlmeinfo = >mlmext_info;
+   int i = 0;
+   u8 *p;
+   u16 rate = 0, max_rate = 0;
+   struct mlme_ext_priv *pmlmeext = >mlmeextpriv;
+   struct mlme_ext_info *pmlmeinfo = >mlmext_info;
struct registry_priv *pregistrypriv = >registrypriv;
-   struct mlme_priv*pmlmepriv = >mlmepriv;
-   struct wlan_bssid_ex  *pcur_bss = >cur_network.network;
-   u8  bw_40MHz = 0, short_GI_20 = 0, short_GI_40 = 0;
-   u32 ht_ielen = 0;
+   struct mlme_priv *pmlmepriv = >mlmepriv;
+   struct wlan_bssid_ex *pcur_bss = >cur_network.network;
+   u8 bw_40MHz = 0, short_GI_20 = 0, short_GI_40 = 0;
+   u32 ht_ielen = 0;
 
if (!check_fwstate(pmlmepriv, _FW_LINKED) &&
!check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE))
-- 
2.19.0



Re: [patch V3 02/11] x86/mm/cpa: Split, rename and clean up try_preserve_large_page()

2018-09-18 Thread Peter Zijlstra
On Mon, Sep 17, 2018 at 04:29:08PM +0200, Thomas Gleixner wrote:
> @@ -1288,23 +1287,23 @@ static int __change_page_attr(struct cpa
>   err = split_large_page(cpa, kpte, address);
>   if (!err) {
>   /*
> +  * Do a global flush tlb after splitting the large page
> +  * and before we do the actual change page attribute in the PTE.
> +  *
> +  * With out this, we violate the TLB application note, that says
> +  * "The TLBs may contain both ordinary and large-page
>*  translations for a 4-KByte range of linear addresses. This
>*  may occur if software modifies the paging structures so that
>*  the page size used for the address range changes. If the two
>*  translations differ with respect to page frame or attributes
>*  (e.g., permissions), processor behavior is undefined and may
>*  be implementation-specific."
> +  *
> +  * We do this global tlb flush inside the cpa_lock, so that we
>* don't allow any other cpu, with stale tlb entries change the
>* page attribute in parallel, that also falls into the
>* just split large page entry.
> +  */
>   flush_tlb_all();
>   goto repeat;
>   }

this made me look at the tlb invalidation of that thing again; do we
want something like the below?

---

--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -285,16 +285,6 @@ static void cpa_flush_all(unsigned long
on_each_cpu(__cpa_flush_all, (void *) cache, 1);
 }
 
-static void __cpa_flush_range(void *arg)
-{
-   /*
-* We could optimize that further and do individual per page
-* tlb invalidates for a low number of pages. Caveat: we must
-* flush the high aliases on 64bit as well.
-*/
-   __flush_tlb_all();
-}
-
 static void cpa_flush_range(unsigned long start, int numpages, int cache)
 {
unsigned int i, level;
@@ -303,7 +293,7 @@ static void cpa_flush_range(unsigned lon
BUG_ON(irqs_disabled() && !early_boot_irqs_disabled);
WARN_ON(PAGE_ALIGN(start) != start);
 
-   on_each_cpu(__cpa_flush_range, NULL, 1);
+   flush_tlb_all();
 
if (!cache)
return;
@@ -1006,14 +996,24 @@ __split_large_page(struct cpa_data *cpa,
__set_pmd_pte(kpte, address, mk_pte(base, __pgprot(_KERNPG_TABLE)));
 
/*
-* Intel Atom errata AAH41 workaround.
+* Do a global flush tlb after splitting the large page
+* and before we do the actual change page attribute in the PTE.
 *
-* The real fix should be in hw or in a microcode update, but
-* we also probabilistically try to reduce the window of having
-* a large TLB mixed with 4K TLBs while instruction fetches are
-* going on.
+* Without this, we violate the TLB application note, that says
+* "The TLBs may contain both ordinary and large-page
+*  translations for a 4-KByte range of linear addresses. This
+*  may occur if software modifies the paging structures so that
+*  the page size used for the address range changes. If the two
+*  translations differ with respect to page frame or attributes
+*  (e.g., permissions), processor behavior is undefined and may
+*  be implementation-specific."
+*
+* We do this global tlb flush inside the cpa_lock, so that we
+* don't allow any other cpu, with stale tlb entries change the
+* page attribute in parallel, that also falls into the
+* just split large page entry.
 */
-   __flush_tlb_all();
+   flush_tlb_all();
spin_unlock(_lock);
 
return 0;
@@ -1538,28 +1538,8 @@ static int __change_page_attr(struct cpa
 * We have to split the large page:
 */
err = split_large_page(cpa, kpte, address);
-   if (!err) {
-   /*
-* Do a global flush tlb after splitting the large page
-* and before we do the actual change page attribute in the PTE.
-*
-* With out this, we violate the TLB application note, that says
-* "The TLBs may contain both ordinary and large-page
-*  translations for a 4-KByte range of linear addresses. This
-*  may occur if software modifies the paging structures so that
-*  the page size used for the address range changes. If the two
-*  translations differ with respect to page frame or attributes
-*  (e.g., permissions), processor behavior is undefined and may
-*  be implementation-specific."
-*
-* We do this global tlb flush inside the cpa_lock, so that we
-* don't allow any other cpu, with stale 

Re: [PATCH 2/9] ARM: change NR_IPIS to 8

2018-09-18 Thread Chunyan Zhang
Hi,

Any conclusion on this patch? The coverity tool is still complaining
error on the issue which this patch can fix.

Thanks,
Chunyan

On 18 February 2016 at 23:18, Arnd Bergmann  wrote:
> On Thursday 18 February 2016 14:37:09 Russell King - ARM Linux wrote:
>> On Thu, Feb 18, 2016 at 03:01:54PM +0100, Arnd Bergmann wrote:
>> > When function tracing for IPIs is enabled, we get a warning for an
>> > overflow of the ipi_types array with the IPI_CPU_BACKTRACE type
>> > as triggered by raise_nmi():
>> >
>> > arch/arm/kernel/smp.c: In function 'raise_nmi':
>> > arch/arm/kernel/smp.c:489:2: error: array subscript is above array bounds 
>> > [-Werror=array-bounds]
>> >   trace_ipi_raise(target, ipi_types[ipinr]);
>>
>> We really don't want to treat the backtrace IPI as a normal IPI at all -
>> we want it to invoke the least amount of code possible.  Hence this code
>> which avoids the issue:
>>
>> if ((unsigned)ipinr < NR_IPI) {
>> trace_ipi_entry_rcuidle(ipi_types[ipinr]);
>> __inc_irq_stat(cpu, ipi_irqs[ipinr]);
>> }
>>
>> However, what's missing is that the addition of tracing here missed
>> that CPU_BACKTRACE is not to be traced.  The call in raise_nmi()
>> should have been converted to __smp_cross_call() to avoid the
>> tracing code.
>
> I've replaced the patch locally with the version below now, and
> will throw it into the randconfig build test infrastructure to
> make sure I didn't screw up in an obvious way here.
>
> Arnd
>
> From 7528c9b0558fdf4de785e62e61f0dd2ffe874110 Mon Sep 17 00:00:00 2001
> From: Arnd Bergmann 
> Date: Sun, 31 Jan 2016 22:26:21 +0100
> Subject: [PATCH] ARM: prevent tracing IPI_CPU_BACKTRACE
>
> When function tracing for IPIs is enabled, we get a warning for an
> overflow of the ipi_types array with the IPI_CPU_BACKTRACE type
> as triggered by raise_nmi():
>
> arch/arm/kernel/smp.c: In function 'raise_nmi':
> arch/arm/kernel/smp.c:489:2: error: array subscript is above array bounds 
> [-Werror=array-bounds]
>   trace_ipi_raise(target, ipi_types[ipinr]);
>
> This is a correct warning as we actually overflow the array here.
>
> This patch raise_nmi() to call __smp_cross_call() instead of
> smp_cross_call(), to avoid calling into ftrace. For clarification,
> I'm also adding a two new code comments describing how this one
> is special.
>
> The warning appears to have shown up after patch e7273ff49acf
> ("ARM: 8488/1: Make IPI_CPU_BACKTRACE a "non-secure" SGI"), which
> changed the number assignment from '15' to '8', but as far as I can
> tell has existed since the IPI tracepoints were first introduced.
> If we decide to backport this patch to stable kernels, we probably
> need to backport e7273ff49acf as well.
>
> Signed-off-by: Arnd Bergmann 
> Fixes: e7273ff49acf ("ARM: 8488/1: Make IPI_CPU_BACKTRACE a "non-secure" SGI")
> Fixes: 365ec7b17327 ("ARM: add IPI tracepoints") # v3.17
> Signed-off-by: Arnd Bergmann 
>
> diff --git a/arch/arm/include/asm/hardirq.h b/arch/arm/include/asm/hardirq.h
> index 3d7351c844aa..2fd0a2619b0b 100644
> --- a/arch/arm/include/asm/hardirq.h
> +++ b/arch/arm/include/asm/hardirq.h
> @@ -5,6 +5,7 @@
>  #include 
>  #include 
>
> +/* number of IPIS _not_ including IPI_CPU_BACKTRACE */
>  #define NR_IPI 7
>
>  typedef struct {
> diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
> index b4048e370730..9802a94260db 100644
> --- a/arch/arm/kernel/smp.c
> +++ b/arch/arm/kernel/smp.c
> @@ -72,6 +72,10 @@ enum ipi_msg_type {
> IPI_CPU_STOP,
> IPI_IRQ_WORK,
> IPI_COMPLETION,
> +   /*
> +* CPU_BACKTRACE is special and not included in NR_IPI
> +* or tracable with trace_ipi_*
> +*/
> IPI_CPU_BACKTRACE,
> /*
>  * SGI8-15 can be reserved by secure firmware, and thus may
> @@ -757,7 +761,7 @@ static void raise_nmi(cpumask_t *mask)
> if (cpumask_test_cpu(smp_processor_id(), mask) && irqs_disabled())
> nmi_cpu_backtrace(NULL);
>
> -   smp_cross_call(mask, IPI_CPU_BACKTRACE);
> +   __smp_cross_call(mask, IPI_CPU_BACKTRACE);
>  }
>
>  void arch_trigger_all_cpu_backtrace(bool include_self)
>
>
> ___
> linux-arm-kernel mailing list
> linux-arm-ker...@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel


[PATCH] PCI/AER: Clear uncorrectable error status for device

2018-09-18 Thread Oza Pawandeep
PCI based device drivers handles ERR_NONFATAL  by registering
pci_error_handlers. some of the drivers clear AER uncorrectable status
in slot_reset while some in resume.

Drivers should not have responsibility of clearing the AER status, instead
shall be done by error and recovery framework defined in err.c

Clear the status while resuming, after reset_link was successful.

Signed-off-by: Oza Pawandeep 

diff --git a/drivers/crypto/qat/qat_common/adf_aer.c 
b/drivers/crypto/qat/qat_common/adf_aer.c
index da8a2d3..61ded36 100644
--- a/drivers/crypto/qat/qat_common/adf_aer.c
+++ b/drivers/crypto/qat/qat_common/adf_aer.c
@@ -198,7 +198,6 @@ static pci_ers_result_t adf_slot_reset(struct pci_dev *pdev)
pr_err("QAT: Can't find acceleration device\n");
return PCI_ERS_RESULT_DISCONNECT;
}
-   pci_cleanup_aer_uncorrect_error_status(pdev);
if (adf_dev_aer_schedule_reset(accel_dev, ADF_DEV_RESET_SYNC))
return PCI_ERS_RESULT_DISCONNECT;
 
diff --git a/drivers/dma/ioat/init.c b/drivers/dma/ioat/init.c
index 4fa4c06..80c475f 100644
--- a/drivers/dma/ioat/init.c
+++ b/drivers/dma/ioat/init.c
@@ -1267,12 +1267,6 @@ static pci_ers_result_t 
ioat_pcie_error_slot_reset(struct pci_dev *pdev)
pci_wake_from_d3(pdev, false);
}
 
-   err = pci_cleanup_aer_uncorrect_error_status(pdev);
-   if (err) {
-   dev_err(>dev,
-   "AER uncorrect error status clear failed: %#x\n", err);
-   }
-
return result;
 }
 
diff --git a/drivers/infiniband/hw/hfi1/pcie.c 
b/drivers/infiniband/hw/hfi1/pcie.c
index baf7c32..38bc804 100644
--- a/drivers/infiniband/hw/hfi1/pcie.c
+++ b/drivers/infiniband/hw/hfi1/pcie.c
@@ -655,7 +655,6 @@ pci_resume(struct pci_dev *pdev)
struct hfi1_devdata *dd = pci_get_drvdata(pdev);
 
dd_dev_info(dd, "HFI1 resume function called\n");
-   pci_cleanup_aer_uncorrect_error_status(pdev);
/*
 * Running jobs will fail, since it's asynchronous
 * unlike sysfs-requested reset.   Better than
diff --git a/drivers/infiniband/hw/qib/qib_pcie.c 
b/drivers/infiniband/hw/qib/qib_pcie.c
index 5ac7b31..30595b3 100644
--- a/drivers/infiniband/hw/qib/qib_pcie.c
+++ b/drivers/infiniband/hw/qib/qib_pcie.c
@@ -597,7 +597,6 @@ qib_pci_resume(struct pci_dev *pdev)
struct qib_devdata *dd = pci_get_drvdata(pdev);
 
qib_devinfo(pdev, "QIB resume function called\n");
-   pci_cleanup_aer_uncorrect_error_status(pdev);
/*
 * Running jobs will fail, since it's asynchronous
 * unlike sysfs-requested reset.   Better than
diff --git a/drivers/net/ethernet/atheros/alx/main.c 
b/drivers/net/ethernet/atheros/alx/main.c
index 567ee54..0d0b6a4 100644
--- a/drivers/net/ethernet/atheros/alx/main.c
+++ b/drivers/net/ethernet/atheros/alx/main.c
@@ -1960,8 +1960,6 @@ static pci_ers_result_t alx_pci_error_slot_reset(struct 
pci_dev *pdev)
if (!alx_reset_mac(hw))
rc = PCI_ERS_RESULT_RECOVERED;
 out:
-   pci_cleanup_aer_uncorrect_error_status(pdev);
-
rtnl_unlock();
 
return rc;
diff --git a/drivers/net/ethernet/broadcom/bnx2.c 
b/drivers/net/ethernet/broadcom/bnx2.c
index 122fdb8..bbb2471 100644
--- a/drivers/net/ethernet/broadcom/bnx2.c
+++ b/drivers/net/ethernet/broadcom/bnx2.c
@@ -8793,13 +8793,6 @@ static pci_ers_result_t bnx2_io_slot_reset(struct 
pci_dev *pdev)
if (!(bp->flags & BNX2_FLAG_AER_ENABLED))
return result;
 
-   err = pci_cleanup_aer_uncorrect_error_status(pdev);
-   if (err) {
-   dev_err(>dev,
-   "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
-err); /* non-fatal, continue */
-   }
-
return result;
 }
 
diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c 
b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 5b1ed24..cfb6c89 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -14379,14 +14379,6 @@ static pci_ers_result_t bnx2x_io_slot_reset(struct 
pci_dev *pdev)
 
rtnl_unlock();
 
-   /* If AER, perform cleanup of the PCIe registers */
-   if (bp->flags & AER_ENABLED) {
-   if (pci_cleanup_aer_uncorrect_error_status(pdev))
-   BNX2X_ERR("pci_cleanup_aer_uncorrect_error_status 
failed\n");
-   else
-   DP(NETIF_MSG_HW, 
"pci_cleanup_aer_uncorrect_error_status succeeded\n");
-   }
-
return PCI_ERS_RESULT_RECOVERED;
 }
 
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c 
b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index 176fc9f..b4d1db9 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -9076,13 +9076,6 @@ static pci_ers_result_t bnxt_io_slot_reset(struct 
pci_dev *pdev)
 
rtnl_unlock();
 
-   err = 

[PATCH] ASoC: remove redundant include

2018-09-18 Thread zhong jiang
module.h already contained moduleparam.h,  so it is safe to remove
the redundant include.

The issue is detected with the help of Coccinelle.

Signed-off-by: zhong jiang 
---
 sound/soc/codecs/rt5651.c | 1 -
 sound/soc/codecs/wm8904.c | 1 -
 sound/soc/codecs/wm8974.c | 1 -
 sound/soc/soc-dapm.c  | 1 -
 4 files changed, 4 deletions(-)

diff --git a/sound/soc/codecs/rt5651.c b/sound/soc/codecs/rt5651.c
index 5bcedbc..b7ba643 100644
--- a/sound/soc/codecs/rt5651.c
+++ b/sound/soc/codecs/rt5651.c
@@ -10,7 +10,6 @@
  */
 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/sound/soc/codecs/wm8904.c b/sound/soc/codecs/wm8904.c
index 1965635..2a3e5fb 100644
--- a/sound/soc/codecs/wm8904.c
+++ b/sound/soc/codecs/wm8904.c
@@ -13,7 +13,6 @@
 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/sound/soc/codecs/wm8974.c b/sound/soc/codecs/wm8974.c
index 43edaf8..593a119 100644
--- a/sound/soc/codecs/wm8974.c
+++ b/sound/soc/codecs/wm8974.c
@@ -11,7 +11,6 @@
  */
 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 43983c6..ee6b975 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -18,7 +18,6 @@
 //  device reopen.
 
 #include 
-#include 
 #include 
 #include 
 #include 
-- 
1.7.12.4



RE: [PATCH v2 1/5] spi: spi-mem: Add driver for NXP FlexSPI controller

2018-09-18 Thread Yogesh Narayan Gaur
Hi Frieder,

> -Original Message-
> From: Frieder Schrempf [mailto:frieder.schre...@exceet.de]
> Sent: Tuesday, September 18, 2018 1:52 PM
> To: Boris Brezillon ; Yogesh Narayan Gaur
> 
> Cc: linux-...@lists.infradead.org; marek.va...@gmail.com; linux-
> s...@vger.kernel.org; devicet...@vger.kernel.org; r...@kernel.org;
> mark.rutl...@arm.com; shawn...@kernel.org; linux-arm-
> ker...@lists.infradead.org; computersforpe...@gmail.com; linux-
> ker...@vger.kernel.org
> Subject: Re: [PATCH v2 1/5] spi: spi-mem: Add driver for NXP FlexSPI 
> controller
> 
> Hi Boris, Yogesh,
> 
> On 17.09.2018 13:37, Boris Brezillon wrote:
> > Hi Yogesh,
> >
> > On Mon, 17 Sep 2018 15:18:26 +0530
> > Yogesh Gaur  wrote:
> >
> >> +
> >> +  /*
> >> +   * R/W functions for big- or little-endian registers:
> >> +   * The FSPI controller's endianness is independent of
> >> +   * the CPU core's endianness. So far, although the CPU
> >> +   * core is little-endian the FSPI controller can use
> >> +   * big-endian or little-endian.
> >> +   */
> >> +  if (of_property_read_bool(np, "big-endian")) {
> >> +  f->write = fspi_writel_be;
> >> +  f->read = fspi_readl_be;
> >> +  } else {
> >> +  f->write = fspi_writel;
> >> +  f->read = fspi_readl;
> >> +  }
> >
> > Hm, isn't it something you can extract from the compatible string? I'd
> > rather not allow users to set that in their DT if it's not something
> > you can change.
> 
> This was copied from the QSPI driver, but I think Boris is right. This seems 
> to be a
> fixed SOC-specific setting and we shouldn't set it in the DT. This applies to 
> QSPI
> and FSPI alike.
> 

Yes, it can be modified. Instead of reading endianness property from device 
tree can be moved to the platform structure nxp_fspi_devtype_data which is 
linked with the compatible string
{ .compatible = "nxp,lx2160a-fspi", .data = (void *)_data, }

Thanks.

Would send the changes in next version.

--
Regards,
Yogesh Gaur.

> Regards,
> Frieder
> 
> >
> > Regards,
> >
> > Boris
> >


Re: [PATCH RESEND 3/6] arm64: add sysfs vulnerability show for spectre v1

2018-09-18 Thread Will Deacon
On Mon, Sep 17, 2018 at 07:22:07PM +0200, Robert Richter wrote:
> On 27.08.18 16:33:07, Mian Yousaf Kaukab wrote:
> > Hard-coded since patches are merged and there are no configuration
> > options.
> 
> Could you add a list of upstream patches to the description that are
> required to solve this? This would be a strict definition for the
> mitigation being enabled and makes it easier to check if backports are
> affected or not. A build-time check would be ideal (e.g. checking for
> certain macros).

Hmm, I don't grok what you're proposing here. Why do we need a build-time
check (and to check what?)

Confused,

Will


[PATCH 1/4] kbuild: remove VERSION and PATCHLEVEL from $(objtree)/Makefile

2018-09-18 Thread Masahiro Yamada
Neither VERSION nor PATCHLEVEL is used in any useful way.

Signed-off-by: Masahiro Yamada 
---

 Makefile   | 3 +--
 scripts/mkmakefile | 6 --
 2 files changed, 1 insertion(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index d2976b5..6e1a059 100644
--- a/Makefile
+++ b/Makefile
@@ -482,8 +482,7 @@ PHONY += outputmakefile
 outputmakefile:
 ifneq ($(KBUILD_SRC),)
$(Q)ln -fsn $(srctree) source
-   $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \
-   $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
+   $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree) $(objtree)
 endif
 
 ifeq ($(cc-name),clang)
diff --git a/scripts/mkmakefile b/scripts/mkmakefile
index e19d656..e2106444 100755
--- a/scripts/mkmakefile
+++ b/scripts/mkmakefile
@@ -7,9 +7,6 @@
 # Usage
 # $1 - Kernel src directory
 # $2 - Output directory
-# $3 - version
-# $4 - patchlevel
-
 
 test ! -r $2/Makefile -o -O $2/Makefile || exit 0
 # Only overwrite automatically generated Makefiles
@@ -25,9 +22,6 @@ fi
 cat << EOF > $2/Makefile
 # Automatically generated by $0: don't edit
 
-VERSION = $3
-PATCHLEVEL = $4
-
 lastword = \$(word \$(words \$(1)),\$(1))
 makedir := \$(dir \$(call lastword,\$(MAKEFILE_LIST)))
 
-- 
2.7.4



RE: [PATCH] misc: remove redundant include moduleparam.h

2018-09-18 Thread Winkler, Tomas
> module.h already contains moduleparam.h,  so it is safe to remove the
> redundant include.
> 
> The issue is detected with the help of Coccinelle.
> 
> eePlease enter the commit message for your changes. Lines starting
> 
> Signed-off-by: zhong jiang 
> ---
>  drivers/misc/mei/bus-fixup.c  | 1 -
>  drivers/misc/vmw_vmci/vmci_host.c | 1 -
>  2 files changed, 2 deletions(-)
> 
> diff --git a/drivers/misc/mei/bus-fixup.c b/drivers/misc/mei/bus-fixup.c index
> a6f41f9..80215c3 100644
> --- a/drivers/misc/mei/bus-fixup.c
> +++ b/drivers/misc/mei/bus-fixup.c

Ack.
Tomas

> @@ -17,7 +17,6 @@
>  #include 
>  #include 
>  #include 
> -#include 
>  #include 
>  #include 
>  #include 
> diff --git a/drivers/misc/vmw_vmci/vmci_host.c
> b/drivers/misc/vmw_vmci/vmci_host.c
> index 83e0c95..be732e5 100644
> --- a/drivers/misc/vmw_vmci/vmci_host.c
> +++ b/drivers/misc/vmw_vmci/vmci_host.c
> @@ -15,7 +15,6 @@
> 
>  #include 
>  #include 
> -#include 
>  #include 
>  #include 
>  #include 
> --
> 1.7.12.4



Re: [PATCH] tty/sysrq: Make local variable 'killer' in sysrq_handle_crash() global

2018-09-18 Thread Sai Prakash Ranjan

On 9/18/2018 12:50 PM, Greg Kroah-Hartman wrote:

On Tue, Sep 18, 2018 at 12:28:39PM +0530, Sai Prakash Ranjan wrote:

On 9/18/2018 11:41 AM, Jiri Slaby wrote:

On 09/17/2018, 11:33 PM, Matthias Kaehlcke wrote:

sysrq_handle_crash() dereferences a NULL pointer on purpose to force
an exception, the local variable 'killer' is assigned to NULL and
dereferenced later. Clang detects the NULL pointer dereference at compile
time and emits a BRK instruction (on arm64) instead of the expected NULL
pointer exception. Change 'killer' to a global variable (and rename it
to 'sysrq_killer' to avoid possible clashes) to prevent Clang from
detecting the condition. By default global variables are initialized
with zero/NULL in C, therefore an explicit initialization is not needed.

Reported-by: Sai Prakash Ranjan 
Suggested-by: Evan Green 
Signed-off-by: Matthias Kaehlcke 
---
   drivers/tty/sysrq.c | 6 +++---
   1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index 06ed20dd01ba..49fa8e758690 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -132,10 +132,10 @@ static struct sysrq_key_op sysrq_unraw_op = {
   #define sysrq_unraw_op (*(struct sysrq_key_op *)NULL)
   #endif /* CONFIG_VT */
+char *sysrq_killer;
+
   static void sysrq_handle_crash(int key)
   {
-   char *killer = NULL;
-
/* we need to release the RCU read lock here,
 * otherwise we get an annoying
 * 'BUG: sleeping function called from invalid context'
@@ -144,7 +144,7 @@ static void sysrq_handle_crash(int key)
rcu_read_unlock();
panic_on_oops = 1;  /* force panic */
wmb();
-   *killer = 1;
+   *sysrq_killer = 1;


Just because a static analyzer is wrong? Oh wait, even compiler is
wrong. At least make it a static global. Or what about OPTIMIZER_HIDE_VAR?



static global does not work, clang still inserts brk. As for
OPTIMIZE_HIDE_VAR, it seems to work.
But, I dont think it is defined for clang in which case it defaults to using
barrier(). There is already one wmb(), so will it be right?


Ick, why is this needed at all?  Why are we trying to "roll our own
panic" in this code?



Hi Greg, do you mean like why there is a killer var at all or why this 
change is required?


Below are some additional info about this issue:

CLANG generated:

  ff800842bc1c :
  ff800842bc1c:   a9bf7bfdstp x29, x30, [sp,#-16]!
  ff800842bc20:   910003fdmov x29, sp
  ff800842bc24:   97f1a34ebl  ff800809495c 
<_mcount>
  ff800842bc28:   97f38876bl  ff800810de00 
<__rcu_read_unlock>
  ff800842bc2c:   f0006888adrpx8, ff800913e000 


  ff800842bc30:   320003e9orr w9, wzr, #0x1
  ff800842bc34:   b9091109str w9, [x8,#2320]
  ff800842bc38:   d5033e9fdsb st
  ff800842bc3c:   d4200020brk #0x1  <


GCC generated:

ff8008452f60 :
ff8008452f60:   a9bf7bfdstp x29, x30, [sp,#-16]!
ff8008452f64:   910003fdmov x29, sp
ff8008452f68:   aa1e03e0mov x0, x30
ff8008452f6c:   97f1078cbl  ff8008094d9c <_mcount>
ff8008452f70:   97f2f2ccbl  ff800810faa0 
<__rcu_read_unlock>
ff8008452f74:   900067e1adrpx1, ff800914e000 

ff8008452f78:   52800020mov w0, #0x1 
   // #1

ff8008452f7c:   b9096820str w0, [x1,#2408]
ff8008452f80:   d5033e9fdsb st
ff8008452f84:   d281mov x1, #0x0 
   // #0

ff8008452f88:   3920strbw0, [x1]
ff8008452f8c:   a8c17bfdldp x29, x30, [sp],#16
ff8008452f90:   d65f03c0ret

Trigger sysrq crash:

localhost ~ # echo c > /proc/sysrq-trigger
 [   78.320401] sysrq: SysRq : Trigger a crash
 [   78.324752] Unexpected kernel BRK exception at EL1
 [   78.329691] Unhandled debug exception: ptrace BRK handler 
(0xf201) at 0x0e25c368

 [   78.338384] Internal error: : 0 [#1] PREEMPT SMP

Thanks,
Sai

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


Re: [BUG] mm: direct I/O (using GUP) can write to COW anonymous pages

2018-09-18 Thread Konstantin Khlebnikov

On 18.09.2018 03:35, Jann Horn wrote:

On Tue, Sep 18, 2018 at 2:05 AM Hugh Dickins  wrote:


Hi Jann,

On Mon, 17 Sep 2018, Jann Horn wrote:


[I'm not sure who the best people to ask about this are, I hope the
recipient list resembles something reasonable...]

I have noticed that the dup_mmap() logic on fork() doesn't handle
pages with active direct I/O properly: dup_mmap() seems to assume that
making the PTE referencing a page readonly will always prevent future
writes to the page, but if the kernel has acquired a direct reference
to the page before (e.g. via get_user_pages_fast()), writes can still
happen that way.

The worst-case effect of this - as far as I can tell - is that when a
multithreaded process forks while one thread is in the middle of
sys_read() on a file that uses direct I/O with get_user_pages_fast(),
the read data can become visible in the child while the parent's
buffer stays uninitialized if the parent writes to a relevant page
post-fork before either the I/O completes or the child writes to it.


Yes: you're understandably more worried by the one seeing the other's
data;


Actually, I was mostly just trying to find a scenario in which the
parent doesn't get the data it's asking for, and this is the simplest
I could come up with. :)


This might happens even in single-threaded process:

io_submit()
fork()

io_getevents()


For example if buffer is only 512 bytes and share page with something else.

THP opens wider race window.



I was also vaguely worried about whether some other part of the mm
subsystem might assume that COW pages are immutable, but I haven't
found anything like that so far, so that might've been unwarranted
paranoia.


we've tended in the past to be more worried about the one getting
corruption, and the other not seeing the data it asked for (and usually
in the context of RDMA, rather than filesystem direct I/O).

I've added some Cc's: I might be misremembering, but I think both
Andrea and Konstantin have offered approaches to this in the past,
and I believe Salman is taking a look at it currently.

But my own interest ended when Michael added MADV_DONTFORK: beyond
that, we've rated it a "Patient: It hurts when I do this. Doctor:
Don't do that then" - more complexity and overhead to solve, than
we have had appetite to get into.


Makes sense, I guess.

I wonder whether there's a concise way to express this in the fork.2
manpage, or something like that. Maybe I'll take a stab at writing
something. The biggest issue I see with documenting this edgecase is
that, as an application developer, if you don't know whether some file
might be coming from a FUSE filesystem that has opted out of using the
disk cache, the "don't do that" essentially becomes "don't read() into
heap buffers while fork()ing in another thread", since with FUSE,
direct I/O can happen even if you don't open files as O_DIRECT as long
as the filesystem requests direct I/O, and get_user_pages_fast() will
AFAIU be used for non-page-aligned buffers, meaning that an adjacent
heap memory access could trigger CoW page duplication. But then, FUSE
filesystems that opt out of the disk cache are probably so rare that
it's not a concern in practice...


fork() from multithreaded process is almost always broken
because child gets locks held by other threads.
For example glibc localtime_r() is unsafe after such fork().

Unless child calls execve() right away it cannot do much.
But in this case vfork() works way much better and faster.




But not a shiningly satisfactory
situation, I'll agree.

Hugh



Reproducer code:

== START hello.c ==
#define FUSE_USE_VERSION 26

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

static const char *hello_path = "/hello";

static int hello_getattr(const char *path, struct stat *stbuf)
{
 int res = 0;
 memset(stbuf, 0, sizeof(struct stat));
 if (strcmp(path, "/") == 0) {
 stbuf->st_mode = S_IFDIR | 0755;
 stbuf->st_nlink = 2;
 } else if (strcmp(path, hello_path) == 0) {
 stbuf->st_mode = S_IFREG | 0666;
 stbuf->st_nlink = 1;
 stbuf->st_size = 0x1000;
 stbuf->st_blocks = 0;
 } else
 res = -ENOENT;
 return res;
}

static int hello_readdir(const char *path, void *buf, fuse_fill_dir_t
filler, off_t offset, struct fuse_file_info *fi) {
 filler(buf, ".", NULL, 0);
 filler(buf, "..", NULL, 0);
 filler(buf, hello_path + 1, NULL, 0);
 return 0;
}

static int hello_open(const char *path, struct fuse_file_info *fi) {
 return 0;
}

static int hello_read(const char *path, char *buf, size_t size, off_t
offset, struct fuse_file_info *fi) {
 sleep(3);
 size_t len = 0x1000;
 if (offset < len) {
 if (offset + size > len)
 size = len - offset;
 memset(buf, 0, size);
 } else
  

Re: soundwire fixes for v4.19

2018-09-18 Thread Greg KH
On Wed, Sep 12, 2018 at 03:27:42PM +0530, Vinod wrote:
> Hi Greg,
> 
> Please pull to receive soundwire fixes for 4.19, these include stream
> state and lock fix on release.
> 
> The following changes since commit 5b394b2ddf0347bef56e50c69a58773c94343ff3:
> 
>   Linux 4.19-rc1 (2018-08-26 14:11:59 -0700)
> 
> are available in the Git repository at:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/vkoul/soundwire.git 
> tags/soundwire-4.19-fixes

Pulled and pushed out, thanks.

greg k-h


[PATCH 2/5] RISC-V: Use swiotlb on RV64 only

2018-09-18 Thread Zong Li
Only RV64 supports swiotlb.

Signed-off-by: Zong Li 
---
 arch/riscv/kernel/setup.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index aee6031..872a280 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -227,7 +227,10 @@ void __init setup_arch(char **cmdline_p)
setup_bootmem();
paging_init();
unflatten_device_tree();
+
+#ifdef CONFIG_64bit
swiotlb_init(1);
+#endif
 
 #ifdef CONFIG_SMP
setup_smp();
-- 
2.7.4



[PATCH 1/5] RISC-V: Build tishift only on 64-bit

2018-09-18 Thread Zong Li
Only RV64 supports 128 integer size.

Signed-off-by: Zong Li 
---
 arch/riscv/lib/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/lib/Makefile b/arch/riscv/lib/Makefile
index 445ec84..5739bd0 100644
--- a/arch/riscv/lib/Makefile
+++ b/arch/riscv/lib/Makefile
@@ -2,6 +2,7 @@ lib-y   += delay.o
 lib-y  += memcpy.o
 lib-y  += memset.o
 lib-y  += uaccess.o
-lib-y  += tishift.o
+
+lib-(CONFIG_64BIT) += tishift.o
 
 lib-$(CONFIG_32BIT) += udivdi3.o
-- 
2.7.4



[PATCH 0/5] Fix some bugs on RV32 build fail and issue.

2018-09-18 Thread Zong Li
This patches fix up the building fail, less function and other issue on RV32.

Vincent Chen (1):
  RISC-V: Avoid corrupting the upper 32-bit of phys_addr_t in ioremap

Zong Li (4):
  RISC-V: Build tishift only on 64-bit
  RISC-V: Use swiotlb on RV64 only
  lib: Add umoddi3 and udivmoddi4 of GCC library routines
  RISC-V: Select GENERIC_LIB_UMODDI3 on RV32

 arch/riscv/Kconfig|   1 +
 arch/riscv/kernel/setup.c |   3 +
 arch/riscv/lib/Makefile   |   3 +-
 arch/riscv/mm/ioremap.c   |   2 +-
 lib/Kconfig   |   3 +
 lib/Makefile  |   1 +
 lib/udivmoddi4.c  | 291 ++
 lib/umoddi3.c |  16 +++
 8 files changed, 318 insertions(+), 2 deletions(-)
 create mode 100644 lib/udivmoddi4.c
 create mode 100644 lib/umoddi3.c

-- 
2.7.4



Re: [PATCH 0/3] ARM: dspi: Provide slave mode support for Vybryd vf610

2018-09-18 Thread Lukasz Majewski
Dear All,

By a mistake I've forgotten to add (to CC/TO) some developers who worked
on this driver before (they were not generated from get_maintainers.py
script).

I'm sending the notification now.

> This patch series provides support for DSPI slave mode operation.
> It tries to maximally reuse current DMA driver (including its
> limitations).
> 
> For testing the spidev_test program has been used.
> Test script for this patch can be found here:
> https://github.com/lmajewski/tests-spi/blob/master/tests/spi/spi_tests.sh
> 
> Lukasz Majewski (3):
>   dt-bindings: spi: Provide bindings for fsl dspi working in slave
> mode ARM: dspi: Provide per DSPI instance of the MCR register (SLAVE
> mode) ARM: dspi: Provide support for DSPI slave more operation (Vybryd
> vf610)
> 
>  .../devicetree/bindings/spi/spi-fsl-dspi.txt   |  8 
>  drivers/spi/spi-fsl-dspi.c | 54
> -- 2 files changed, 49 insertions(+), 13
> deletions(-)
> 




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de


pgpxPRFjk2HyO.pgp
Description: OpenPGP digital signature


RE: [PATCH v2] fanotify reports the thread id of the event trigger

2018-09-18 Thread Nixiaoming
On Tue, Sep 18, 2018 3:07 PM Amir Goldstein 
>On Tue, Sep 18, 2018 at 6:01 AM Nixiaoming  wrote:
>>
>> On Mon, Sep 17, 2018 11:51 PM Amir Goldstein  wrote:
>> >On Mon, Sep 17, 2018 at 6:05 PM nixiaoming  wrote:
>...
>> >> diff --git a/include/linux/fsnotify_backend.h 
>> >> b/include/linux/fsnotify_backend.h
>> >> index b8f4182..44c659f 100644
>> >> --- a/include/linux/fsnotify_backend.h
>> >> +++ b/include/linux/fsnotify_backend.h
>> >> @@ -193,6 +193,7 @@ struct fsnotify_group {
>> >> unsigned int max_marks;
>> >> struct user_struct *user;
>> >> bool audit;
>> >> +   bool should_report_tid;
>> >
>> >For brevity I would call that report_tid, but not insisting.
>> >
>>
>> Whether it is better to change to "unsigned int flags"
>> Save "group->fanotify_data.flags=flags;" in "fanotify_init"
>> Determine whether "group->fanotify_data.flags" contains "FAN_EVENT_INFO_TID" 
>> in "fanotify_alloc_event";
>>
>> At the same time, if there are other flags that need to be used later, there 
>> is no need to add new members.
>>
>> By the way, whether or not "bool audit" can also be included by flags
>>
>
>I strongly agree. Didn't want to impose this change on you, but in
>fact, I already did
>that in my own patch set, so you can use my patches as reference:
>https://github.com/amir73il/linux/commit/5225fe1e19c74f4d7a4a4cc98ff6ef5872c8e620
>https://github.com/amir73il/linux/commit/0d1a226f5c18012f19ed6eabfab46f0f125ec190
>
>If you do this you need to separate your change into 2 patches.
>First make the fanotify_data.flags change collecting the pieces from both
>my patches.
>Then make your TID change using fanotify_data.flags.
>
>Thanks,
>Amir.
>
Should I do this:
1 git cherry-pick 5225fe1e19c74f4d7a4a4cc98ff6ef5872c8e620 
Git cherry-pick 0d1a226f5c18012f19ed6eabfab46f0f125ec190
  Manually handle patch conflicts 
2 Add a new flag "FAN_EVENT_INFO_TID" into fanotify_data.flags
3 Incorporate "bool audit" into fanotify_data.flags
4 Submit 4 patches

thanks


Re: [PATCH] x86/speculation: Use AMD specific retpoline for inline asm on AMD

2018-09-18 Thread Peter Zijlstra
On Mon, Sep 17, 2018 at 10:17:30PM -0700, Zhenzhong Duan wrote:
> Lfence is preferred than general retpoline on AMD, add this option
> in C / inline asm just as the ASM code does.
> 
> For x86_64, it still help to have minimal retpoline for kernel even
> if gcc doesn't support it, change the inline asm for x86 so that it
> could also be used by x86_64.
> Add ANNOTATE_NOSPEC_ALTERNATIVE for i386 to avoid below warning:
> "warning: objtool: .altinstr_replacement+0x10: unsupported
> intra-function call"
> "warning: objtool: If this is a retpoline, please patch it
> in with alternatives and annotate it with ANNOTATE_NOSPEC_ALTERNATIVE."

This Changelog is almost unreadable, please rewrite.

Reverse engineering the patch you add RETPOLINE_AMD support to the
inline-asm CALL_NOSPEC so that they match the asm CALL_NOSPEC.

> Signed-off-by: Zhenzhong Duan 
> ---
>  arch/x86/include/asm/nospec-branch.h |   23 ---
>  1 files changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/x86/include/asm/nospec-branch.h 
> b/arch/x86/include/asm/nospec-branch.h
> index fd2a8c1..2d49eab 100644
> --- a/arch/x86/include/asm/nospec-branch.h
> +++ b/arch/x86/include/asm/nospec-branch.h
> @@ -170,21 +170,26 @@
>   */
>  # define CALL_NOSPEC \
>   ANNOTATE_NOSPEC_ALTERNATIVE \
> - ALTERNATIVE(\
> + ALTERNATIVE_2(  \
>   ANNOTATE_RETPOLINE_SAFE \
>   "call *%[thunk_target]\n",  \
>   "call __x86_indirect_thunk_%V[thunk_target]\n", \
> - X86_FEATURE_RETPOLINE)
> + X86_FEATURE_RETPOLINE,  \
> + "lfence;\n" \
> + ANNOTATE_RETPOLINE_SAFE \
> + "call *%[thunk_target]\n",  \
> + X86_FEATURE_RETPOLINE_AMD)
>  # define THUNK_TARGET(addr) [thunk_target] "r" (addr)

That's OK.

>  
> -#elif defined(CONFIG_X86_32) && defined(CONFIG_RETPOLINE)
> +#elif defined(CONFIG_RETPOLINE)

This doesn't make any sense..

>  /*
>   * For i386 we use the original ret-equivalent retpoline, because
>   * otherwise we'll run out of registers. We don't care about CET
>   * here, anyway.
>   */
>  # define CALL_NOSPEC \
> - ALTERNATIVE(\
> + ANNOTATE_NOSPEC_ALTERNATIVE \
> + ALTERNATIVE_2(  \
>   ANNOTATE_RETPOLINE_SAFE \
>   "call *%[thunk_target]\n",  \
>   "   jmp904f;\n" \
> @@ -194,12 +199,16 @@
>   "   lfence;\n"  \
>   "   jmp902b;\n" \
>   "   .align 16\n"\
> - "903:   addl   $4, %%esp;\n"\
> - "   pushl  %[thunk_target];\n"  \
> + "903:   add   $4, %%" _ASM_SP ";\n" \
> + "   push  %[thunk_target];\n"   \

Yeah, don't do that.

>   "   ret;\n" \
>   "   .align 16\n"\
>   "904:   call   901b;\n",\
> - X86_FEATURE_RETPOLINE)
> + X86_FEATURE_RETPOLINE,  \
> + "lfence;\n" \
> + ANNOTATE_RETPOLINE_SAFE \
> + "call *%[thunk_target]\n",  \
> + X86_FEATURE_RETPOLINE_AMD)

And that's OK again.


Re: [PATCH 11/19] vmw_balloon: rework the inflate and deflate loops

2018-09-18 Thread kbuild test robot
Hi Nadav,

I love your patch! Yet something to improve:

[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on v4.19-rc4 next-20180913]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Nadav-Amit/vmw_balloon-compaction-shrinker-64-bit-etc/20180918-152302
config: i386-randconfig-s2-09171149 (attached as .config)
compiler: gcc-6 (Debian 6.4.0-9) 6.4.0 20171026
reproduce:
# save the attached .config to linux build tree
make ARCH=i386 

All errors (new ones prefixed by >>):

   drivers/misc/vmw_balloon.o: In function `vmballoon_deflate':
>> drivers/misc/vmw_balloon.c:1073: undefined reference to `__divdi3'
   drivers/misc/vmw_balloon.o: In function `vmballoon_inflate':
   drivers/misc/vmw_balloon.c:966: undefined reference to `__divdi3'

vim +1073 drivers/misc/vmw_balloon.c

  1018  
  1019  /**
  1020   * vmballoon_deflate() - Decrease the size of the balloon.
  1021   *
  1022   * @b: pointer to the balloon
  1023   * @n_frames: the number of frames to deflate. If zero, automatically
  1024   * calculated according to the target size.
  1025   * @coordinated: whether to coordinate with the host
  1026   *
  1027   * Decrease the size of the balloon allowing guest to use more memory.
  1028   *
  1029   * Return: The number of deflated frames (i.e., basic page size units)
  1030   */
  1031  static unsigned long vmballoon_deflate(struct vmballoon *b, uint64_t 
n_frames,
  1032 bool coordinated)
  1033  {
  1034  unsigned long deflated_frames = 0;
  1035  unsigned long tried_frames = 0;
  1036  struct vmballoon_ctl ctl = {
  1037  .pages = LIST_HEAD_INIT(ctl.pages),
  1038  .refused_pages = LIST_HEAD_INIT(ctl.refused_pages),
  1039  .page_size = VMW_BALLOON_4K_PAGE,
  1040  .op = VMW_BALLOON_DEFLATE
  1041  };
  1042  
  1043  /* free pages to reach target */
  1044  while (true) {
  1045  unsigned int to_deflate_pages, n_unlocked_frames;
  1046  unsigned int page_in_frames;
  1047  int64_t to_deflate_frames;
  1048  bool deflated_all;
  1049  
  1050  page_in_frames = 
vmballoon_page_in_frames(ctl.page_size);
  1051  
  1052  VM_BUG_ON(!list_empty());
  1053  VM_BUG_ON(ctl.n_pages);
  1054  VM_BUG_ON(!list_empty(_pages));
  1055  VM_BUG_ON(ctl.n_refused_pages);
  1056  
  1057  /*
  1058   * If we were requested a specific number of frames, we 
try to
  1059   * deflate this number of frames. Otherwise, deflation 
is
  1060   * performed according to the target and balloon size.
  1061   */
  1062  to_deflate_frames = n_frames ? n_frames - tried_frames :
  1063 -vmballoon_change(b);
  1064  
  1065  /* break if no work to do */
  1066  if (to_deflate_frames <= 0)
  1067  break;
  1068  
  1069  /*
  1070   * Calculate the number of frames based on current page 
size,
  1071   * but limit the deflated frames to a single chunk
  1072   */
> 1073  to_deflate_pages = min_t(unsigned long, 
> b->batch_max_pages,
  1074   DIV_ROUND_UP(to_deflate_frames,
  1075page_in_frames));
  1076  
  1077  /* First take the pages from the balloon pages. */
  1078  vmballoon_dequeue_page_list(b, , _pages,
  1079  ctl.page_size, 
to_deflate_pages);
  1080  
  1081  /*
  1082   * Before pages are moving to the refused list, count 
their
  1083   * frames as frames that we tried to deflate.
  1084   */
  1085  tried_frames += ctl.n_pages * page_in_frames;
  1086  
  1087  /*
  1088   * Unlock the pages by communicating with the 
hypervisor if the
  1089   * communication is coordinated (i.e., not pop). We 
ignore the
  1090   * return code. Instead we check if all the pages we 
manage to
  1091   * unlock all the pages. If we failed, we will move to 
the next
  1092   * page size, and would eventually try again later.
  1093   */
  1094  if (coordinated)
  1095  vmballoon_lock(b, );
  1096  
  1097  /*
  1098   * Check if we deflated enough. We will move 

Re: [PATCH 14/33] vfs: Implement a filesystem superblock creation/configuration context [ver #11]

2018-09-18 Thread Sergey Senozhatsky
On (08/01/18 16:25), David Howells wrote:
[..]
> @@ -2460,18 +2428,41 @@ static int do_remount(struct path *path, int 
> ms_flags, int sb_flags,
>   if (!can_change_locked_flags(mnt, mnt_flags))
>   return -EPERM;
>  
> - err = security_sb_remount(sb, data, data_size);
> - if (err)
> - return err;
> + if (type->init_fs_context) {
> + fc = vfs_sb_reconfig(path, sb_flags);
> + if (IS_ERR(fc))
> + return PTR_ERR(fc);
> +
> + err = parse_monolithic_mount_data(fc, data, data_size);
> + if (err < 0)
> + goto err_fc;
> +
> + if (fc->ops->validate) {
> + err = fc->ops->validate(fc);
> + if (err < 0)
> + goto err_fc;
> + }
> +
> + err = security_fs_context_validate(fc);
> + if (err)
> + return err;

goto err_fc?

> + } else {
> + err = security_sb_remount(sb, data, data_size);
> + if (err)
> + return err;
> + }

goto err_fc?

-ss


Re: pinctrl-icelake: driver writes to wrong offsets?

2018-09-18 Thread Mika Westerberg
On Mon, Sep 17, 2018 at 11:16:41AM -0700, Rajat Jain wrote:
> On Mon, Sep 17, 2018 at 1:13 AM Mika Westerberg
>  wrote:
> >
> > On Fri, Sep 14, 2018 at 05:18:34PM -0700, Rajat Jain wrote:
> > > This is to report what I think is a problem in the pinctrl-icelake
> > > driver. It seems that when trying to control GPIO pins GPP_A* and
> > > GPIO_B*, the driver ends up writing to incorrect PADCFG registers.
> > > I've reached this conclusion by putting debug prints in the driver,
> > > although this can be seen by the following commands too. Please let me
> > > know if something is wrong in my experiments. For example, when trying
> > > to control GPP_B8/ISH_I2C1_SCL, the driver ends up writing to
> > > GPP_A6/ESPI_RESETB registers.
> >
> > Hmm, when you add debug prints to the driver and you access GPIO 224
> > (GPP_B8/ISH_I2C1_SCL) from userspace you can see that the driver
> > actually uses PADCFG registers of GPP_A6/ESPI_RESETB? So that it is not
> > just a side-effect of how the pins are wired on your board.
> 
> Right, also I don't have to use put debug prints as it can be seen
> from the following debug files. And it is not isolated to just this
> pin. For instance, in this examples you can see that another pin 18
> (GPP_B10/I2C5_SCL) that I'm trying to write , the value actually gets
> written to the PADCFG for (GPP_A8/I2S2_SFRM) i.e. pin42. So there is
> clearly a pattern:
> 
> static const struct pinctrl_pin_desc icllp_pins[] = {
>  ...
> /* GPP_B */
> ..
> PINCTRL_PIN(18, "I2C5_SCL"),  <- GPP_B10/I2C5_SCL = Pin 18
> 
> localhost /sys/class/gpio # cat
> /sys/kernel/debug/pinctrl/INT3455\:00/gpio-ranges
> GPIO ranges handled:
> 0: INT3455:00 GPIOS [184 - 191] PINS [0 - 7]
> 32: INT3455:00 GPIOS [216 - 241] PINS [8 - 33]  < pin 18 = gpio 226
> 
> 
> localhost /sys/class/gpio # cat
> /sys/kernel/debug/pinctrl/INT3455\:00/pins | grep
> "I2C5_SCL\|(I2S2_SFRM)"
> pin 18 (I2C5_SCL) mode 1 0x44000702 0x002a 0x [ACPI]
> pin 42 (I2S2_SFRM) mode 2 0x44000b00 0x0040 0x0100 [ACPI]
> localhost /sys/class/gpio #
> localhost /sys/class/gpio # echo 226 > export
> localhost /sys/class/gpio # cat
> /sys/kernel/debug/pinctrl/INT3455\:00/pins | grep
> "I2C5_SCL\|(I2S2_SFRM)"
> pin 18 (I2C5_SCL) GPIO 0x44000102 0x002a 0x [ACPI]
> pin 42 (I2S2_SFRM) mode 2 0x44000b00 0x0040 0x0100 [ACPI]
> localhost /sys/class/gpio #
> localhost /sys/class/gpio #
> localhost /sys/class/gpio # cat gpio226/value
> 0
> localhost /sys/class/gpio # cat gpio226/direction
> in
> localhost /sys/class/gpio # echo out > gpio226/direction
> localhost /sys/class/gpio # cat gpio226/direction
> out
> localhost /sys/class/gpio # cat
> /sys/kernel/debug/pinctrl/INT3455\:00/pins | grep
> "I2C5_SCL\|(I2S2_SFRM)"
> pin 18 (I2C5_SCL) GPIO 0x44000200 0x002a 0x [ACPI]
> pin 42 (I2S2_SFRM) mode 2 0x44000b00 0x0040 0x0100 [ACPI]
> localhost /sys/class/gpio #
> localhost /sys/class/gpio #
> localhost /sys/class/gpio # cat gpio226/value
> 0
> localhost /sys/class/gpio # echo 1 > gpio226/value
> localhost /sys/class/gpio # cat gpio226/value
> 0
> localhost /sys/class/gpio # cat
> /sys/kernel/debug/pinctrl/INT3455\:00/pins | grep
> "I2C5_SCL\|(I2S2_SFRM)"
> pin 18 (I2C5_SCL) GPIO 0x44000200 0x002a 0x [ACPI]
> pin 42 (I2S2_SFRM) mode 2 0x44000b01 0x0040 0x0100 [ACPI]
> localhost /sys/class/gpio #
> 
> As you can see in the above example, when I export the pins and change
> the directions from "in" to "out" PADCFG get updated correctly for pin
> 18, but when writing the value, it is the PADCFG for pin 42 that gets
> updated which is incorrect.

It looks like we are missing translation (call intel_gpio_to_pin()) in
intel_gpio_set(), intel_gpio_get() and intel_gpio_get_direction(). IIRC
gpiolib handles the translation but here it seems not. Strange.

> So this looks like a driver issue to me. Please let me know if I need
> to file a bug on bugzilla for this.

I agree, definitely driver issue. Please file bugzilla about this (add
me and Andy there as well) and we'll investigate.

Thanks!


[PATCH 2/4] kbuild: remove user ID check in scripts/mkmakefile

2018-09-18 Thread Masahiro Yamada
This line was added by commit fd5f0cd6b0ce ("kbuild: Do not overwrite
makefile as anohter user").  Its commit description says the intention
was to prevent $(objtree)/Makefile from being owned by root when e.g.
running 'make install'.

However, as commit 19514fc665ff ("arm, kbuild: make "make install" not
depend on vmlinux") stated, installation targets must not modify the
source tree in the first place.  If they do, we are already screwed up.
We must fix the root cause.

Installation targets should just copy files verbatim, hence we never
expect $(objtree)/Makefile is touched by root.  The user ID check in
scripts/mkmakefile is unneeded.

Signed-off-by: Masahiro Yamada 
---

 scripts/mkmakefile | 1 -
 1 file changed, 1 deletion(-)

diff --git a/scripts/mkmakefile b/scripts/mkmakefile
index e2106444..2435428 100755
--- a/scripts/mkmakefile
+++ b/scripts/mkmakefile
@@ -8,7 +8,6 @@
 # $1 - Kernel src directory
 # $2 - Output directory
 
-test ! -r $2/Makefile -o -O $2/Makefile || exit 0
 # Only overwrite automatically generated Makefiles
 # (so we do not overwrite kernel Makefile)
 if test -e $2/Makefile && ! grep -q Automatically $2/Makefile
-- 
2.7.4



[PATCH] misc: remove redundant include moduleparam.h

2018-09-18 Thread zhong jiang
module.h already contains moduleparam.h,  so it is safe to remove
the redundant include.

The issue is detected with the help of Coccinelle.

eePlease enter the commit message for your changes. Lines starting

Signed-off-by: zhong jiang 
---
 drivers/misc/mei/bus-fixup.c  | 1 -
 drivers/misc/vmw_vmci/vmci_host.c | 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/misc/mei/bus-fixup.c b/drivers/misc/mei/bus-fixup.c
index a6f41f9..80215c3 100644
--- a/drivers/misc/mei/bus-fixup.c
+++ b/drivers/misc/mei/bus-fixup.c
@@ -17,7 +17,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/drivers/misc/vmw_vmci/vmci_host.c 
b/drivers/misc/vmw_vmci/vmci_host.c
index 83e0c95..be732e5 100644
--- a/drivers/misc/vmw_vmci/vmci_host.c
+++ b/drivers/misc/vmw_vmci/vmci_host.c
@@ -15,7 +15,6 @@
 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
-- 
1.7.12.4



[PATCH 4/4] kbuild: simplify command line creation in scripts/mkmakefile

2018-09-18 Thread Masahiro Yamada
Assuming we never invoke the generated Makefile from outside of
the $(objtree) directory, $(CURDIR) points to the absolute path
of $(objtree).

BTW, 'lastword' is natively supported by GNU Make 3.81+, which
is the current requirement for building the kernel.

Signed-off-by: Masahiro Yamada 
---

 scripts/mkmakefile | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/scripts/mkmakefile b/scripts/mkmakefile
index 85995f9..412f13f 100755
--- a/scripts/mkmakefile
+++ b/scripts/mkmakefile
@@ -20,9 +20,6 @@ fi
 cat << EOF > Makefile
 # Automatically generated by $0: don't edit
 
-lastword = \$(word \$(words \$(1)),\$(1))
-makedir := \$(dir \$(call lastword,\$(MAKEFILE_LIST)))
-
 ifeq ("\$(origin V)", "command line")
 VERBOSE := \$(V)
 endif
@@ -30,15 +27,12 @@ ifneq (\$(VERBOSE),1)
 Q := @
 endif
 
-MAKEARGS := -C $1
-MAKEARGS += O=\$(if \$(patsubst /%,,\$(makedir)),\$(CURDIR)/)\$(patsubst 
%/,%,\$(makedir))
-
 MAKEFLAGS += --no-print-directory
 
 .PHONY: __sub-make \$(MAKECMDGOALS)
 
 __sub-make:
-   \$(Q)\$(MAKE) \$(MAKEARGS) \$(MAKECMDGOALS)
+   \$(Q)\$(MAKE) -C $1 O=\$(CURDIR) \$(MAKECMDGOALS)
 
 \$(filter-out __sub-make, \$(MAKECMDGOALS)): __sub-make
@:
-- 
2.7.4



[PATCH 3/4] kbuild: do not pass $(objtree) to scripts/mkmakefile

2018-09-18 Thread Masahiro Yamada
Since $(objtree) is always '.', it is not useful to pass it to
scripts/mkmakefile.  I assume nobody wants to run this script directly.

Signed-off-by: Masahiro Yamada 
---

 Makefile   | 2 +-
 scripts/mkmakefile | 7 +++
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index 6e1a059..3799bc5 100644
--- a/Makefile
+++ b/Makefile
@@ -482,7 +482,7 @@ PHONY += outputmakefile
 outputmakefile:
 ifneq ($(KBUILD_SRC),)
$(Q)ln -fsn $(srctree) source
-   $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree) $(objtree)
+   $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
 endif
 
 ifeq ($(cc-name),clang)
diff --git a/scripts/mkmakefile b/scripts/mkmakefile
index 2435428..85995f9 100755
--- a/scripts/mkmakefile
+++ b/scripts/mkmakefile
@@ -6,19 +6,18 @@
 
 # Usage
 # $1 - Kernel src directory
-# $2 - Output directory
 
 # Only overwrite automatically generated Makefiles
 # (so we do not overwrite kernel Makefile)
-if test -e $2/Makefile && ! grep -q Automatically $2/Makefile
+if test -e Makefile && ! grep -q Automatically Makefile
 then
exit 0
 fi
 if [ "${quiet}" != "silent_" ]; then
-   echo "  GEN $2/Makefile"
+   echo "  GEN Makefile"
 fi
 
-cat << EOF > $2/Makefile
+cat << EOF > Makefile
 # Automatically generated by $0: don't edit
 
 lastword = \$(word \$(words \$(1)),\$(1))
-- 
2.7.4



[LKP] [vfree, kvfree] a79ed8bfb2: BUG:sleeping_function_called_from_invalid_context_at_mm/util.c

2018-09-18 Thread kernel test robot
FYI, we noticed the following commit (built with gcc-6):

commit: a79ed8bfb24e899aa55de42703ae4508ff016311 ("[PATCH 3/3] vfree, kvfree: 
Add debug might sleeps.")
url: 
https://github.com/0day-ci/linux/commits/Andrey-Ryabinin/kvfree-Fix-misleading-comment/20180915-094734


in testcase: trinity
with following parameters:

runtime: 300s

test-description: Trinity is a linux system call fuzz tester.
test-url: http://codemonkey.org.uk/projects/trinity/


on test machine: qemu-system-i386 -enable-kvm -cpu Haswell,+smep,+smap -m 384M

caused below changes (please refer to attached dmesg/kmsg for entire 
log/backtrace):


++++
|| d835757305 | 
a79ed8bfb2 |
++++
| boot_successes | 0  | 
0  |
| boot_failures  | 12 | 
12 |
| INFO:trying_to_register_non-static_key | 12 | 
12 |
| WARNING:at_mm/slab_common.c:#kmalloc_slab  | 12 | 
12 |
| EIP:kmalloc_slab   | 12 | 
12 |
| Mem-Info   | 12 | 
12 |
| WARNING:at_lib/debugobjects.c:#__debug_object_init | 12 | 
12 |
| EIP:__debug_object_init| 12 | 
12 |
| WARNING:at_arch/x86/mm/dump_pagetables.c:#note_page| 8  | 
8  |
| EIP:note_page  | 8  | 
8  |
| BUG:sleeping_function_called_from_invalid_context_at_mm/util.c | 0  | 
12 |
++++



[3.265372] BUG: sleeping function called from invalid context at 
mm/util.c:449
[3.288552] in_atomic(): 0, irqs_disabled(): 0, pid: 142, name: 
rhashtable_thra
[3.301548] INFO: lockdep is turned off.
[3.302214] Preemption disabled at:
[3.302221] [] get_random_u32+0x4f/0x100
[3.327556] CPU: 0 PID: 142 Comm: rhashtable_thra Tainted: GW   
T 4.19.0-rc3-00266-ga79ed8bf #656
[3.328540] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
1.10.2-1 04/01/2014
[3.328540] Call Trace:
[3.328540]  ? dump_stack+0x55/0x7b
[3.328540]  ? get_random_u32+0x4f/0x100
[3.328540]  ? ___might_sleep+0x11d/0x170
[3.328540]  ? kvfree+0x61/0x70
[3.328540]  ? bucket_table_free+0x18/0x80
[3.328540]  ? bucket_table_alloc+0x79/0x160
[3.328540]  ? rhashtable_insert_slow+0x25d/0x2d0
[3.328540]  ? insert_retry+0x1df/0x320
[3.328540]  ? threadfunc+0xa3/0x3fe
[3.328540]  ? kzalloc+0x14/0x14
[3.328540]  ? _raw_spin_unlock_irqrestore+0x30/0x50
[3.328540]  ? kthread+0xd1/0x100
[3.328540]  ? insert_retry+0x320/0x320
[3.328540]  ? kthread_delayed_work_timer_fn+0x80/0x80
[3.328540]  ? ret_from_fork+0x2e/0x38
[5.372143] test 3125 add/delete pairs into rhlist
[5.403746] test 3125 random rhlist add/delete operations
[5.424742] Started 10 threads, 0 failed, rhltable test returns 0
[5.428940] test passed
[5.429422] test_printf: crng possibly not yet initialized. plain 'p' buffer 
contains "(ptrval)"
[5.429582] test_printf: all 240 tests passed
[5.431911] test_bitmap: test 13: input is '0-2047:128/256' OK, Time: 1362
[5.437605] test_bitmap: all 1524 tests passed
[5.439117] crc32: CRC_LE_BITS = 64, CRC_BE BITS = 64
[5.439954] crc32: self tests passed, processed 225944 bytes in 182273 nsec
[5.441271] crc32c: CRC_LE_BITS = 64
[5.441916] crc32c: self tests passed, processed 225944 bytes in 91343 nsec
[5.461018] crc32_combine: 8373 self tests passed
[5.484112] crc32c_combine: 8373 self tests passed
[5.485066] rbtree testing
[5.493229]  -> test 1 (latency of nnodes insert+delete): 21966 cycles
[5.500638]  -> test 2 (latency of nnodes cached insert+delete): 15776 cycles
[5.502454]  -> test 3 (latency of inorder traversal): 1708 cycles
[5.503461]  -> test 4 (latency to fetch first node)
[5.504259] non-cached: 24 cycles
[5.504920] cached: 0 cycles
[5.556187] augmented rbtree testing
[5.566165]  -> test 1 (latency of nnodes insert+delete): 26854 cycles
[5.575698]  -> test 2 (latency of nnodes cached insert+delete): 21175 cycles
[5.635774] gpio_it87: no device
[5.638713] input: Power Button as 
/devices/LNXSYSTM:00/LNXPWRBN:00/input/input0
[5.639917] ACPI: Power Button [PWRF]
[5.672299] r3964: Philips r3964 Driver $Revision: 1.10 $
[5.673230] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[5.706897] 00:05: 

Re: [PATCH] misc: remove redundant include moduleparam.h

2018-09-18 Thread zhong jiang
On 2018/9/18 16:55, Greg KH wrote:
> On Tue, Sep 18, 2018 at 04:34:42PM +0800, zhong jiang wrote:
>> module.h already contains moduleparam.h,  so it is safe to remove
>> the redundant include.
>>
>> The issue is detected with the help of Coccinelle.
>>
>> eePlease enter the commit message for your changes. Lines starting
> Odd line to have in a changelog text :)
>
> Please fix up and resend.
It's my fault to have a odd line.  I will resend. Thanks.

Sincerely,
zhong jiang
> tanks,
>
> greg k-h
>
> .
>




[PATCH 3/5] lib: Add umoddi3 and udivmoddi4 of GCC library routines

2018-09-18 Thread Zong Li
Add umoddi3 and udivmoddi4 support for 32-bit.

Signed-off-by: Zong Li 
---
 lib/Kconfig  |   3 +
 lib/Makefile |   1 +
 lib/udivmoddi4.c | 291 +++
 lib/umoddi3.c|  16 +++
 4 files changed, 311 insertions(+)
 create mode 100644 lib/udivmoddi4.c
 create mode 100644 lib/umoddi3.c

diff --git a/lib/Kconfig b/lib/Kconfig
index a3928d4..d82f206 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -621,3 +621,6 @@ config GENERIC_LIB_CMPDI2
 
 config GENERIC_LIB_UCMPDI2
bool
+
+config GENERIC_LIB_UMODDI3
+   bool
diff --git a/lib/Makefile b/lib/Makefile
index ca3f7eb..51bf24d 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -271,3 +271,4 @@ obj-$(CONFIG_GENERIC_LIB_LSHRDI3) += lshrdi3.o
 obj-$(CONFIG_GENERIC_LIB_MULDI3) += muldi3.o
 obj-$(CONFIG_GENERIC_LIB_CMPDI2) += cmpdi2.o
 obj-$(CONFIG_GENERIC_LIB_UCMPDI2) += ucmpdi2.o
+obj-$(CONFIG_GENERIC_LIB_UMODDI3) += umoddi3.o udivmoddi4.o
diff --git a/lib/udivmoddi4.c b/lib/udivmoddi4.c
new file mode 100644
index 000..69f2d36
--- /dev/null
+++ b/lib/udivmoddi4.c
@@ -0,0 +1,291 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include 
+
+#define count_leading_zeros(COUNT, X)   ((COUNT) = __builtin_clz(X))
+
+#define W_TYPE_SIZE 32
+
+#define __ll_B ((unsigned long) 1 << (W_TYPE_SIZE / 2))
+#define __ll_lowpart(t) ((unsigned long) (t) & (__ll_B - 1))
+#define __ll_highpart(t) ((unsigned long) (t) >> (W_TYPE_SIZE / 2))
+
+/* If we still don't have umul_ppmm, define it using plain C. */
+#if !defined(umul_ppmm)
+#define umul_ppmm(w1, w0, u, v)
\
+   do {\
+   unsigned long __x0, __x1, __x2, __x3;   \
+   unsigned short __ul, __vl, __uh, __vh;  \
+   \
+   __ul = __ll_lowpart(u); \
+   __uh = __ll_highpart(u);\
+   __vl = __ll_lowpart(v); \
+   __vh = __ll_highpart(v);\
+   \
+   __x0 = (unsigned long) __ul * __vl; \
+   __x1 = (unsigned long) __ul * __vh; \
+   __x2 = (unsigned long) __uh * __vl; \
+   __x3 = (unsigned long) __uh * __vh; \
+   \
+   __x1 += __ll_highpart(__x0);\
+   __x1 += __x2;   \
+   if (__x1 < __x2)\
+   __x3 += __ll_B; \
+   \
+   (w1) = __x3 + __ll_highpart(__x1);  \
+   (w0) = __ll_lowpart(__x1) * __ll_B + __ll_lowpart(__x0);\
+   } while (0)
+#endif
+
+#if !defined(sub_ddmmss)
+#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
+   do {\
+   unsigned long __x;  \
+   __x = (al) - (bl);  \
+   (sh) = (ah) - (bh) - (__x > (al));  \
+   (sl) = __x; \
+   } while (0)
+#endif
+
+/* Define this unconditionally, so it can be used for debugging. */
+#define __udiv_qrnnd_c(q, r, n1, n0, d)
\
+   do {\
+   unsigned long __d1, __d0, __q1, __q0;   \
+   unsigned long __r1, __r0, __m;  \
+   __d1 = __ll_highpart(d);\
+   __d0 = __ll_lowpart(d); \
+   \
+   __r1 = (n1) % __d1; \
+   __q1 = (n1) / __d1; \
+   __m = (unsigned long) __q1 * __d0;  \
+   __r1 = __r1 * __ll_B | __ll_highpart(n0);   \
+   if (__r1 < __m) {   \
+   __q1--, __r1 += (d);\
+   if (__r1 >= (d))\
+   if (__r1 < __m) \
+   __q1--, __r1 += (d);\
+   }

[PATCH 4/5] RISC-V: Select GENERIC_LIB_UMODDI3 on RV32

2018-09-18 Thread Zong Li
On 32-bit, it need to use __umoddi3 by some drivers.

Signed-off-by: Zong Li 
---
 arch/riscv/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index a344980..dc262fa 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -108,6 +108,7 @@ config ARCH_RV32I
select GENERIC_LIB_ASHRDI3
select GENERIC_LIB_LSHRDI3
select GENERIC_LIB_UCMPDI2
+   select GENERIC_LIB_UMODDI3
 
 config ARCH_RV64I
bool "RV64I"
-- 
2.7.4



[PATCH 5/5] RISC-V: Avoid corrupting the upper 32-bit of phys_addr_t in ioremap

2018-09-18 Thread Zong Li
From: Vincent Chen 

For 32bit, the upper 32-bit of phys_addr_t will be flushed to zero
after AND with PAGE_MASK because the data type of PAGE_MASK is
unsigned long. To fix this problem, the page alignment is done by
subtracting the page offset instead of AND with PAGE_MASK.

Signed-off-by: Vincent Chen 
---
 arch/riscv/mm/ioremap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/mm/ioremap.c b/arch/riscv/mm/ioremap.c
index 70ef272..bd2f2db 100644
--- a/arch/riscv/mm/ioremap.c
+++ b/arch/riscv/mm/ioremap.c
@@ -42,7 +42,7 @@ static void __iomem *__ioremap_caller(phys_addr_t addr, 
size_t size,
 
/* Page-align mappings */
offset = addr & (~PAGE_MASK);
-   addr &= PAGE_MASK;
+   addr -= offset;
size = PAGE_ALIGN(size + offset);
 
area = get_vm_area_caller(size, VM_IOREMAP, caller);
-- 
2.7.4



Re: [PATCH v4 2/2] pci: dwc: pci-dra7xx: Enable errata i870 for both EP and RC mode

2018-09-18 Thread Lorenzo Pieralisi
On Mon, Sep 17, 2018 at 11:36:35PM +0530, Vignesh R wrote:
> Errata i870 is applicable in both EP and RC mode. Therefore rename
> function dra7xx_pcie_ep_unaligned_memaccess(), that implements errata
> workaround, to dra7xx_pcie_unaligned_memaccess() and call it from a
> common place. So, that errata workaround is applied for both modes of
> operation.
> 
> Reported-by: Chris Welch 
> Signed-off-by: Vignesh R 
> Acked-by: Kishon Vijay Abraham I 
> Acked-by: Lorenzo Pieralisi 
> ---
>  drivers/pci/controller/dwc/pci-dra7xx.c | 12 ++--
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/pci/controller/dwc/pci-dra7xx.c 
> b/drivers/pci/controller/dwc/pci-dra7xx.c
> index ce9224a36f62..43711561a199 100644
> --- a/drivers/pci/controller/dwc/pci-dra7xx.c
> +++ b/drivers/pci/controller/dwc/pci-dra7xx.c
> @@ -542,7 +542,7 @@ static const struct of_device_id of_dra7xx_pcie_match[] = 
> {
>  };
>  
>  /*
> - * dra7xx_pcie_ep_unaligned_memaccess: workaround for AM572x/AM571x Errata 
> i870
> + * dra7xx_pcie_unaligned_memaccess: workaround for AM572x/AM571x Errata i870
>   * @dra7xx: the dra7xx device where the workaround should be applied
>   *
>   * Access to the PCIe slave port that are not 32-bit aligned will result
> @@ -552,7 +552,7 @@ static const struct of_device_id of_dra7xx_pcie_match[] = 
> {
>   *
>   * To avoid this issue set PCIE_SS1_AXI2OCP_LEGACY_MODE_ENABLE to 1.
>   */
> -static int dra7xx_pcie_ep_unaligned_memaccess(struct device *dev)
> +static int dra7xx_pcie_unaligned_memaccess(struct device *dev)
>  {
>   int ret;
>   struct device_node *np = dev->of_node;
> @@ -695,6 +695,10 @@ static int __init dra7xx_pcie_probe(struct 
> platform_device *pdev)
>   if (dra7xx->link_gen < 0 || dra7xx->link_gen > 2)
>   dra7xx->link_gen = 2;
>  
> + ret = dra7xx_pcie_unaligned_memaccess(dev);
> + if (ret)
> + dev_err(dev, "WA for Errata i870 not applied. Update DT\n");

Hi Vignesh,

I am not sure you want this code merged into an -rc given that without
a DTS update is basically pointless (and for that bindings should at
least be merged too as a fix).

I would also like to understand why a dev_err() is sufficient, can the
controller work without the WA applied ?

Nit: Lastly, in the dev_err() message, it is your call/code but I would not
print "update DT", kernel log is not a command prompt but that's just my
opinion so it is up to you.

Thanks,
Lorenzo

>   switch (mode) {
>   case DW_PCIE_RC_TYPE:
>   if (!IS_ENABLED(CONFIG_PCI_DRA7XX_HOST)) {
> @@ -717,10 +721,6 @@ static int __init dra7xx_pcie_probe(struct 
> platform_device *pdev)
>   dra7xx_pcie_writel(dra7xx, PCIECTRL_TI_CONF_DEVICE_TYPE,
>  DEVICE_TYPE_EP);
>  
> - ret = dra7xx_pcie_ep_unaligned_memaccess(dev);
> - if (ret)
> - goto err_gpio;
> -
>   ret = dra7xx_add_pcie_ep(dra7xx, pdev);
>   if (ret < 0)
>   goto err_gpio;
> -- 
> 2.19.0
> 


Re: [PATCH v3 2/2] [media] videobuf2-dc: Support cacheable MMAP

2018-09-18 Thread Tomasz Figa
Hi Hans,

On Mon, Sep 17, 2018 at 11:41 PM Hans Verkuil  wrote:
>
> I'm going through old patches in patchwork that fell through the
> cracks, and this is one of them.
>
> If this is still desired, please rebase and repost.
>
> I'm marking this series as Obsoleted in patchwork, since it no longer
> applies anyway.

The ability to have cached mappings of MMAP buffers is strongly
desired, but I'm afraid not the way this patch does it.

First of all, it's not a decision for the driver to make, but for the
user space, depending on the access pattern it does. It also isn't
something specific to vb2-dma-contig only.

I remember Sakari had a series that attempted to solve this in a more
comprehensive way[1]. I remember it had some minor problems when I
reviewed it, but generally the idea seemed sane.

Sakari, do you have any plans to revive that work?

[1] https://www.mail-archive.com/linux-media@vger.kernel.org/msg112459.html

Best regards,
Tomasz

>
> Regards,
>
> Hans
>
>
> On 10/26/2016 10:52 AM, Thierry Escande wrote:
> > From: Heng-Ruey Hsu 
> >
> > DMA allocations for MMAP type are uncached by default. But for
> > some cases, CPU has to access the buffers. ie: memcpy for format
> > converter. Supporting cacheable MMAP improves huge performance.
> >
> > This patch enables cacheable memory for DMA coherent allocator in mmap
> > buffer allocation if non-consistent DMA attribute is set and kernel
> > mapping is present. Even if userspace doesn't mmap the buffer, sync
> > still should be happening if kernel mapping is present.
> > If not done in allocation, it is enabled when memory is mapped from
> > userspace (if non-consistent DMA attribute is set).
> >
> > Signed-off-by: Heng-Ruey Hsu 
> > Tested-by: Heng-ruey Hsu 
> > Reviewed-by: Tomasz Figa 
> > Signed-off-by: Thierry Escande 
> > ---
> >  drivers/media/v4l2-core/videobuf2-dma-contig.c | 16 
> >  1 file changed, 16 insertions(+)
> >
> > diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c 
> > b/drivers/media/v4l2-core/videobuf2-dma-contig.c
> > index 0d9665d..89b534a 100644
> > --- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
> > +++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
> > @@ -151,6 +151,10 @@ static void vb2_dc_put(void *buf_priv)
> >   sg_free_table(buf->sgt_base);
> >   kfree(buf->sgt_base);
> >   }
> > + if (buf->dma_sgt) {
> > + sg_free_table(buf->dma_sgt);
> > + kfree(buf->dma_sgt);
> > + }
> >   dma_free_attrs(buf->dev, buf->size, buf->cookie, buf->dma_addr,
> >  buf->attrs);
> >   put_device(buf->dev);
> > @@ -192,6 +196,14 @@ static void *vb2_dc_alloc(struct device *dev, unsigned 
> > long attrs,
> >   buf->handler.put = vb2_dc_put;
> >   buf->handler.arg = buf;
> >
> > + /*
> > +  * Enable cache maintenance. Even if userspace doesn't mmap the 
> > buffer,
> > +  * sync still should be happening if kernel mapping is present.
> > +  */
> > + if (!(buf->attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
> > + buf->attrs & DMA_ATTR_NON_CONSISTENT)
> > + buf->dma_sgt = vb2_dc_get_base_sgt(buf);
> > +
> >   atomic_inc(>refcount);
> >
> >   return buf;
> > @@ -227,6 +239,10 @@ static int vb2_dc_mmap(void *buf_priv, struct 
> > vm_area_struct *vma)
> >
> >   vma->vm_ops->open(vma);
> >
> > + /* Enable cache maintenance if not enabled in allocation. */
> > + if (!buf->dma_sgt && buf->attrs & DMA_ATTR_NON_CONSISTENT)
> > + buf->dma_sgt = vb2_dc_get_base_sgt(buf);
> > +
> >   pr_debug("%s: mapped dma addr 0x%08lx at 0x%08lx, size %ld\n",
> >   __func__, (unsigned long)buf->dma_addr, vma->vm_start,
> >   buf->size);
> >
>


Re: [PATCH 14/33] vfs: Implement a filesystem superblock creation/configuration context [ver #11]

2018-09-18 Thread Sergey Senozhatsky
On (09/18/18 18:07), Sergey Senozhatsky wrote:
> emergency_remount()
>  do_emergency_remount()
>   do_emergency_remount_callback()
>reconfigure_super()
> 
> At fc->ops dereference:
> 
>  981 if (fc->ops->reconfigure) {
>   ^
>  982 retval = fc->ops->reconfigure(fc);
>  983 if (retval == 0) {
>  984 security_sb_reconfigure(fc);
> 
> 
> So the check either better be
> 
>   if (fc->ops && fc->ops->reconfigure)

I guess I was pretty lucky to have leading zeroes in that fc.

David, do you want to add a macro which would make `struct fs_context fc'
misuse less possible? There are 3 users right now who don't use
vfs_new_fs_context(), and none of them appear to properly set all of
`struct fs_context fc' members. This can cause problems in the future,
right?

fs/namespace.c: struct fs_context fc = {
fs/super.c: struct fs_context fc = {
fs/super.c: struct fs_context fc = {

-ss


Re: [PATCH] samples: disable CONFIG_SAMPLES for UML

2018-09-18 Thread Richard Weinberger
Am Dienstag, 18. September 2018, 05:58:33 CEST schrieb Masahiro Yamada:
> Some samples require headers installation, so commit 3fca1700c4c3
> ("kbuild: make samples really depend on headers_install") added
> such dependency in the top Makefile.  However, UML fails to build
> with CONFIG_SAMPLES=y because UML does not support headers_install.
> 
> Fixes: 3fca1700c4c3 ("kbuild: make samples really depend on headers_install")
> Reported-by: Kees Cook 
> Cc: David Howells 
> Signed-off-by: Masahiro Yamada 

Is there anything UML can do better?
Not sure whether an arch like is supposed to install headers at all,
I guess no. :)

Thanks,
//richard




Re: [PATCH] md: bitmap: use mddev_suspend/resume instead of ->quiesce()

2018-09-18 Thread Gi-Oh Kim
On Thu, Sep 13, 2018 at 5:35 PM, Jack Wang  wrote:
> From: Jack Wang 
>
> After 9e1cc0a54556 ("md: use mddev_suspend/resume instead of ->quiesce()")
> We still have similar left in bitmap functions.
>
> Replace quiesce() with mddev_suspend/resume.
>
> Also move md_bitmap_create out of mddev_suspend. and move mddev_resume
> after md_bitmap_destroy. as we did in set_bitmap_file.
>
> Signed-off-by: Jack Wang 

Reviewed-by: Gioh Kim 





-- 
GIOH KIM
Linux Kernel Entwickler

ProfitBricks GmbH
Greifswalder Str. 207
D - 10405 Berlin

Tel:   +49 176 2697 8962
Fax:  +49 30 577 008 299
Email:gi-oh@profitbricks.com
URL:  https://www.profitbricks.de

Sitz der Gesellschaft: Berlin
Registergericht: Amtsgericht Charlottenburg, HRB 125506 B
Geschäftsführer: Achim Weiss, Matthias Steinberg, Christoph Steffens


Re: [PATCH V5 1/3] irqchip: add C-SKY irqchip drivers

2018-09-18 Thread Guo Ren
On Mon, Sep 17, 2018 at 02:27:31PM +0100, Marc Zyngier wrote:
> On Mon, 17 Sep 2018 03:09:29 +0100,
> Guo Ren  wrote:
> 
> [...]
> 
> > > > +
> > > > +   irq_set_default_host(root_domain);
> > > 
> > > Please drop this. There is no reason to use this on any modern, DT
> > > based architecture.
Ok.

> > Please let me keep this and in my arch/csky/kernel/smp.c:
> > 
> > void __init setup_smp_ipi(void)
> > {
> > ...
> > irq_create_mapping(NULL, IPI_IRQ);
> > rc = request_percpu_irq(IPI_IRQ, handle_ipi, "IPI Interrupt", 
> > _dummy_dev);
> 
> This looks quite wrong. Reading the code at
> https://lkml.org/lkml/2018/9/12/674, it really looks like you're
> assuming that IPI_IRQ will be mapped to a Linux IRQ with the same
> number. Nothing could be farther from the truth.
Yes, you are right. I should use irq_create_mapping() return value as
the arg for request_percpu_irq. It's a stupid bug, thoug it happens to
work.

> The Linux IRQ is returned as the result of irq_create_mapping, which
> you're ignoring. You'd be better off creating this mapping from the
> irqchip code, and expose the resulting Linux IRQ to oyu SMP code by
> any mean of your choice (such as moving the send_ipi_message into the
> irqchip code as well).
Ok, see my diff below, is that OK?

--- a/drivers/irqchip/irq-csky-mpintc.c
+++ b/drivers/irqchip/irq-csky-mpintc.c
@@ -16,6 +16,7 @@
 #include 
 #include 
 
+static struct irq_domain *root_domain;
 static void __iomem *INTCG_base;
 static void __iomem *INTCL_base;
 
@@ -46,7 +47,7 @@ static void csky_mpintc_handler(struct pt_regs *regs)
void __iomem *reg_base = this_cpu_read(intcl_reg);
 
do {
-   handle_domain_irq(NULL,
+   handle_domain_irq(root_domain,
  readl_relaxed(reg_base + INTCL_RDYIR),
  regs);
} while (readl_relaxed(reg_base + INTCL_HPPIR) & BIT(31));
@@ -139,13 +140,17 @@ static void csky_mpintc_send_ipi(const unsigned long 
*mask, unsigned long irq)
 */
writel_relaxed((*mask) << 8 | irq, reg_base + INTCL_SIGR);
 }
+
+static int csky_mpintc_ipi_irq_mapping(void)
+{
+   return irq_create_mapping(root_domain, IPI_IRQ);
+}
 #endif
 
 /* C-SKY multi processor interrupt controller */
 static int __init
 csky_mpintc_init(struct device_node *node, struct device_node *parent)
 {
-   struct irq_domain *root_domain;
unsigned int cpu, nr_irq;
int ret;
 
@@ -172,8 +177,6 @@ csky_mpintc_init(struct device_node *node, struct 
device_node *parent)
if (!root_domain)
return -ENXIO;
 
-   irq_set_default_host(root_domain);
-
/* for every cpu */
for_each_present_cpu(cpu) {
per_cpu(intcl_reg, cpu) = INTCL_base + (INTCL_SIZE * cpu);
@@ -184,6 +187,8 @@ csky_mpintc_init(struct device_node *node, struct 
device_node *parent)
 
 #ifdef CONFIG_SMP
set_send_ipi(_mpintc_send_ipi);
+
+   set_ipi_irq_mapping(_mpintc_ipi_irq_mapping);
 #endif
 
return 0;

diff --git a/arch/csky/include/asm/smp.h b/arch/csky/include/asm/smp.h
index 9a53abf..fed3a5a 100644
--- a/arch/csky/include/asm/smp.h
+++ b/arch/csky/include/asm/smp.h
@@ -7,6 +7,8 @@
 
 #ifdef CONFIG_SMP
 
+#define IPI_IRQ15
+
 void __init setup_smp(void);
 
 void __init setup_smp_ipi(void);
@@ -19,6 +21,8 @@ void arch_send_call_function_single_ipi(int cpu);
 
 void __init set_send_ipi(void (*func)(const unsigned long *, unsigned long));
 
+void __init set_ipi_irq_mapping(int (*func)(void));
+
 #define raw_smp_processor_id() (current_thread_info()->cpu)
 
 #endif /* CONFIG_SMP */
diff --git a/arch/csky/kernel/smp.c b/arch/csky/kernel/smp.c
index 522c73f..f8343f6 100644
--- a/arch/csky/kernel/smp.c
+++ b/arch/csky/kernel/smp.c
@@ -20,8 +20,6 @@
 #include 
 #include 
 
-#define IPI_IRQ15
-
 static struct {
unsigned long bits cacheline_aligned;
 } ipi_data[NR_CPUS] __cacheline_aligned;
@@ -121,13 +119,23 @@ void __init enable_smp_ipi(void)
enable_percpu_irq(IPI_IRQ, 0);
 }
 
+static int (*arch_ipi_irq_mapping)(void) = NULL;
+
+void __init set_ipi_irq_mapping(int (*func)(void))
+{
+   if (arch_ipi_irq_mapping)
+   return;
+
+   arch_ipi_irq_mapping = func;
+}
+
 void __init setup_smp_ipi(void)
 {
-   int rc;
+   int rc, irq;
 
-   irq_create_mapping(NULL, IPI_IRQ);
+   irq = arch_ipi_irq_mapping();
 
-   rc = request_percpu_irq(IPI_IRQ, handle_ipi, "IPI Interrupt", 
_dummy_dev);
+   rc = request_percpu_irq(irq, handle_ipi, "IPI Interrupt", 
_dummy_dev);
if (rc)
panic("%s IRQ request failed\n", __func__);


Re: linux-next: manual merge of the net-next tree with the net tree

2018-09-18 Thread Daniel Borkmann
On 09/18/2018 02:11 AM, Stephen Rothwell wrote:
> Hi all,
> 
> Today's linux-next merge of the net-next tree got a conflict in:
> 
>   tools/testing/selftests/net/tls.c
> 
> between commit:
> 
>   50c6b58a814d ("tls: fix currently broken MSG_PEEK behavior")
> 
> from the net tree and commit:
> 
>   c2ad647c6442 ("selftests/tls: Add test for recv(PEEK) spanning across 
> multiple records")
> 
> from the net-next 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.

The test from 50c6b58a814d supersedes the one from c2ad647c6442 so the
recv_peek_large_buf_mult_recs could be removed; latter was also not working
correctly due to this bug.

Thanks,
Daniel


[PATCH v2] misc: remove redundant include moduleparam.h

2018-09-18 Thread zhong jiang
module.h already contains moduleparam.h,  so it is safe to remove
the redundant include.

The issue is detected with the help of Coccinelle.

Signed-off-by: zhong jiang 
---
 drivers/misc/mei/bus-fixup.c  | 1 -
 drivers/misc/vmw_vmci/vmci_host.c | 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/misc/mei/bus-fixup.c b/drivers/misc/mei/bus-fixup.c
index a6f41f9..80215c3 100644
--- a/drivers/misc/mei/bus-fixup.c
+++ b/drivers/misc/mei/bus-fixup.c
@@ -17,7 +17,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/drivers/misc/vmw_vmci/vmci_host.c 
b/drivers/misc/vmw_vmci/vmci_host.c
index 83e0c95..be732e5 100644
--- a/drivers/misc/vmw_vmci/vmci_host.c
+++ b/drivers/misc/vmw_vmci/vmci_host.c
@@ -15,7 +15,6 @@
 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
-- 
1.7.12.4



[PATCH v3 18/20] tpm: use u32 instead of int for pcr index

2018-09-18 Thread Tomas Winkler
TPM pcr indices cannot be negative, also the tpm
commands accept u32 number as a pcr index.

1. Adjust the API to use u32 instead of int in all pcr related
functions.
2. Rename tpm1_pcr_read_dev to tpm1_pcr_read() to match
the counterpart tpm2_pcr_read()
3. Remove redundant constants in tpm1_pcr_extend() function.

Signed-off-by: Tomas Winkler 
---
V3: new in the series
 drivers/char/tpm/tpm-interface.c|  4 ++--
 drivers/char/tpm/tpm-sysfs.c|  4 ++--
 drivers/char/tpm/tpm.h  | 10 +-
 drivers/char/tpm/tpm1-cmd.c | 14 ++
 drivers/char/tpm/tpm2-cmd.c |  6 +++---
 include/linux/tpm.h |  2 +-
 security/integrity/ima/ima_crypto.c |  5 +++--
 7 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index e3206874be22..0eea784e1ae4 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -444,7 +444,7 @@ EXPORT_SYMBOL_GPL(tpm_is_tpm2);
  *
  * Return: same as with tpm_transmit_cmd()
  */
-int tpm_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
+int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf)
 {
int rc;
 
@@ -455,7 +455,7 @@ int tpm_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 
*res_buf)
if (chip->flags & TPM_CHIP_FLAG_TPM2)
rc = tpm2_pcr_read(chip, pcr_idx, res_buf);
else
-   rc = tpm1_pcr_read_dev(chip, pcr_idx, res_buf);
+   rc = tpm1_pcr_read(chip, pcr_idx, res_buf);
 
tpm_put_ops(chip);
return rc;
diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c
index 861acafd8f29..b88e08ec2c59 100644
--- a/drivers/char/tpm/tpm-sysfs.c
+++ b/drivers/char/tpm/tpm-sysfs.c
@@ -102,7 +102,7 @@ static ssize_t pcrs_show(struct device *dev, struct 
device_attribute *attr,
cap_t cap;
u8 digest[TPM_DIGEST_SIZE];
ssize_t rc;
-   int i, j, num_pcrs;
+   u32 i, j, num_pcrs;
char *str = buf;
struct tpm_chip *chip = to_tpm_chip(dev);
 
@@ -114,7 +114,7 @@ static ssize_t pcrs_show(struct device *dev, struct 
device_attribute *attr,
 
num_pcrs = be32_to_cpu(cap.num_pcrs);
for (i = 0; i < num_pcrs; i++) {
-   rc = tpm1_pcr_read_dev(chip, i, digest);
+   rc = tpm1_pcr_read(chip, i, digest);
if (rc)
break;
str += sprintf(str, "PCR-%02d: ", i);
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index d0402aa122ec..dbbfb7118c31 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -518,14 +518,14 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct 
tpm_space *space,
 int tpm_get_timeouts(struct tpm_chip *);
 int tpm_auto_startup(struct tpm_chip *chip);
 
-int tpm1_pm_suspend(struct tpm_chip *chip, int tpm_suspend_pcr);
+int tpm1_pm_suspend(struct tpm_chip *chip, u32 tpm_suspend_pcr);
 int tpm1_do_selftest(struct tpm_chip *chip);
 int tpm1_auto_startup(struct tpm_chip *chip);
 int tpm1_get_timeouts(struct tpm_chip *chip);
 unsigned long tpm1_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
-int tpm1_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash,
+int tpm1_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash,
const char *log_msg);
-int tpm1_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf);
+int tpm1_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf);
 ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
const char *desc, size_t min_cap_length);
 int tpm1_get_random(struct tpm_chip *chip, u8 *out, size_t max);
@@ -567,8 +567,8 @@ static inline u32 tpm2_rc_value(u32 rc)
 }
 
 int tpm2_get_timeouts(struct tpm_chip *chip);
-int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf);
-int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash);
+int tpm2_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf);
+int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash);
 int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max);
 void tpm2_flush_context_cmd(struct tpm_chip *chip, u32 handle,
unsigned int flags);
diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c
index e81641f9d0e3..777b1158e1b5 100644
--- a/drivers/char/tpm/tpm1-cmd.c
+++ b/drivers/char/tpm/tpm1-cmd.c
@@ -449,9 +449,7 @@ int tpm1_get_timeouts(struct tpm_chip *chip)
 }
 
 #define TPM_ORD_PCR_EXTEND 20
-#define EXTEND_PCR_RESULT_SIZE 34
-#define EXTEND_PCR_RESULT_BODY_SIZE 20
-int tpm1_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash,
+int tpm1_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash,
const char *log_msg)
 {
struct tpm_buf buf;
@@ -464,8 +462,8 @@ int tpm1_pcr_extend(struct tpm_chip *chip, int pcr_idx, 
const u8 *hash,

[PATCH v3 05/20] tpm: factor out tpm_get_timeouts

2018-09-18 Thread Tomas Winkler
Factor out tpm_get_timeouts into tpm2_get_timeouts
and tpm1_get_timeouts.

Signed-off-by: Tomas Winkler 
---
V2-V3: Rebase
 drivers/char/tpm/tpm-interface.c | 127 ++-
 drivers/char/tpm/tpm.h   |   5 +-
 drivers/char/tpm/tpm1-cmd.c  | 106 
 drivers/char/tpm/tpm2-cmd.c  |  22 +++
 4 files changed, 136 insertions(+), 124 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 7b460f646781..55f9094a8f11 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -492,132 +492,13 @@ EXPORT_SYMBOL_GPL(tpm_getcap);
 
 int tpm_get_timeouts(struct tpm_chip *chip)
 {
-   cap_t cap;
-   unsigned long timeout_old[4], timeout_chip[4], timeout_eff[4];
-   ssize_t rc;
-
if (chip->flags & TPM_CHIP_FLAG_HAVE_TIMEOUTS)
return 0;
 
-   if (chip->flags & TPM_CHIP_FLAG_TPM2) {
-   /* Fixed timeouts for TPM2 */
-   chip->timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A);
-   chip->timeout_b = msecs_to_jiffies(TPM2_TIMEOUT_B);
-   chip->timeout_c = msecs_to_jiffies(TPM2_TIMEOUT_C);
-   chip->timeout_d = msecs_to_jiffies(TPM2_TIMEOUT_D);
-   chip->duration[TPM_SHORT] =
-   msecs_to_jiffies(TPM2_DURATION_SHORT);
-   chip->duration[TPM_MEDIUM] =
-   msecs_to_jiffies(TPM2_DURATION_MEDIUM);
-   chip->duration[TPM_LONG] =
-   msecs_to_jiffies(TPM2_DURATION_LONG);
-   chip->duration[TPM_LONG_LONG] =
-   msecs_to_jiffies(TPM2_DURATION_LONG_LONG);
-
-   chip->flags |= TPM_CHIP_FLAG_HAVE_TIMEOUTS;
-   return 0;
-   }
-
-   rc = tpm_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, , NULL,
-   sizeof(cap.timeout));
-   if (rc == TPM_ERR_INVALID_POSTINIT) {
-   if (tpm_startup(chip))
-   return rc;
-
-   rc = tpm_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, ,
-   "attempting to determine the timeouts",
-   sizeof(cap.timeout));
-   }
-
-   if (rc) {
-   dev_err(>dev,
-   "A TPM error (%zd) occurred attempting to determine the 
timeouts\n",
-   rc);
-   return rc;
-   }
-
-   timeout_old[0] = jiffies_to_usecs(chip->timeout_a);
-   timeout_old[1] = jiffies_to_usecs(chip->timeout_b);
-   timeout_old[2] = jiffies_to_usecs(chip->timeout_c);
-   timeout_old[3] = jiffies_to_usecs(chip->timeout_d);
-   timeout_chip[0] = be32_to_cpu(cap.timeout.a);
-   timeout_chip[1] = be32_to_cpu(cap.timeout.b);
-   timeout_chip[2] = be32_to_cpu(cap.timeout.c);
-   timeout_chip[3] = be32_to_cpu(cap.timeout.d);
-   memcpy(timeout_eff, timeout_chip, sizeof(timeout_eff));
-
-   /*
-* Provide ability for vendor overrides of timeout values in case
-* of misreporting.
-*/
-   if (chip->ops->update_timeouts != NULL)
-   chip->timeout_adjusted =
-   chip->ops->update_timeouts(chip, timeout_eff);
-
-   if (!chip->timeout_adjusted) {
-   /* Restore default if chip reported 0 */
-   int i;
-
-   for (i = 0; i < ARRAY_SIZE(timeout_eff); i++) {
-   if (timeout_eff[i])
-   continue;
-
-   timeout_eff[i] = timeout_old[i];
-   chip->timeout_adjusted = true;
-   }
-
-   if (timeout_eff[0] != 0 && timeout_eff[0] < 1000) {
-   /* timeouts in msec rather usec */
-   for (i = 0; i != ARRAY_SIZE(timeout_eff); i++)
-   timeout_eff[i] *= 1000;
-   chip->timeout_adjusted = true;
-   }
-   }
-
-   /* Report adjusted timeouts */
-   if (chip->timeout_adjusted) {
-   dev_info(>dev,
-HW_ERR "Adjusting reported timeouts: A %lu->%luus B 
%lu->%luus C %lu->%luus D %lu->%luus\n",
-timeout_chip[0], timeout_eff[0],
-timeout_chip[1], timeout_eff[1],
-timeout_chip[2], timeout_eff[2],
-timeout_chip[3], timeout_eff[3]);
-   }
-
-   chip->timeout_a = usecs_to_jiffies(timeout_eff[0]);
-   chip->timeout_b = usecs_to_jiffies(timeout_eff[1]);
-   chip->timeout_c = usecs_to_jiffies(timeout_eff[2]);
-   chip->timeout_d = usecs_to_jiffies(timeout_eff[3]);
-
-   rc = tpm_getcap(chip, TPM_CAP_PROP_TIS_DURATION, ,
-   "attempting to determine the durations",
-   sizeof(cap.duration));
-   if (rc)
-   return rc;
-
-   chip->duration[TPM_SHORT] =
-   

[PATCH v3 20/20] tpm1: reimplement tpm1_continue_selftest() using tpm_buf

2018-09-18 Thread Tomas Winkler
Reimplement tpm1_continue_selftest() using tpm_buf structure.
This is the last command using the old tpm_cmd_t structure
and now the structure can be removed.

Signed-off-by: Tomas Winkler 
---
V3: new in the series
 drivers/char/tpm/tpm.h  |  9 -
 drivers/char/tpm/tpm1-cmd.c | 16 
 2 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index dbbfb7118c31..5d018f61b812 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -377,15 +377,6 @@ enum tpm_sub_capabilities {
TPM_CAP_PROP_TIS_DURATION = 0x120,
 };
 
-typedef union {
-   struct  tpm_input_header in;
-   struct  tpm_output_header out;
-} tpm_cmd_header;
-
-struct tpm_cmd_t {
-   tpm_cmd_header  header;
-} __packed;
-
 
 /* 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - 18
  * bytes, but 128 is still a relatively large number of random bytes and
diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c
index c4a0bacb1378..f30d2801c2e0 100644
--- a/drivers/char/tpm/tpm1-cmd.c
+++ b/drivers/char/tpm/tpm1-cmd.c
@@ -604,11 +604,6 @@ int tpm1_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 
*res_buf)
 
 #define TPM_ORD_CONTINUE_SELFTEST 83
 #define CONTINUE_SELFTEST_RESULT_SIZE 10
-static const struct tpm_input_header continue_selftest_header = {
-   .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
-   .length = cpu_to_be32(10),
-   .ordinal = cpu_to_be32(TPM_ORD_CONTINUE_SELFTEST),
-};
 
 /**
  * tpm_continue_selftest -- run TPM's selftest
@@ -619,12 +614,17 @@ static const struct tpm_input_header 
continue_selftest_header = {
  */
 static int tpm1_continue_selftest(struct tpm_chip *chip)
 {
+   struct tpm_buf buf;
int rc;
-   struct tpm_cmd_t cmd;
 
-   cmd.header.in = continue_selftest_header;
-   rc = tpm_transmit_cmd(chip, NULL, , CONTINUE_SELFTEST_RESULT_SIZE,
+   rc = tpm_buf_init(, TPM_TAG_RQU_COMMAND, TPM_ORD_CONTINUE_SELFTEST);
+   if (rc)
+   return rc;
+   rc = tpm_transmit_cmd(chip, NULL, , PAGE_SIZE,
  0, 0, "continue selftest");
+
+   tpm_buf_destroy();
+
return rc;
 }
 
-- 
2.14.4



[PATCH v3 09/20] tpm: move tpm1 selftest code from tpm-interface tpm1-cmd.c

2018-09-18 Thread Tomas Winkler
Move the tpm1 selftest code functions to tpm1-cmd.c
and adjust callers to use the new function names.
 1. tpm_pcr_read_dev to tpm1_pcr_read_dev
 2. tpm_continue_selftest to tpm1_continue_selftest
 3. tpm_do_selftest to tpm1_do_selftest

Signed-off-by: Tomas Winkler 
---
V2-V3: Rebase

 drivers/char/tpm/st33zp24/st33zp24.c |   2 +-
 drivers/char/tpm/tpm-interface.c | 148 +--
 drivers/char/tpm/tpm-sysfs.c |   2 +-
 drivers/char/tpm/tpm.h   |   4 +-
 drivers/char/tpm/tpm1-cmd.c  | 142 +
 drivers/char/tpm/tpm_tis_core.c  |   2 +-
 6 files changed, 150 insertions(+), 150 deletions(-)

diff --git a/drivers/char/tpm/st33zp24/st33zp24.c 
b/drivers/char/tpm/st33zp24/st33zp24.c
index abd675bec88c..64dc560859f2 100644
--- a/drivers/char/tpm/st33zp24/st33zp24.c
+++ b/drivers/char/tpm/st33zp24/st33zp24.c
@@ -649,7 +649,7 @@ int st33zp24_pm_resume(struct device *dev)
} else {
ret = tpm_pm_resume(dev);
if (!ret)
-   tpm_do_selftest(chip);
+   tpm1_do_selftest(chip);
}
return ret;
 } /* st33zp24_pm_resume() */
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index c15957fef08f..8396cf6735ec 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -456,59 +456,6 @@ int tpm_get_timeouts(struct tpm_chip *chip)
 }
 EXPORT_SYMBOL_GPL(tpm_get_timeouts);
 
-#define TPM_ORD_CONTINUE_SELFTEST 83
-#define CONTINUE_SELFTEST_RESULT_SIZE 10
-
-static const struct tpm_input_header continue_selftest_header = {
-   .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
-   .length = cpu_to_be32(10),
-   .ordinal = cpu_to_be32(TPM_ORD_CONTINUE_SELFTEST),
-};
-
-/**
- * tpm_continue_selftest -- run TPM's selftest
- * @chip: TPM chip to use
- *
- * Returns 0 on success, < 0 in case of fatal error or a value > 0 representing
- * a TPM error code.
- */
-static int tpm_continue_selftest(struct tpm_chip *chip)
-{
-   int rc;
-   struct tpm_cmd_t cmd;
-
-   cmd.header.in = continue_selftest_header;
-   rc = tpm_transmit_cmd(chip, NULL, , CONTINUE_SELFTEST_RESULT_SIZE,
- 0, 0, "continue selftest");
-   return rc;
-}
-
-#define TPM_ORDINAL_PCRREAD 21
-#define READ_PCR_RESULT_SIZE 30
-#define READ_PCR_RESULT_BODY_SIZE 20
-static const struct tpm_input_header pcrread_header = {
-   .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
-   .length = cpu_to_be32(14),
-   .ordinal = cpu_to_be32(TPM_ORDINAL_PCRREAD)
-};
-
-int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
-{
-   int rc;
-   struct tpm_cmd_t cmd;
-
-   cmd.header.in = pcrread_header;
-   cmd.params.pcrread_in.pcr_idx = cpu_to_be32(pcr_idx);
-   rc = tpm_transmit_cmd(chip, NULL, , READ_PCR_RESULT_SIZE,
- READ_PCR_RESULT_BODY_SIZE, 0,
- "attempting to read a pcr value");
-
-   if (rc == 0)
-   memcpy(res_buf, cmd.params.pcrread_out.pcr_result,
-  TPM_DIGEST_SIZE);
-   return rc;
-}
-
 /**
  * tpm_is_tpm2 - do we a have a TPM2 chip?
  * @chip:  a  tpm_chip instance, %NULL for the default chip
@@ -549,10 +496,12 @@ int tpm_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 
*res_buf)
chip = tpm_find_get_ops(chip);
if (!chip)
return -ENODEV;
+
if (chip->flags & TPM_CHIP_FLAG_TPM2)
rc = tpm2_pcr_read(chip, pcr_idx, res_buf);
else
-   rc = tpm_pcr_read_dev(chip, pcr_idx, res_buf);
+   rc = tpm1_pcr_read_dev(chip, pcr_idx, res_buf);
+
tpm_put_ops(chip);
return rc;
 }
@@ -603,97 +552,6 @@ int tpm_pcr_extend(struct tpm_chip *chip, int pcr_idx, 
const u8 *hash)
 }
 EXPORT_SYMBOL_GPL(tpm_pcr_extend);
 
-/**
- * tpm_do_selftest - have the TPM continue its selftest and wait until it
- *   can receive further commands
- * @chip: TPM chip to use
- *
- * Returns 0 on success, < 0 in case of fatal error or a value > 0 representing
- * a TPM error code.
- */
-int tpm_do_selftest(struct tpm_chip *chip)
-{
-   int rc;
-   unsigned int loops;
-   unsigned int delay_msec = 100;
-   unsigned long duration;
-   u8 dummy[TPM_DIGEST_SIZE];
-
-   duration = tpm1_calc_ordinal_duration(chip, TPM_ORD_CONTINUE_SELFTEST);
-
-   loops = jiffies_to_msecs(duration) / delay_msec;
-
-   rc = tpm_continue_selftest(chip);
-   if (rc == TPM_ERR_INVALID_POSTINIT) {
-   chip->flags |= TPM_CHIP_FLAG_ALWAYS_POWERED;
-   dev_info(>dev, "TPM not ready (%d)\n", rc);
-   }
-   /* This may fail if there was no TPM driver during a suspend/resume
-* cycle; some may return 10 (BAD_ORDINAL), others 28 (FAILEDSELFTEST)
-*/
-   if (rc)
-   return rc;
-
-   do {
-   /* Attempt 

[PATCH v3 03/20] tpm: factor out tpm 1.x duration calculation to tpm1-cmd.c

2018-09-18 Thread Tomas Winkler
Factor out tpm 1.x commands calculation into tpm1-cmd.c file.
and change the prefix from tpm_ to tpm1_.
No functional change is done here.

Signed-off-by: Tomas Winkler 
---
V2-V3: Rebase
 drivers/char/tpm/Makefile|   1 +
 drivers/char/tpm/st33zp24/st33zp24.c |   2 +-
 drivers/char/tpm/tpm-interface.c | 284 +---
 drivers/char/tpm/tpm.h   |   2 +-
 drivers/char/tpm/tpm1-cmd.c  | 310 +++
 drivers/char/tpm/tpm_i2c_nuvoton.c   |  10 +-
 drivers/char/tpm/tpm_tis_core.c  |   2 +-
 drivers/char/tpm/xen-tpmfront.c  |   2 +-
 8 files changed, 322 insertions(+), 291 deletions(-)
 create mode 100644 drivers/char/tpm/tpm1-cmd.c

diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
index efc785053627..a01c4cab902a 100644
--- a/drivers/char/tpm/Makefile
+++ b/drivers/char/tpm/Makefile
@@ -7,6 +7,7 @@ tpm-y := tpm-chip.o
 tpm-y += tpm-dev-common.o
 tpm-y += tpm-dev.o
 tpm-y += tpm-interface.o
+tpm-y += tpm1-cmd.o
 tpm-y += tpm2-cmd.o
 tpm-y += tpmrm-dev.o
 tpm-y += tpm2-space.o
diff --git a/drivers/char/tpm/st33zp24/st33zp24.c 
b/drivers/char/tpm/st33zp24/st33zp24.c
index abd675bec88c..16be974955ea 100644
--- a/drivers/char/tpm/st33zp24/st33zp24.c
+++ b/drivers/char/tpm/st33zp24/st33zp24.c
@@ -430,7 +430,7 @@ static int st33zp24_send(struct tpm_chip *chip, unsigned 
char *buf,
ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
 
ret = wait_for_stat(chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID,
-   tpm_calc_ordinal_duration(chip, ordinal),
+   tpm1_calc_ordinal_duration(chip, ordinal),
_dev->read_queue, false);
if (ret < 0)
goto out_err;
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 129f640424b7..bb3eed907c72 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -33,7 +33,6 @@
 
 #include "tpm.h"
 
-#define TPM_MAX_ORDINAL 243
 #define TSC_MAX_ORDINAL 12
 #define TPM_PROTECTED_COMMAND 0x00
 #define TPM_CONNECTION_COMMAND 0x40
@@ -48,285 +47,6 @@ module_param_named(suspend_pcr, tpm_suspend_pcr, uint, 
0644);
 MODULE_PARM_DESC(suspend_pcr,
 "PCR to use for dummy writes to facilitate flush on suspend.");
 
-/*
- * Array with one entry per ordinal defining the maximum amount
- * of time the chip could take to return the result.  The ordinal
- * designation of short, medium or long is defined in a table in
- * TCG Specification TPM Main Part 2 TPM Structures Section 17. The
- * values of the SHORT, MEDIUM, and LONG durations are retrieved
- * from the chip during initialization with a call to tpm_get_timeouts.
- */
-static const u8 tpm_ordinal_duration[TPM_MAX_ORDINAL] = {
-   TPM_UNDEFINED,  /* 0 */
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,  /* 5 */
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_SHORT,  /* 10 */
-   TPM_SHORT,
-   TPM_MEDIUM,
-   TPM_LONG,
-   TPM_LONG,
-   TPM_MEDIUM, /* 15 */
-   TPM_SHORT,
-   TPM_SHORT,
-   TPM_MEDIUM,
-   TPM_LONG,
-   TPM_SHORT,  /* 20 */
-   TPM_SHORT,
-   TPM_MEDIUM,
-   TPM_MEDIUM,
-   TPM_MEDIUM,
-   TPM_SHORT,  /* 25 */
-   TPM_SHORT,
-   TPM_MEDIUM,
-   TPM_SHORT,
-   TPM_SHORT,
-   TPM_MEDIUM, /* 30 */
-   TPM_LONG,
-   TPM_MEDIUM,
-   TPM_SHORT,
-   TPM_SHORT,
-   TPM_SHORT,  /* 35 */
-   TPM_MEDIUM,
-   TPM_MEDIUM,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_MEDIUM, /* 40 */
-   TPM_LONG,
-   TPM_MEDIUM,
-   TPM_SHORT,
-   TPM_SHORT,
-   TPM_SHORT,  /* 45 */
-   TPM_SHORT,
-   TPM_SHORT,
-   TPM_SHORT,
-   TPM_LONG,
-   TPM_MEDIUM, /* 50 */
-   TPM_MEDIUM,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,  /* 55 */
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_MEDIUM, /* 60 */
-   TPM_MEDIUM,
-   TPM_MEDIUM,
-   TPM_SHORT,
-   TPM_SHORT,
-   TPM_MEDIUM, /* 65 */
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_SHORT,  /* 70 */
-   TPM_SHORT,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,  /* 75 */
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_UNDEFINED,
-   TPM_LONG,   /* 80 */
-   TPM_UNDEFINED,
-   TPM_MEDIUM,
-   TPM_LONG,
-   TPM_SHORT,
-   TPM_UNDEFINED,

[PATCH v3 02/20] tpm: sort objects in the Makefile

2018-09-18 Thread Tomas Winkler
Make the tpm Makefile a bit more in order by putting
objects in one column and group together tpm2 modules

Signed-off-by: Tomas Winkler 
---
V2: 1. back to tpm-y notation
2. Partially sort files alphanumerically.
V3: Rebase

 drivers/char/tpm/Makefile | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
index 4e9c33ca1f8f..efc785053627 100644
--- a/drivers/char/tpm/Makefile
+++ b/drivers/char/tpm/Makefile
@@ -3,9 +3,18 @@
 # Makefile for the kernel tpm device drivers.
 #
 obj-$(CONFIG_TCG_TPM) += tpm.o
-tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-cmd.o \
-tpm-dev-common.o tpmrm-dev.o eventlog/common.o eventlog/tpm1.o \
-eventlog/tpm2.o tpm2-space.o
+tpm-y := tpm-chip.o
+tpm-y += tpm-dev-common.o
+tpm-y += tpm-dev.o
+tpm-y += tpm-interface.o
+tpm-y += tpm2-cmd.o
+tpm-y += tpmrm-dev.o
+tpm-y += tpm2-space.o
+tpm-y += tpm-sysfs.o
+tpm-y += eventlog/common.o
+tpm-y += eventlog/tpm1.o
+tpm-y += eventlog/tpm2.o
+
 tpm-$(CONFIG_ACPI) += tpm_ppi.o eventlog/acpi.o
 tpm-$(CONFIG_EFI) += eventlog/efi.o
 tpm-$(CONFIG_OF) += eventlog/of.o
-- 
2.14.4



[PATCH v3 16/20] tpm: tpm1: rewrite tpm1_get_random() using tpm_buf structure

2018-09-18 Thread Tomas Winkler
1. Use tpm_buf in tpm1_get_random()
2. Fix comment in tpm_get_random() so it is clear that
the function is expected to return number of random bytes.

Signed-off-by: Tomas Winkler 
---
V3: new in the series
 drivers/char/tpm/tpm-interface.c |  2 +-
 drivers/char/tpm/tpm.h   | 11 --
 drivers/char/tpm/tpm1-cmd.c  | 85 +++-
 3 files changed, 50 insertions(+), 48 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 358ef5bd601e..e3206874be22 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -576,7 +576,7 @@ EXPORT_SYMBOL_GPL(tpm_pm_resume);
  * @out:   destination buffer for the random bytes
  * @max:   the max number of bytes to write to @out
  *
- * Return: same as with tpm_transmit_cmd()
+ * Return: number of random bytes read or a negative error value.
  */
 int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max)
 {
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 4ccffbb56864..d6eca81a011a 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -396,20 +396,9 @@ struct tpm_pcrread_in {
  * compiler warnings about stack frame size. */
 #define TPM_MAX_RNG_DATA   128
 
-struct tpm_getrandom_out {
-   __be32 rng_data_len;
-   u8 rng_data[TPM_MAX_RNG_DATA];
-} __packed;
-
-struct tpm_getrandom_in {
-   __be32 num_bytes;
-} __packed;
-
 typedef union {
struct  tpm_pcrread_in  pcrread_in;
struct  tpm_pcrread_out pcrread_out;
-   struct  tpm_getrandom_in getrandom_in;
-   struct  tpm_getrandom_out getrandom_out;
 } tpm_cmd_params;
 
 struct tpm_cmd_t {
diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c
index 90e5bc1720ad..5708d4bf908f 100644
--- a/drivers/char/tpm/tpm1-cmd.c
+++ b/drivers/char/tpm/tpm1-cmd.c
@@ -507,58 +507,71 @@ ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, 
cap_t *cap,
 EXPORT_SYMBOL_GPL(tpm1_getcap);
 
 #define TPM_ORD_GET_RANDOM 70
-#define TPM_GETRANDOM_RESULT_SIZE  18
-static const struct tpm_input_header tpm_getrandom_header = {
-   .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
-   .length = cpu_to_be32(14),
-   .ordinal = cpu_to_be32(TPM_ORD_GET_RANDOM)
-};
+struct tpm1_get_random_out {
+   __be32 rng_data_len;
+   u8 rng_data[TPM_MAX_RNG_DATA];
+} __packed;
 
-int tpm1_get_random(struct tpm_chip *chip, u8 *out, size_t max)
+/**
+ * tpm1_get_random() - get random bytes from the TPM's RNG
+ *
+ * @chip:  a  tpm_chip instance
+ * @dest:  destination buffer for the random bytes
+ * @max:   the maximum number of bytes to write to @dest
+ *
+ * Return:
+ *   number of bytes read
+ *   -errno or a TPM return code otherwise
+ */
+int tpm1_get_random(struct tpm_chip *chip, u8 *dest, size_t max)
 {
-   struct tpm_cmd_t tpm_cmd;
+   struct tpm1_get_random_out *out;
+   u32 num_bytes =  min_t(u32, max, TPM_MAX_RNG_DATA);
+   struct tpm_buf buf;
+   u32 total = 0;
+   int retries = 5;
u32 recd;
-   u32 num_bytes = min_t(u32, max, TPM_MAX_RNG_DATA);
-   u32 rlength;
-   int err, total = 0, retries = 5;
-   u8 *dest = out;
+   int rc;
 
-   if (!out || !num_bytes || max > TPM_MAX_RNG_DATA)
-   return -EINVAL;
+   rc = tpm_buf_init(, TPM_TAG_RQU_COMMAND, TPM_ORD_GET_RANDOM);
+   if (rc)
+   return rc;
 
do {
-   tpm_cmd.header.in = tpm_getrandom_header;
-   tpm_cmd.params.getrandom_in.num_bytes = cpu_to_be32(num_bytes);
-
-   err = tpm_transmit_cmd(chip, NULL, _cmd,
-  TPM_GETRANDOM_RESULT_SIZE + num_bytes,
-  offsetof(struct tpm_getrandom_out,
-   rng_data),
-  0, "attempting get random");
-   if (err)
-   break;
+   tpm_buf_append_u32(, num_bytes);
+
+   rc = tpm_transmit_cmd(chip, NULL, buf.data, PAGE_SIZE,
+ sizeof(out->rng_data_len), 0,
+ "attempting get random");
+   if (rc)
+   goto out;
 
-   recd = be32_to_cpu(tpm_cmd.params.getrandom_out.rng_data_len);
+   out = (struct tpm1_get_random_out *)[TPM_HEADER_SIZE];
+
+   recd = be32_to_cpu(out->rng_data_len);
if (recd > num_bytes) {
-   total = -EFAULT;
-   break;
+   rc = -EFAULT;
+   goto out;
}
 
-   rlength = be32_to_cpu(tpm_cmd.header.out.length);
-   if (rlength < TPM_HEADER_SIZE +
- offsetof(struct tpm_getrandom_out, rng_data) +
- recd) {
-   total = -EFAULT;
- 

[PATCH v3 15/20] tpm: tpm-space.c remove unneeded semicolon

2018-09-18 Thread Tomas Winkler
Remove unneeded semicolon in tpm2_map_response_header()

Signed-off-by: Tomas Winkler 
---
V3: new in the series
 drivers/char/tpm/tpm2-space.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c
index d2e101b32482..dcdfde3c253e 100644
--- a/drivers/char/tpm/tpm2-space.c
+++ b/drivers/char/tpm/tpm2-space.c
@@ -373,7 +373,7 @@ static int tpm2_map_response_header(struct tpm_chip *chip, 
u32 cc, u8 *rsp,
dev_err(>dev, "%s: unknown handle 0x%08X\n",
__func__, phandle);
break;
-   };
+   }
 
return 0;
 out_no_slots:
-- 
2.14.4



[PATCH v3 01/20] tpm2: add new tpm2 commands according to TCG 1.36

2018-09-18 Thread Tomas Winkler
1. TPM2_CC_LAST has moved from 182 to 193
2. Convert tpm2_ordinal_duration from an array into a switch statement,
   as there are not so many commands that require special duration
   relative to a number of commands.

Signed-off-by: Tomas Winkler 
---
V2-V3: Rebase.
 drivers/char/tpm/tpm.h  |  41 +
 drivers/char/tpm/tpm2-cmd.c | 196 +++-
 2 files changed, 93 insertions(+), 144 deletions(-)

diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index f20dc8ece348..0f08518b525d 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -134,22 +134,31 @@ enum tpm2_algorithms {
 };
 
 enum tpm2_command_codes {
-   TPM2_CC_FIRST   = 0x011F,
-   TPM2_CC_CREATE_PRIMARY  = 0x0131,
-   TPM2_CC_SELF_TEST   = 0x0143,
-   TPM2_CC_STARTUP = 0x0144,
-   TPM2_CC_SHUTDOWN= 0x0145,
-   TPM2_CC_CREATE  = 0x0153,
-   TPM2_CC_LOAD= 0x0157,
-   TPM2_CC_UNSEAL  = 0x015E,
-   TPM2_CC_CONTEXT_LOAD= 0x0161,
-   TPM2_CC_CONTEXT_SAVE= 0x0162,
-   TPM2_CC_FLUSH_CONTEXT   = 0x0165,
-   TPM2_CC_GET_CAPABILITY  = 0x017A,
-   TPM2_CC_GET_RANDOM  = 0x017B,
-   TPM2_CC_PCR_READ= 0x017E,
-   TPM2_CC_PCR_EXTEND  = 0x0182,
-   TPM2_CC_LAST= 0x018F,
+   TPM2_CC_FIRST   = 0x011F,
+   TPM2_CC_HIERARCHY_CONTROL   = 0x0121,
+   TPM2_CC_HIERARCHY_CHANGE_AUTH   = 0x0129,
+   TPM2_CC_CREATE_PRIMARY  = 0x0131,
+   TPM2_CC_SEQUENCE_COMPLETE   = 0x013E,
+   TPM2_CC_SELF_TEST   = 0x0143,
+   TPM2_CC_STARTUP = 0x0144,
+   TPM2_CC_SHUTDOWN= 0x0145,
+   TPM2_CC_NV_READ = 0x014E,
+   TPM2_CC_CREATE  = 0x0153,
+   TPM2_CC_LOAD= 0x0157,
+   TPM2_CC_SEQUENCE_UPDATE = 0x015C,
+   TPM2_CC_UNSEAL  = 0x015E,
+   TPM2_CC_CONTEXT_LOAD= 0x0161,
+   TPM2_CC_CONTEXT_SAVE= 0x0162,
+   TPM2_CC_FLUSH_CONTEXT   = 0x0165,
+   TPM2_CC_VERIFY_SIGNATURE= 0x0177,
+   TPM2_CC_GET_CAPABILITY  = 0x017A,
+   TPM2_CC_GET_RANDOM  = 0x017B,
+   TPM2_CC_PCR_READ= 0x017E,
+   TPM2_CC_PCR_EXTEND  = 0x0182,
+   TPM2_CC_EVENT_SEQUENCE_COMPLETE = 0x0185,
+   TPM2_CC_HASH_SEQUENCE_START = 0x0186,
+   TPM2_CC_CREATE_LOADED   = 0x0191,
+   TPM2_CC_LAST= 0x0193, /* Spec 1.36 */
 };
 
 enum tpm2_permanent_handles {
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 3acf4fd4e5a5..9c3c5c0628d9 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -41,128 +41,73 @@ static struct tpm2_hash tpm2_hash_map[] = {
 };
 
 /*
- * Array with one entry per ordinal defining the maximum amount
+ * tpm2_ordinal_duration returns the maximum amount
  * of time the chip could take to return the result. The values
- * of the SHORT, MEDIUM, and LONG durations are taken from the
- * PC Client Profile (PTP) specification.
+ * of the MEDIUM, and LONG durations are taken from the
+ * PC Client Profile (PTP) specification (750, 2000 msec)
+ *
  * LONG_LONG is for commands that generates keys which empirically
  * takes longer time on some systems.
  */
-static const u8 tpm2_ordinal_duration[TPM2_CC_LAST - TPM2_CC_FIRST + 1] = {
-   TPM_UNDEFINED,  /* 11F */
-   TPM_UNDEFINED,  /* 120 */
-   TPM_LONG,   /* 121 */
-   TPM_UNDEFINED,  /* 122 */
-   TPM_UNDEFINED,  /* 123 */
-   TPM_UNDEFINED,  /* 124 */
-   TPM_UNDEFINED,  /* 125 */
-   TPM_UNDEFINED,  /* 126 */
-   TPM_UNDEFINED,  /* 127 */
-   TPM_UNDEFINED,  /* 128 */
-   TPM_LONG,   /* 129 */
-   TPM_UNDEFINED,  /* 12a */
-   TPM_UNDEFINED,  /* 12b */
-   TPM_UNDEFINED,  /* 12c */
-   TPM_UNDEFINED,  /* 12d */
-   TPM_UNDEFINED,  /* 12e */
-   TPM_UNDEFINED,  /* 12f */
-   TPM_UNDEFINED,  /* 130 */
-   TPM_LONG_LONG,  /* 131 */
-   TPM_UNDEFINED,  /* 132 */
-   TPM_UNDEFINED,  /* 133 */
-   TPM_UNDEFINED,  /* 134 */
-   TPM_UNDEFINED,  /* 135 */
-   TPM_UNDEFINED,  /* 136 */
-   TPM_UNDEFINED,  /* 137 */
-   TPM_UNDEFINED,  /* 138 */
-   TPM_UNDEFINED,  /* 139 */
-   TPM_UNDEFINED,  /* 13a */
-   TPM_UNDEFINED,  /* 13b */
-   TPM_UNDEFINED,  /* 13c */
-   TPM_UNDEFINED,  /* 13d */
-   TPM_MEDIUM, /* 13e */
-   TPM_UNDEFINED,  /* 13f */
-   TPM_UNDEFINED,  /* 140 */
-   TPM_UNDEFINED,  /* 141 */
-   

[PATCH v3 19/20] tpm1: reimplement SAVESTATE using tpm_buf

2018-09-18 Thread Tomas Winkler
In tpm1_pm_suspend() function reimplement,
TPM_ORD_SAVESTATE comamnd using tpm_buf.

Signed-off-by: Tomas Winkler 
---
V3: new in the series

 drivers/char/tpm/tpm1-cmd.c | 22 --
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c
index 777b1158e1b5..c4a0bacb1378 100644
--- a/drivers/char/tpm/tpm1-cmd.c
+++ b/drivers/char/tpm/tpm1-cmd.c
@@ -719,12 +719,6 @@ int tpm1_auto_startup(struct tpm_chip *chip)
 }
 
 #define TPM_ORD_SAVESTATE 152
-#define SAVESTATE_RESULT_SIZE 10
-static const struct tpm_input_header savestate_header = {
-   .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
-   .length = cpu_to_be32(10),
-   .ordinal = cpu_to_be32(TPM_ORD_SAVESTATE)
-};
 
 /*
  * We are about to suspend. Save the TPM state
@@ -733,18 +727,22 @@ static const struct tpm_input_header savestate_header = {
 int tpm1_pm_suspend(struct tpm_chip *chip, u32 tpm_suspend_pcr)
 {
u8 dummy_hash[TPM_DIGEST_SIZE] = { 0 };
-   struct tpm_cmd_t cmd;
-   int rc, try;
+   struct tpm_buf buf;
+   unsigned int try;
+   int rc;
+
 
/* for buggy tpm, flush pcrs with extend to selected dummy */
if (tpm_suspend_pcr)
rc = tpm1_pcr_extend(chip, tpm_suspend_pcr, dummy_hash,
 "extending dummy pcr before suspend");
 
+   rc = tpm_buf_init(, TPM_TAG_RQU_COMMAND, TPM_ORD_SAVESTATE);
+   if (rc)
+   return rc;
/* now do the actual savestate */
for (try = 0; try < TPM_RETRY; try++) {
-   cmd.header.in = savestate_header;
-   rc = tpm_transmit_cmd(chip, NULL, , SAVESTATE_RESULT_SIZE,
+   rc = tpm_transmit_cmd(chip, NULL, buf.data, PAGE_SIZE,
  0, 0, NULL);
 
/*
@@ -760,6 +758,8 @@ int tpm1_pm_suspend(struct tpm_chip *chip, u32 
tpm_suspend_pcr)
if (rc != TPM_WARN_RETRY)
break;
tpm_msleep(TPM_TIMEOUT_RETRY);
+
+   tpm_buf_reset(, TPM_TAG_RQU_COMMAND, TPM_ORD_SAVESTATE);
}
 
if (rc)
@@ -769,6 +769,8 @@ int tpm1_pm_suspend(struct tpm_chip *chip, u32 
tpm_suspend_pcr)
dev_warn(>dev, "TPM savestate took %dms\n",
 try * TPM_TIMEOUT_RETRY);
 
+   tpm_buf_destroy();
+
return rc;
 }
 
-- 
2.14.4



[PATCH v3 17/20] tpm1: implement tpm1_pcr_read_dev() using tpm_buf structure

2018-09-18 Thread Tomas Winkler
Implement tpm1_pcr_read_dev() using tpm_buf and remove
now unneeded structures from tpm.h

Signed-off-by: Tomas Winkler 
---
V3: new in the series
 drivers/char/tpm/tpm.h  | 18 ++
 drivers/char/tpm/tpm1-cmd.c | 38 +-
 2 files changed, 23 insertions(+), 33 deletions(-)

diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index d6eca81a011a..d0402aa122ec 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -382,13 +382,10 @@ typedef union {
struct  tpm_output_header out;
 } tpm_cmd_header;
 
-struct tpm_pcrread_out {
-   u8  pcr_result[TPM_DIGEST_SIZE];
+struct tpm_cmd_t {
+   tpm_cmd_header  header;
 } __packed;
 
-struct tpm_pcrread_in {
-   __be32  pcr_idx;
-} __packed;
 
 /* 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - 18
  * bytes, but 128 is still a relatively large number of random bytes and
@@ -396,17 +393,6 @@ struct tpm_pcrread_in {
  * compiler warnings about stack frame size. */
 #define TPM_MAX_RNG_DATA   128
 
-typedef union {
-   struct  tpm_pcrread_in  pcrread_in;
-   struct  tpm_pcrread_out pcrread_out;
-} tpm_cmd_params;
-
-struct tpm_cmd_t {
-   tpm_cmd_header  header;
-   tpm_cmd_params  params;
-} __packed;
-
-
 /* A string buffer type for constructing TPM commands. This is based on the
  * ideas of string buffer code in security/keys/trusted.h but is heap based
  * in order to keep the stack usage minimal.
diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c
index 5708d4bf908f..e81641f9d0e3 100644
--- a/drivers/char/tpm/tpm1-cmd.c
+++ b/drivers/char/tpm/tpm1-cmd.c
@@ -574,29 +574,33 @@ int tpm1_get_random(struct tpm_chip *chip, u8 *dest, 
size_t max)
return rc;
 }
 
-#define TPM_ORDINAL_PCRREAD 21
-#define READ_PCR_RESULT_SIZE 30
-#define READ_PCR_RESULT_BODY_SIZE 20
-static const struct tpm_input_header pcrread_header = {
-   .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
-   .length = cpu_to_be32(14),
-   .ordinal = cpu_to_be32(TPM_ORDINAL_PCRREAD)
-};
-
+#define TPM_ORD_PCRREAD 21
 int tpm1_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
 {
+   struct tpm_buf buf;
int rc;
-   struct tpm_cmd_t cmd;
 
-   cmd.header.in = pcrread_header;
-   cmd.params.pcrread_in.pcr_idx = cpu_to_be32(pcr_idx);
-   rc = tpm_transmit_cmd(chip, NULL, , READ_PCR_RESULT_SIZE,
- READ_PCR_RESULT_BODY_SIZE, 0,
+   rc = tpm_buf_init(, TPM_TAG_RQU_COMMAND, TPM_ORD_PCRREAD);
+   if (rc)
+   return rc;
+
+   tpm_buf_append_u32(, pcr_idx);
+
+   rc = tpm_transmit_cmd(chip, NULL, buf.data, PAGE_SIZE,
+ TPM_DIGEST_SIZE, 0,
  "attempting to read a pcr value");
+   if (rc)
+   goto out;
 
-   if (rc == 0)
-   memcpy(res_buf, cmd.params.pcrread_out.pcr_result,
-  TPM_DIGEST_SIZE);
+   if (tpm_buf_length() < TPM_DIGEST_SIZE) {
+   rc = -EFAULT;
+   goto out;
+   }
+
+   memcpy(res_buf, [TPM_HEADER_SIZE], TPM_DIGEST_SIZE);
+
+out:
+   tpm_buf_destroy();
return rc;
 }
 
-- 
2.14.4



[PATCH v3 00/20] tpm: separate tpm 1.x and tpm 2.x commands

2018-09-18 Thread Tomas Winkler
This patch series provides initial separation of tpm 1.x and tpm 2.x
commands, in foresight that the tpm 1.x chips will eventually phase out
and can be compiled out for modern systems.
 A new file is added tpm1-cmd.c that contains tpm 1.x specific commands.
In addition, tpm 1.x commands are now implemented using tpm_buf
structure and instead of tpm_cmd_t construct. The latter is now removed.

Note: my tpm 1.x HW availability is limited hence some more testing is needed.

This series also contains two trivial cleanups and addition of new
commands by TCG spec 1.36, now supported on new Intet's platforms.

Tomas Winkler (20):
  tpm2: add new tpm2 commands according to TCG 1.36
  tpm: sort objects in the Makefile
  tpm: factor out tpm 1.x duration calculation to tpm1-cmd.c
  tpm: add tpm_calc_ordinal_duration wrapper
  tpm: factor out tpm_get_timeouts
  tpm: move tpm1_pcr_extend to tpm1-cmd.c
  tpm: move tpm_getcap to tpm1-cmd.c
  tpm: factor out tpm1_get_random into tpm1-cmd.c
  tpm: move tpm1 selftest code from tpm-interface tpm1-cmd.c
  tpm: factor out tpm1 pm suspend flow into tpm1-cmd.c
  tpm: factor out tpm_startup function
  tpm: move pcr extend code to tpm2-cmd.c
  tpm: add tpm_auto_startup into tpm-interface
  tpm: tpm-interface.c drop unused macros
  tpm: tpm-space.c remove unneeded semicolon
  tpm: tpm1: rewrite tpm1_get_random() using tpm_buf structure
  tpm1: implement tpm1_pcr_read_dev() using tpm_buf structure
  tpm: use u32 instead of int for pcr index
  tpm1: reimplement SAVESTATE using tpm_buf
  tpm1: reimplement tpm1_continue_selftest() using tpm_buf

 drivers/char/tpm/Makefile|  16 +-
 drivers/char/tpm/st33zp24/st33zp24.c |   2 +-
 drivers/char/tpm/tpm-chip.c  |  11 +-
 drivers/char/tpm/tpm-interface.c | 829 ++-
 drivers/char/tpm/tpm-sysfs.c |  52 +--
 drivers/char/tpm/tpm.h   |  98 ++---
 drivers/char/tpm/tpm1-cmd.c  | 776 
 drivers/char/tpm/tpm2-cmd.c  | 279 ++--
 drivers/char/tpm/tpm2-space.c|   2 +-
 drivers/char/tpm/tpm_i2c_nuvoton.c   |  10 +-
 drivers/char/tpm/tpm_tis_core.c  |  10 +-
 include/linux/tpm.h  |   2 +-
 security/integrity/ima/ima_crypto.c  |   5 +-
 13 files changed, 1061 insertions(+), 1031 deletions(-)
 create mode 100644 drivers/char/tpm/tpm1-cmd.c

-- 
2.14.4



[PATCH v3 04/20] tpm: add tpm_calc_ordinal_duration wrapper

2018-09-18 Thread Tomas Winkler
Add convenient wrapper for ordinal duration computation
to remove boiler plate if else statement over TPM2.

if (chip->flags & TPM_CHIP_FLAG_TPM2)
tpm2_calc_ordinal_duration(chip, ordinal);
else
tpm1_calc_ordinal_duration(chip, ordinal);

Signed-off-by: Tomas Winkler 
---
V2-V3: Rebase
 drivers/char/tpm/st33zp24/st33zp24.c |  2 +-
 drivers/char/tpm/tpm-interface.c | 14 ++
 drivers/char/tpm/tpm.h   |  1 +
 drivers/char/tpm/tpm1-cmd.c  |  1 -
 drivers/char/tpm/tpm2-cmd.c  |  1 -
 drivers/char/tpm/tpm_i2c_nuvoton.c   |  2 +-
 drivers/char/tpm/tpm_tis_core.c  |  6 +-
 drivers/char/tpm/xen-tpmfront.c  |  2 +-
 8 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/char/tpm/st33zp24/st33zp24.c 
b/drivers/char/tpm/st33zp24/st33zp24.c
index 16be974955ea..abd675bec88c 100644
--- a/drivers/char/tpm/st33zp24/st33zp24.c
+++ b/drivers/char/tpm/st33zp24/st33zp24.c
@@ -430,7 +430,7 @@ static int st33zp24_send(struct tpm_chip *chip, unsigned 
char *buf,
ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
 
ret = wait_for_stat(chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID,
-   tpm1_calc_ordinal_duration(chip, ordinal),
+   tpm_calc_ordinal_duration(chip, ordinal),
_dev->read_queue, false);
if (ret < 0)
goto out_err;
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index bb3eed907c72..7b460f646781 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -47,6 +47,15 @@ module_param_named(suspend_pcr, tpm_suspend_pcr, uint, 0644);
 MODULE_PARM_DESC(suspend_pcr,
 "PCR to use for dummy writes to facilitate flush on suspend.");
 
+unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal)
+{
+   if (chip->flags & TPM_CHIP_FLAG_TPM2)
+   return tpm2_calc_ordinal_duration(chip, ordinal);
+   else
+   return tpm1_calc_ordinal_duration(chip, ordinal);
+}
+EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration);
+
 static int tpm_validate_command(struct tpm_chip *chip,
 struct tpm_space *space,
 const u8 *cmd,
@@ -220,10 +229,7 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip,
if (chip->flags & TPM_CHIP_FLAG_IRQ)
goto out_recv;
 
-   if (chip->flags & TPM_CHIP_FLAG_TPM2)
-   stop = jiffies + tpm2_calc_ordinal_duration(chip, ordinal);
-   else
-   stop = jiffies + tpm1_calc_ordinal_duration(chip, ordinal);
+   stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal);
do {
u8 status = chip->ops->status(chip);
if ((status & chip->ops->req_complete_mask) ==
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index c59d2c20c339..73511cd89bef 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -547,6 +547,7 @@ int tpm_get_timeouts(struct tpm_chip *);
 int tpm1_auto_startup(struct tpm_chip *chip);
 int tpm_do_selftest(struct tpm_chip *chip);
 unsigned long tpm1_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
+unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
 int tpm_pm_suspend(struct device *dev);
 int tpm_pm_resume(struct device *dev);
 
diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c
index fa6ba8d3458c..7e7fa94c095c 100644
--- a/drivers/char/tpm/tpm1-cmd.c
+++ b/drivers/char/tpm/tpm1-cmd.c
@@ -306,5 +306,4 @@ unsigned long tpm1_calc_ordinal_duration(struct tpm_chip 
*chip, u32 ordinal)
else
return duration;
 }
-EXPORT_SYMBOL_GPL(tpm1_calc_ordinal_duration);
 
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 9c3c5c0628d9..f6c981f3ee12 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -712,7 +712,6 @@ unsigned long tpm2_calc_ordinal_duration(struct tpm_chip 
*chip, u32 ordinal)
else
return msecs_to_jiffies(TPM2_DURATION_DEFAULT);
 }
-EXPORT_SYMBOL_GPL(tpm2_calc_ordinal_duration);
 
 /**
  * tpm2_do_selftest() - ensure that all self tests have passed
diff --git a/drivers/char/tpm/tpm_i2c_nuvoton.c 
b/drivers/char/tpm/tpm_i2c_nuvoton.c
index 5d20e98b844f..4146f822fba9 100644
--- a/drivers/char/tpm/tpm_i2c_nuvoton.c
+++ b/drivers/char/tpm/tpm_i2c_nuvoton.c
@@ -456,7 +456,7 @@ static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, 
size_t len)
return rc;
}
ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
-   duration = tpm1_calc_ordinal_duration(chip, ordinal);
+   duration = tpm_calc_ordinal_duration(chip, ordinal);
rc = i2c_nuvoton_wait_for_data_avail(chip, duration, >read_queue);
if (rc) {
dev_err(dev, "%s() timeout command duration %ld\n",
diff --git 

[PATCH v3 14/20] tpm: tpm-interface.c drop unused macros

2018-09-18 Thread Tomas Winkler
The code movement left some macros unused.

Signed-off-by: Tomas Winkler 
---
V3: new in the series

 drivers/char/tpm/tpm-interface.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index a8f8e0bcb434..358ef5bd601e 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -33,10 +33,6 @@
 
 #include "tpm.h"
 
-#define TSC_MAX_ORDINAL 12
-#define TPM_PROTECTED_COMMAND 0x00
-#define TPM_CONNECTION_COMMAND 0x40
-
 /*
  * Bug workaround - some TPM's don't flush the most
  * recently changed pcr on suspend, so force the flush
-- 
2.14.4



Re: [LKP] [vfree, kvfree] a79ed8bfb2: BUG:sleeping_function_called_from_invalid_context_at_mm/util.c

2018-09-18 Thread Andrey Ryabinin
On 09/18/2018 11:52 AM, kernel test robot wrote:

> 
> [3.265372] BUG: sleeping function called from invalid context at 
> mm/util.c:449
> [3.288552] in_atomic(): 0, irqs_disabled(): 0, pid: 142, name: 
> rhashtable_thra
> [3.301548] INFO: lockdep is turned off.
> [3.302214] Preemption disabled at:
> [3.302221] [] get_random_u32+0x4f/0x100
> [3.327556] CPU: 0 PID: 142 Comm: rhashtable_thra Tainted: GW  
>  T 4.19.0-rc3-00266-ga79ed8bf #656
> [3.328540] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
> 1.10.2-1 04/01/2014
> [3.328540] Call Trace:
> [3.328540]  ? dump_stack+0x55/0x7b
> [3.328540]  ? get_random_u32+0x4f/0x100
> [3.328540]  ? ___might_sleep+0x11d/0x170
> [3.328540]  ? kvfree+0x61/0x70
> [3.328540]  ? bucket_table_free+0x18/0x80
> [3.328540]  ? bucket_table_alloc+0x79/0x160
> [3.328540]  ? rhashtable_insert_slow+0x25d/0x2d0
> [3.328540]  ? insert_retry+0x1df/0x320
> [3.328540]  ? threadfunc+0xa3/0x3fe
> [3.328540]  ? kzalloc+0x14/0x14
> [3.328540]  ? _raw_spin_unlock_irqrestore+0x30/0x50
> [3.328540]  ? kthread+0xd1/0x100
> [3.328540]  ? insert_retry+0x320/0x320
> [3.328540]  ? kthread_delayed_work_timer_fn+0x80/0x80
> [3.328540]  ? ret_from_fork+0x2e/0x38


Seems like we need to drop might_sleep_if() from kvfree().

rcu_read_lock()
rhashtable_insert_rehash()
new_tbl = bucket_table_alloc(ht, size, GFP_ATOMIC | 
__GFP_NOWARN);
->kvmalloc();

bucket_table_free(new_tbl);
->kvfree()
rcu_read_unlock()

kvmalloc(..., GFP_ATOMIC) simply always kmalloc:
if ((flags & GFP_KERNEL) != GFP_KERNEL)
return kmalloc_node(size, flags, node);

So in the above case, kvfree() always frees kmalloced memory -> and never calls 
vfree().

Signed-off-by: Andrey Ryabinin 
---
 mm/util.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/mm/util.c b/mm/util.c
index 929ed1795bc1..7f1f165f46af 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -446,8 +446,6 @@ EXPORT_SYMBOL(kvmalloc_node);
  */
 void kvfree(const void *addr)
 {
-   might_sleep_if(!in_interrupt());
-
if (is_vmalloc_addr(addr))
vfree(addr);
else
-- 


Re: [PATCH] tty/sysrq: Make local variable 'killer' in sysrq_handle_crash() global

2018-09-18 Thread Sai Prakash Ranjan

On 9/18/2018 2:47 PM, Greg Kroah-Hartman wrote:

On Tue, Sep 18, 2018 at 02:35:02PM +0530, Sai Prakash Ranjan wrote:

On 9/18/2018 12:50 PM, Greg Kroah-Hartman wrote:

On Tue, Sep 18, 2018 at 12:28:39PM +0530, Sai Prakash Ranjan wrote:

On 9/18/2018 11:41 AM, Jiri Slaby wrote:

On 09/17/2018, 11:33 PM, Matthias Kaehlcke wrote:

sysrq_handle_crash() dereferences a NULL pointer on purpose to force
an exception, the local variable 'killer' is assigned to NULL and
dereferenced later. Clang detects the NULL pointer dereference at compile
time and emits a BRK instruction (on arm64) instead of the expected NULL
pointer exception. Change 'killer' to a global variable (and rename it
to 'sysrq_killer' to avoid possible clashes) to prevent Clang from
detecting the condition. By default global variables are initialized
with zero/NULL in C, therefore an explicit initialization is not needed.

Reported-by: Sai Prakash Ranjan 
Suggested-by: Evan Green 
Signed-off-by: Matthias Kaehlcke 
---
drivers/tty/sysrq.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index 06ed20dd01ba..49fa8e758690 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -132,10 +132,10 @@ static struct sysrq_key_op sysrq_unraw_op = {
#define sysrq_unraw_op (*(struct sysrq_key_op *)NULL)
#endif /* CONFIG_VT */
+char *sysrq_killer;
+
static void sysrq_handle_crash(int key)
{
-   char *killer = NULL;
-
/* we need to release the RCU read lock here,
 * otherwise we get an annoying
 * 'BUG: sleeping function called from invalid context'
@@ -144,7 +144,7 @@ static void sysrq_handle_crash(int key)
rcu_read_unlock();
panic_on_oops = 1;  /* force panic */
wmb();
-   *killer = 1;
+   *sysrq_killer = 1;


Just because a static analyzer is wrong? Oh wait, even compiler is
wrong. At least make it a static global. Or what about OPTIMIZER_HIDE_VAR?



static global does not work, clang still inserts brk. As for
OPTIMIZE_HIDE_VAR, it seems to work.
But, I dont think it is defined for clang in which case it defaults to using
barrier(). There is already one wmb(), so will it be right?


Ick, why is this needed at all?  Why are we trying to "roll our own
panic" in this code?



Hi Greg, do you mean like why there is a killer var at all or why this
change is required?


I understand you are using a compiler that thinks it wants to protect
yourself from your code and tries to "fix" it for you.  That's fine, and
is up to the compiler writers (personally that seems not a good idea.)

My question is why we just don't call panic() here instead of trying to
duplicate the logic of that function here.  Why is that happening?



It seems fine to call panic() here. Dont no why they chose to have a 
null pointer dereference.


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


Re: [PATCH v2 7/8] KVM: PMU: support to save/restore the guest lbr stack on vCPU switching

2018-09-18 Thread Wei Wang

On 09/18/2018 10:56 AM, Andi Kleen wrote:

From: Like Xu 

This patch adds support to KVM to save/restore the lbr stack on vCPU
context switching.

When the guest sets the ACTIVE bit of MSR_KVM_PV_LBR_CTRL, a perf event
is created on the host for the related vCPU. This perf event ensures the
LBR stack to be saved/restored when the vCPU thread is scheduled out/in.
The perf event is removed and freed when the guest clears the ACTIVE
bit.


What about live migration? Does LBR stack need to be saved on the source side 
and
restored on the dest side with the passthrough mode?

Yes it should. Either for call stack LBR, or when it is frozen/disabled.

When it's not frozen/disabled and not in call stack LBR mode it likely doesn't
hurt either, but it's not strictly needed because it will
be replaced so quickly.


Yes, should be supported. We are working on v3 with the suggested lazy 
save approach, and will send it out shortly.


Best,
Wei


Re: [BUG] mm: direct I/O (using GUP) can write to COW anonymous pages

2018-09-18 Thread Jan Kara
On Tue 18-09-18 02:35:43, Jann Horn wrote:
> On Tue, Sep 18, 2018 at 2:05 AM Hugh Dickins  wrote:

Thanks for CC Hugh.

> > On Mon, 17 Sep 2018, Jann Horn wrote:
> >
> > > [I'm not sure who the best people to ask about this are, I hope the
> > > recipient list resembles something reasonable...]
> > >
> > > I have noticed that the dup_mmap() logic on fork() doesn't handle
> > > pages with active direct I/O properly: dup_mmap() seems to assume that
> > > making the PTE referencing a page readonly will always prevent future
> > > writes to the page, but if the kernel has acquired a direct reference
> > > to the page before (e.g. via get_user_pages_fast()), writes can still
> > > happen that way.
> > >
> > > The worst-case effect of this - as far as I can tell - is that when a
> > > multithreaded process forks while one thread is in the middle of
> > > sys_read() on a file that uses direct I/O with get_user_pages_fast(),
> > > the read data can become visible in the child while the parent's
> > > buffer stays uninitialized if the parent writes to a relevant page
> > > post-fork before either the I/O completes or the child writes to it.
> >
> > Yes: you're understandably more worried by the one seeing the other's
> > data;
> 
> Actually, I was mostly just trying to find a scenario in which the
> parent doesn't get the data it's asking for, and this is the simplest
> I could come up with. :)
> 
> I was also vaguely worried about whether some other part of the mm
> subsystem might assume that COW pages are immutable, but I haven't
> found anything like that so far, so that might've been unwarranted
> paranoia.

It's actually warranted paranoia. There are situations where filesystems
don't expect *shared file* page to be written when all pages tables are
write-protected - you can have a look at https://lwn.net/Articles/753027/
for a discussion from LSF/MM on this.  And as I've learned from Nick Piggin
people were aware of this problem over 10 years ago -
https://lkml.org/lkml/2018/7/9/217. Just nobody put enough effort into
fixing this.

> > we've tended in the past to be more worried about the one getting
> > corruption, and the other not seeing the data it asked for (and usually
> > in the context of RDMA, rather than filesystem direct I/O).
> >
> > I've added some Cc's: I might be misremembering, but I think both
> > Andrea and Konstantin have offered approaches to this in the past,
> > and I believe Salman is taking a look at it currently.
> >
> > But my own interest ended when Michael added MADV_DONTFORK: beyond
> > that, we've rated it a "Patient: It hurts when I do this. Doctor:
> > Don't do that then" - more complexity and overhead to solve, than
> > we have had appetite to get into.
> 
> Makes sense, I guess.
> 
> I wonder whether there's a concise way to express this in the fork.2
> manpage, or something like that. Maybe I'll take a stab at writing
> something. The biggest issue I see with documenting this edgecase is
> that, as an application developer, if you don't know whether some file
> might be coming from a FUSE filesystem that has opted out of using the
> disk cache, the "don't do that" essentially becomes "don't read() into
> heap buffers while fork()ing in another thread", since with FUSE,
> direct I/O can happen even if you don't open files as O_DIRECT as long
> as the filesystem requests direct I/O, and get_user_pages_fast() will
> AFAIU be used for non-page-aligned buffers, meaning that an adjacent
> heap memory access could trigger CoW page duplication. But then, FUSE
> filesystems that opt out of the disk cache are probably so rare that
> it's not a concern in practice...

So at least for shared file mappings we do need to fix this issue as it's
currently userspace triggerable Oops if you try hard enough. And with RDMA
you don't even have to try that hard. Properly dealing with private
mappings should not be that hard once the infrastructure is there I hope
but I didn't seriously look into that. I've added Miklos and John to CC as
they are interested as well. John was working on fixing this problem -
https://lkml.org/lkml/2018/7/9/158 - but I didn't hear from him for quite a
while so I'm not sure whether it died off or what's the current situation.

Honza
-- 
Jan Kara 
SUSE Labs, CR


Re: [PATCH 05/19] vmw_balloon: remove sleeping allocations

2018-09-18 Thread kbuild test robot
Hi Nadav,

I love your patch! Yet something to improve:

[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on v4.19-rc4 next-20180913]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Nadav-Amit/vmw_balloon-compaction-shrinker-64-bit-etc/20180918-152302
config: x86_64-randconfig-x015-201837 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

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

   Cyclomatic Complexity 5 include/linux/compiler.h:__write_once_size
   Cyclomatic Complexity 1 include/linux/list.h:INIT_LIST_HEAD
   Cyclomatic Complexity 1 include/linux/list.h:__list_del
   Cyclomatic Complexity 2 arch/x86/include/asm/page_64.h:__phys_addr_nodebug
   Cyclomatic Complexity 1 include/linux/err.h:PTR_ERR
   Cyclomatic Complexity 1 arch/x86/include/asm/topology.h:numa_node_id
   Cyclomatic Complexity 1 arch/x86/include/asm/io.h:virt_to_phys
   Cyclomatic Complexity 1 include/linux/topology.h:numa_mem_id
   Cyclomatic Complexity 1 include/linux/mm.h:lowmem_page_address
   Cyclomatic Complexity 3 include/linux/vmw_vmci_defs.h:vmci_handle_is_equal
   Cyclomatic Complexity 1 include/linux/vmw_vmci_defs.h:vmci_handle_is_invalid
   Cyclomatic Complexity 1 drivers/misc/vmw_balloon.c:vmballoon_cmd
   Cyclomatic Complexity 2 drivers/misc/vmw_balloon.c:vmballoon_send_guest_id
   Cyclomatic Complexity 2 drivers/misc/vmw_balloon.c:vmballoon_page_size
   Cyclomatic Complexity 4 drivers/misc/vmw_balloon.c:vmballoon_send_lock_page
   Cyclomatic Complexity 5 
drivers/misc/vmw_balloon.c:vmballoon_send_batched_lock
   Cyclomatic Complexity 1 drivers/misc/vmw_balloon.c:vmballoon_add_page
   Cyclomatic Complexity 1 drivers/misc/vmw_balloon.c:vmballoon_add_batched_page
   Cyclomatic Complexity 2 include/linux/workqueue.h:to_delayed_work
   Cyclomatic Complexity 1 include/linux/err.h:IS_ERR
   Cyclomatic Complexity 8 drivers/misc/vmw_balloon.c:__vmballoon_cmd
   Cyclomatic Complexity 4 drivers/misc/vmw_balloon.c:vmballoon_send_start
   Cyclomatic Complexity 2 include/linux/list.h:__list_add
   Cyclomatic Complexity 1 include/linux/list.h:list_add
   Cyclomatic Complexity 2 drivers/misc/vmw_balloon.c:vmballoon_free_page
   Cyclomatic Complexity 2 drivers/misc/vmw_balloon.c:vmballoon_unlock_page
   Cyclomatic Complexity 5 drivers/misc/vmw_balloon.c:vmballoon_lock_page
   Cyclomatic Complexity 4 
drivers/misc/vmw_balloon.c:vmballoon_unlock_batched_page
   Cyclomatic Complexity 9 
drivers/misc/vmw_balloon.c:vmballoon_lock_batched_page
   Cyclomatic Complexity 2 drivers/misc/vmw_balloon.c:vmballoon_vmci_cleanup
   Cyclomatic Complexity 2 include/linux/list.h:__list_del_entry
   Cyclomatic Complexity 1 include/linux/list.h:list_del
   Cyclomatic Complexity 6 drivers/misc/vmw_balloon.c:vmballoon_pop
   Cyclomatic Complexity 1 include/linux/gfp.h:__alloc_pages
   Cyclomatic Complexity 1 include/linux/gfp.h:__alloc_pages_node
   Cyclomatic Complexity 2 include/linux/gfp.h:alloc_pages_node
   Cyclomatic Complexity 2 drivers/misc/vmw_balloon.c:vmballoon_init_batching
   Cyclomatic Complexity 4 drivers/misc/vmw_balloon.c:vmballoon_vmci_init
   Cyclomatic Complexity 7 drivers/misc/vmw_balloon.c:vmballoon_reset
   Cyclomatic Complexity 1 include/linux/workqueue.h:mod_delayed_work
   Cyclomatic Complexity 1 drivers/misc/vmw_balloon.c:vmballoon_doorbell
   Cyclomatic Complexity 3 drivers/misc/vmw_balloon.c:vmballoon_send_get_target
   Cyclomatic Complexity 3 drivers/misc/vmw_balloon.c:vmballoon_alloc_page
   Cyclomatic Complexity 5 
drivers/misc/vmw_balloon.c:vmballoon_release_refused_pages
   Cyclomatic Complexity 10 drivers/misc/vmw_balloon.c:vmballoon_inflate
   Cyclomatic Complexity 13 drivers/misc/vmw_balloon.c:vmballoon_deflate
   Cyclomatic Complexity 2 drivers/misc/vmw_balloon.c:vmballoon_debugfs_init
   Cyclomatic Complexity 1 drivers/misc/vmw_balloon.c:vmballoon_debug_open
   Cyclomatic Complexity 4 drivers/misc/vmw_balloon.c:vmballoon_debug_show
   Cyclomatic Complexity 1 include/linux/workqueue.h:queue_delayed_work
   Cyclomatic Complexity 4 drivers/misc/vmw_balloon.c:vmballoon_init
   Cyclomatic Complexity 8 drivers/misc/vmw_balloon.c:vmballoon_work
   Cyclomatic Complexity 1 drivers/misc/vmw_balloon.c:vmballoon_debugfs_exit
   Cyclomatic Complexity 1 drivers/misc/vmw_balloon.c:vmballoon_exit
   In file included from include/linux/mm.h:10:0,
from drivers/misc/vmw_balloon.c:21:
   In function 'vmballoon_alloc_page',
   inlined from 'vmballoon_inflate' at drivers/misc/vmw_balloon.c:735:8,
   inlined from 'vmballoon_work' at drivers/misc/vmw_balloon.c:964:4:
>> include/linux/compiler.h:358:38: error: call to '__compiletime_assert_446' 
>> declared with attribute error: BUILD_BUG failed
 _compiletime_assert(condition, msg, __compiletime

Re: [PATCH v3 7/7] regulator: bd718xx: rename bd71837 to 718xx

2018-09-18 Thread kbuild test robot
Hi Matti,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on regulator/for-next]
[also build test ERROR on next-20180913]
[cannot apply to v4.19-rc4]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Matti-Vaittinen/regulator-mfd-dt_bindings-bd718x7-Support-ROHM-bd71847/20180914-210454
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git 
for-next
config: x86_64-randconfig-s4-09181517 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

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

>> drivers/regulator/bd718x7-regulator.c:364:16: error: implicit declaration of 
>> function 'of_match_ptr'; did you mean 'hash_ptr'? 
>> [-Werror=implicit-function-declaration]
   .of_match = of_match_ptr("BUCK1"),
   ^~~~
   hash_ptr
>> drivers/regulator/bd718x7-regulator.c:364:16: warning: initialization makes 
>> pointer from integer without a cast [-Wint-conversion]
   drivers/regulator/bd718x7-regulator.c:364:16: note: (near initialization for 
'bd71847_regulators[0].desc.of_match')
>> drivers/regulator/bd718x7-regulator.c:364:16: error: initializer element is 
>> not constant
   drivers/regulator/bd718x7-regulator.c:364:16: note: (near initialization for 
'bd71847_regulators[0].desc.of_match')
   drivers/regulator/bd718x7-regulator.c:365:23: warning: initialization makes 
pointer from integer without a cast [-Wint-conversion]
   .regulators_node = of_match_ptr("regulators"),
  ^~~~
   drivers/regulator/bd718x7-regulator.c:365:23: note: (near initialization for 
'bd71847_regulators[0].desc.regulators_node')
   drivers/regulator/bd718x7-regulator.c:365:23: error: initializer element is 
not constant
   drivers/regulator/bd718x7-regulator.c:365:23: note: (near initialization for 
'bd71847_regulators[0].desc.regulators_node')
   drivers/regulator/bd718x7-regulator.c:388:16: warning: initialization makes 
pointer from integer without a cast [-Wint-conversion]
   .of_match = of_match_ptr("BUCK2"),
   ^~~~
   drivers/regulator/bd718x7-regulator.c:388:16: note: (near initialization for 
'bd71847_regulators[1].desc.of_match')
   drivers/regulator/bd718x7-regulator.c:388:16: error: initializer element is 
not constant
   drivers/regulator/bd718x7-regulator.c:388:16: note: (near initialization for 
'bd71847_regulators[1].desc.of_match')
   drivers/regulator/bd718x7-regulator.c:389:23: warning: initialization makes 
pointer from integer without a cast [-Wint-conversion]
   .regulators_node = of_match_ptr("regulators"),
  ^~~~
   drivers/regulator/bd718x7-regulator.c:389:23: note: (near initialization for 
'bd71847_regulators[1].desc.regulators_node')
   drivers/regulator/bd718x7-regulator.c:389:23: error: initializer element is 
not constant
   drivers/regulator/bd718x7-regulator.c:389:23: note: (near initialization for 
'bd71847_regulators[1].desc.regulators_node')
   drivers/regulator/bd718x7-regulator.c:411:16: warning: initialization makes 
pointer from integer without a cast [-Wint-conversion]
   .of_match = of_match_ptr("BUCK3"),
   ^~~~
   drivers/regulator/bd718x7-regulator.c:411:16: note: (near initialization for 
'bd71847_regulators[2].desc.of_match')
   drivers/regulator/bd718x7-regulator.c:411:16: error: initializer element is 
not constant
   drivers/regulator/bd718x7-regulator.c:411:16: note: (near initialization for 
'bd71847_regulators[2].desc.of_match')
   drivers/regulator/bd718x7-regulator.c:412:23: warning: initialization makes 
pointer from integer without a cast [-Wint-conversion]
   .regulators_node = of_match_ptr("regulators"),
  ^~~~
   drivers/regulator/bd718x7-regulator.c:412:23: note: (near initialization for 
'bd71847_regulators[2].desc.regulators_node')
   drivers/regulator/bd718x7-regulator.c:412:23: error: initializer element is 
not constant
   drivers/regulator/bd718x7-regulator.c:412:23: note: (near initialization for 
'bd71847_regulators[2].desc.regulators_node')
   drivers/regulator/bd718x7-regulator.c:438:16: warning: initialization makes 
pointer from integer without a cast [-Wint-conversion]
   .of_match = of_match_ptr("BUCK4"),
   ^~~~
   drivers/regulator/bd718x7-regulator.c:438:16: note: (near initialization for 
'bd71847_regulators[3].desc.of_match')
   drivers/regulator/bd718x7-regulator.c:438:16: error: initializer element is 
not constant
   drivers/regulator/bd718x7-regulator.c:438:16: note: (near initialization for 
'bd71847_regulators[3].desc.of_match')
   drivers/regulator/bd718x7-regulator.c:439:23: warning: initialization makes 
pointer from integer without a cast [-Wint-conversion]
   

Re: Custom Interrupt Handler for NMI

2018-09-18 Thread Alexander Shishkin
Andy Shevchenko  writes:

> On Wed, Sep 12, 2018 at 6:16 PM Jack Henschel  
> wrote:
>>
>> Hi there,
>>
>> is it possible to register a custom interrupt handler for a NMI/PMI
>> Interrupt?
>
> I don't think so, though I'm not an expert in the area, so, I also
> might be interested to see the answer to this question.

Sure, register_nmi_handler().

>> In particular, I want to catch the Intel PT interrupt (generated by the
>> PMU and sent over the LAPIC) in a kernel module. Is such a thing possible?
>
> I'm not sure why do you need this, Cc'ed to PT driver author.

Thanks, Andy. I am indeed interested in all the different PT drivers out
there.

So far, I'm aware of the perf driver and an out of tree simple-pt. If
you end up with yet another one, do let me know.

Good luck,
--
Alex


[PATCH 0/4] blk-mq: allow to unfreeze queue when io isn't drained

2018-09-18 Thread Ming Lei
Hi,

The 1st patch is one cleanup and prepares for introducing percpu_ref_resurge().

The 2nd patch introduces percpu_ref_resurge() for implementing
blk_mq_unfreeze_queue_no_drain_io().

The 3rd patch introdces blk_mq_unfreeze_queue_no_drain_io() for
cases in which queue can be unfreeze without draininig IO.

The 4th patch applies blk_mq_unfreeze_queue_no_drain_io() to
NVMe PCI timeout, so that IO hang may be avoided inside
nvme_reset_work() when new IO timeout is triggered. 

Part of idea is from Jianchao's early work:

https://marc.info/?l=linux-kernel=153612052611020=2


Ming Lei (4):
  percpu-refcount: move zeroing of percpu part into
percpu_ref_switch_to_atomic_rcu
  lib/percpu-refcount: introduce percpu_ref_resurge()
  blk-mq: introduce blk_mq_unfreeze_queue_no_drain_io
  nvme: don't drain IO in nvme_reset_work()

 block/blk-mq.c  | 25 +--
 drivers/nvme/host/core.c| 12 ---
 drivers/nvme/host/nvme.h|  2 +-
 drivers/nvme/host/pci.c |  3 +-
 include/linux/blk-mq.h  |  1 +
 include/linux/percpu-refcount.h |  1 +
 lib/percpu-refcount.c   | 71 +++--
 7 files changed, 90 insertions(+), 25 deletions(-)

-- 
2.9.5



Re: [PATCH 2/2] x86/kexec_file: add reserved e820 ranges to 2nd kernel e820 table

2018-09-18 Thread lijiang
在 2018年09月18日 11:20, Dave Young 写道:
> On 09/18/18 at 10:48am, Lianbo Jiang wrote:
>> e820 reserved ranges is useful in kdump kernel, we have added this in
>> kexec-tools code.
>>
>> One reason is PCI mmconf (extended mode) requires reserved region
>> otherwise it falls back to legacy mode.
>>
>> When AMD SME kdump support, it needs to map dmi table area as unencrypted.
>> For normal boot these ranges sit in e820 reserved ranges thus the early
>> ioremap code naturally map them as unencrypted. So if we have same e820
>> reserve setup in kdump kernel then it will just work like normal kernel.
>>
>> Signed-off-by: Dave Young 
>> Signed-off-by: Lianbo Jiang 
>> ---
>>  arch/x86/kernel/crash.c | 6 ++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
>> index 3c113e6545a3..db453e9c117b 100644
>> --- a/arch/x86/kernel/crash.c
>> +++ b/arch/x86/kernel/crash.c
>> @@ -384,6 +384,12 @@ int crash_setup_memmap_entries(struct kimage *image, 
>> struct boot_params *params)
>>  walk_iomem_res_desc(IORES_DESC_ACPI_NV_STORAGE, flags, 0, -1, ,
>>  memmap_entry_callback);
>>  
>> +/* Add all reserved ranges */
>> +cmd.type = E820_TYPE_RESERVED;
>> +flags = IORESOURCE_MEM;
> 
> Lianbo, rethink about this, we will miss other io resource types if only
> match IORESOURCE_MEM here, can you redo the patch with just using "0"
> for the passing flags?
> 

This patches align on kexec-tools for e820 reserved ranges, if so, the 
kexec-tools also need to
be improved for the other type, such as IORESOURCE_IO/BUS/DMA(...), right?

I will improve these patches and post v2 tomorrow.

Thanks.

>> +walk_iomem_res_desc(IORES_DESC_NONE, flags, 0, -1, ,
>> +memmap_entry_callback);
>> +
>>  /* Add crashk_low_res region */
>>  if (crashk_low_res.end) {
>>  ei.addr = crashk_low_res.start;
>> -- 
>> 2.17.1
>>


Re: [LKP] [ipc] 61224adcd2: general_protection_fault:#[##]

2018-09-18 Thread David Howells
Li Zhijian  wrote:

> this is not expected.
> could you list/home/dhowells/.lkp/cache

final_initrd  initrd-concatenated  lkp/  lkp-x86_64-ad88cb1a437a_.cgz  osimage/

Note that ~/.lkp is a symlink to somewhere that I don't mind clobbering.

Does this assume that I'm running on some particular OS other than Fedora?

David


Re: [PATCH v2 1/5] spi: spi-mem: Add driver for NXP FlexSPI controller

2018-09-18 Thread Frieder Schrempf

Hi Yogesh,

I have some remarks about your general approach that came to me when 
looking at the FSPI driver with the things at the back of my mind, that 
I've learned from working at the FSL QSPI driver.


On 17.09.2018 11:48, Yogesh Gaur wrote:

- Add a driver for NXP FlexSPI host controller

(0) What is the FlexSPI controller?
  FlexSPI is a flexsible SPI host controller which supports two SPI
  channels and up to 4 external devices. Each channel supports
  Single/Dual/Quad/Octal mode data transfer (1/2/4/8 bidirectional
  data lines) i.e. FlexSPI acts as an interface to external devices,
  maximum 4, each with up to 8 bidirectional data lines.

  It uses new SPI memory interface of SPI framework to issue flash memory
  operations to up to four connected flash chips (2 buses with 2 CS each).

(1) Tested this driver with the mtd_debug and JFFS2 filesystem utility
  on NXP LX2160ARDB and LX2160AQDS targets.
  LX2160ARDB is having two NOR slave device connected on single bus A
  i.e. A0 and A1 (CS0 and CS1).
  LX2160AQDS is having two NOR slave device connected on separate buses
  one flash on A0 and second on B1 i.e. (CS0 and CS3).
  Verified this driver on following SPI NOR flashes:
 Micron, mt35xu512ab, [Read - 1 bit mode]
 Cypress, s25fl512s, [Read - 1/2/4 bit mode]

Signed-off-by: Yogesh Gaur 
---
Changes for v2:
- Incorporated Boris review comments.
- Remove dependency of driver over connected flash device size.
- Modified the logic to select requested CS.
- Remove SPI-Octal Macros.

  drivers/spi/Kconfig|   10 +
  drivers/spi/Makefile   |1 +
  drivers/spi/spi-nxp-fspi.c | 1246 
  3 files changed, 1257 insertions(+)
  create mode 100644 drivers/spi/spi-nxp-fspi.c

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index ad5d68e..68da874 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -251,6 +251,16 @@ config SPI_FSL_LPSPI
help
  This enables Freescale i.MX LPSPI controllers in master mode.
  
+config SPI_NXP_FLEXSPI

+   tristate "NXP Flex SPI controller"
+   depends on ARCH_LAYERSCAPE || HAS_IOMEM
+   help
+ This enables support for the Flex SPI controller in master mode.
+ Up to four slave devices can be connected on two buses with two
+ chipselects each.
+ This controller does not support generic SPI messages and only
+ supports the high-level SPI memory interface.
+
  config SPI_GPIO
tristate "GPIO-based bitbanging SPI Master"
depends on GPIOLIB || COMPILE_TEST
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index cb1f437..52c9f18 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -59,6 +59,7 @@ obj-$(CONFIG_SPI_MPC52xx) += spi-mpc52xx.o
  obj-$(CONFIG_SPI_MT65XX)+= spi-mt65xx.o
  obj-$(CONFIG_SPI_MXS) += spi-mxs.o
  obj-$(CONFIG_SPI_NUC900)  += spi-nuc900.o
+obj-$(CONFIG_SPI_NXP_FLEXSPI)  += spi-nxp-fspi.o
  obj-$(CONFIG_SPI_OC_TINY) += spi-oc-tiny.o
  spi-octeon-objs   := spi-cavium.o 
spi-cavium-octeon.o
  obj-$(CONFIG_SPI_OCTEON)  += spi-octeon.o
diff --git a/drivers/spi/spi-nxp-fspi.c b/drivers/spi/spi-nxp-fspi.c
new file mode 100644
index 000..8106254
--- /dev/null
+++ b/drivers/spi/spi-nxp-fspi.c
@@ -0,0 +1,1246 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/*
+ * NXP FlexSPI(FSPI) controller driver.
+ *
+ * Copyright 2018 NXP.
+ *
+ * FlexSPI is a flexsible SPI host controller which supports two SPI
+ * channels and up to 4 external devices. Each channel supports
+ * Single/Dual/Quad/Octal mode data transfer (1/2/4/8 bidirectional
+ * data lines).
+ *
+ * FlexSPI controller is driven by the LUT(Look-up Table) registers
+ * LUT registers are a look-up-table for sequences of instructions.
+ * A valid sequence consists of four LUT registers.
+ * Maximum 32 LUT sequences can be programmed simultaneously.
+ *
+ * LUTs are being created at run-time based on the commands passed
+ * from the spi-mem framework, using single LUT index.
+ *
+ * Software triggered Flash read/write access by IP Bus.
+ *
+ * Memory mapped read access by AHB Bus.
+ *
+ * Based on SPI MEM interface.
+ *
+ * Author:
+ * Yogesh Gaur 


Although the QSPI driver is not merged yet, large parts of this driver 
are based on the code that Boris and I have written for the FSL QSPI 
controller. So I consider it appropriate to add a reference to the QSPI 
driver and its authors here.



+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+/*
+ * The driver only uses one single LUT entry, that is updated on
+ * each call of exec_op(). Index 0 is preset at boot with a basic
+ * read operation, so let's use the last entry (31).
+ */
+#defineSEQID_LUT   

[PATCH v5 0/2] Add support for LPASS clock controller for SDM845

2018-09-18 Thread Taniya Das
 [v5]
  * Address the comments in device tree binding to update the reg-names,
update the unit address in lpass clock node example and also
add reg property for the gcc clock node.
  * Update the lpass driver to take care of the reg-names.

 [v4]
  * Update the description in GCC Documentation binding for
  'qcom,lpass-protected'.
  * Remove 'qcom,lpass-protected' from LPASS Documentation binding.
  * Update KConfig to use Low Power Audio Subsystem.
  * Add module_exit() and also update return value for
devm_ioremap_resource failure.

 [v3]
  * Add a device tree property to identify lpass protected GCC clocks.
  * Update the GCC driver code to register the lpass clocks when the flag is
   defined.
  * Add comment for clocks using the BRANCH_HALT_SKIP flag.
  * Use platform APIs instead of of_address_to_resource.
  * Replace devm_ioremap with devm_ioremap_resource.
  * Use fixed index for 'lpass_cc' & 'lpass_qdsp6ss' in probe.

 [v2]
  * Make gcc_lpass_sway_clk static.
  * Remove using child nodes and use reg-names to differentiate various
domains of LPASS CC.

Add support for the lpass clock controller found on SDM845 based devices.
This would allow lpass peripheral loader drivers to control the clocks to
bring the subsystem out of reset.

Taniya Das (2):
  dt-bindings: clock: Introduce QCOM LPASS clock bindings
  clk: qcom: Add lpass clock controller driver for SDM845

 .../devicetree/bindings/clock/qcom,gcc.txt |   2 +
 .../devicetree/bindings/clock/qcom,lpasscc.txt |  35 
 drivers/clk/qcom/Kconfig   |   9 +
 drivers/clk/qcom/Makefile  |   1 +
 drivers/clk/qcom/gcc-sdm845.c  |  35 
 drivers/clk/qcom/lpasscc-sdm845.c  | 195 +
 include/dt-bindings/clock/qcom,gcc-sdm845.h|   2 +
 include/dt-bindings/clock/qcom,lpass-sdm845.h  |  16 ++
 8 files changed, 295 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/qcom,lpasscc.txt
 create mode 100644 drivers/clk/qcom/lpasscc-sdm845.c
 create mode 100644 include/dt-bindings/clock/qcom,lpass-sdm845.h

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



Re: [PATCH 1/2] dt-bindings: clock: Introduce QCOM LPASS clock bindings

2018-09-18 Thread Taniya Das

Hello Rob,

Thanks for the review comments.

On 9/17/2018 8:48 AM, Rob Herring wrote:

On Tue, Sep 11, 2018 at 10:30:05PM +0530, Taniya Das wrote:

Add device tree bindings for Low Power Audio subsystem clock controller for
Qualcomm Technology Inc's SDM845 SoCs.

Signed-off-by: Taniya Das 
---
  .../devicetree/bindings/clock/qcom,gcc.txt |  2 ++
  .../devicetree/bindings/clock/qcom,lpasscc.txt | 31 ++
  include/dt-bindings/clock/qcom,gcc-sdm845.h|  2 ++
  include/dt-bindings/clock/qcom,lpass-sdm845.h  | 16 +++
  4 files changed, 51 insertions(+)
  create mode 100644 Documentation/devicetree/bindings/clock/qcom,lpasscc.txt
  create mode 100644 include/dt-bindings/clock/qcom,lpass-sdm845.h

diff --git a/Documentation/devicetree/bindings/clock/qcom,gcc.txt 
b/Documentation/devicetree/bindings/clock/qcom,gcc.txt
index 664ea1f..b3ff6e8 100644
--- a/Documentation/devicetree/bindings/clock/qcom,gcc.txt
+++ b/Documentation/devicetree/bindings/clock/qcom,gcc.txt
@@ -32,6 +32,8 @@ be part of GCC and hence the TSENS properties can also be
  part of the GCC/clock-controller node.
  For more details on the TSENS properties please refer
  Documentation/devicetree/bindings/thermal/qcom-tsens.txt
+- qcom,lpass-protected : Indicate that the LPASS clock branches within GCC are
+unusable due to firmware access control restrictions.
  
  Example:

clock-controller@90 {
diff --git a/Documentation/devicetree/bindings/clock/qcom,lpasscc.txt 
b/Documentation/devicetree/bindings/clock/qcom,lpasscc.txt
new file mode 100644
index 000..d312957
--- /dev/null
+++ b/Documentation/devicetree/bindings/clock/qcom,lpasscc.txt
@@ -0,0 +1,31 @@
+Qualcomm LPASS Clock Controller Binding
+---
+
+Required properties :
+- compatible   : shall contain "qcom,sdm845-lpasscc"
+- #clock-cells : from common clock binding, shall contain 1.
+- reg  : shall contain base register address and size,
+ in the order
+   Index-0 maps to LPASS_CC register region
+   Index-1 maps to LPASS_QDSP6SS register region
+
+Optional properties :
+- reg-names: register names of LPASS domain
+"lpass_cc", "lpass_qdsp6ss".


"cc" and "qdsp6ss" is sufficient.



Sure will update in the next patch series.


+
+Example:
+
+The below node has to be defined in the cases where the LPASS peripheral loader
+would bring the subsystem out of reset.
+
+   lpasscc: clock-controller {


Needs a unit-address.



Yes, my mistake. Missed adding it.


+   compatible = "qcom,sdm845-lpasscc";
+   reg = <0x17014000 0x1f004>, <0x1730 0x200>;
+   reg-names = "lpass_cc", "lpass_qdsp6ss";
+   #clock-cells = <1>;
+   };
+
+   gcc: clock-controller@10 {


This needs a reg property.



Sure, will update the same.


+   compatible = "qcom,gcc-sdm845";
+   qcom,lpass-protected;
+   };



diff --git a/include/dt-bindings/clock/qcom,gcc-sdm845.h 
b/include/dt-bindings/clock/qcom,gcc-sdm845.h
index b8eae5a..968fa65 100644
--- a/include/dt-bindings/clock/qcom,gcc-sdm845.h
+++ b/include/dt-bindings/clock/qcom,gcc-sdm845.h
@@ -197,6 +197,8 @@
  #define GCC_QSPI_CORE_CLK_SRC 187
  #define GCC_QSPI_CORE_CLK 188
  #define GCC_QSPI_CNOC_PERIPH_AHB_CLK  189
+#define GCC_LPASS_Q6_AXI_CLK   190
+#define GCC_LPASS_SWAY_CLK 191
  
  /* GCC Resets */

  #define GCC_MMSS_BCR  0
diff --git a/include/dt-bindings/clock/qcom,lpass-sdm845.h 
b/include/dt-bindings/clock/qcom,lpass-sdm845.h
new file mode 100644
index 000..015968e
--- /dev/null
+++ b/include/dt-bindings/clock/qcom,lpass-sdm845.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
+ */
+
+#ifndef _DT_BINDINGS_CLK_SDM_LPASS_SDM845_H
+#define _DT_BINDINGS_CLK_SDM_LPASS_SDM845_H
+
+#define LPASS_AUDIO_WRAPPER_AON_CLK0
+#define LPASS_Q6SS_AHBM_AON_CLK1
+#define LPASS_Q6SS_AHBS_AON_CLK2
+#define LPASS_QDSP6SS_XO_CLK   3
+#define LPASS_QDSP6SS_SLEEP_CLK4
+#define LPASS_QDSP6SS_CORE_CLK 5
+
+#endif
--
Qualcomm INDIA, on behalf of Qualcomm Innovation Center, Inc.is a member
of the Code Aurora Forum, hosted by the  Linux Foundation.





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

--


[PATCH v5 2/2] clk: qcom: Add lpass clock controller driver for SDM845

2018-09-18 Thread Taniya Das
Add support for the lpass clock controller found on SDM845 based devices.
This would allow lpass peripheral loader drivers to control the clocks to
bring the subsystem out of reset.
LPASS clocks present on the global clock controller would be registered
with the clock framework based on the device tree flag.

Signed-off-by: Taniya Das 
---
 drivers/clk/qcom/Kconfig  |   9 ++
 drivers/clk/qcom/Makefile |   1 +
 drivers/clk/qcom/gcc-sdm845.c |  35 +++
 drivers/clk/qcom/lpasscc-sdm845.c | 195 ++
 4 files changed, 240 insertions(+)
 create mode 100644 drivers/clk/qcom/lpasscc-sdm845.c

diff --git a/drivers/clk/qcom/Kconfig b/drivers/clk/qcom/Kconfig
index 5b181b1..747ffb4 100644
--- a/drivers/clk/qcom/Kconfig
+++ b/drivers/clk/qcom/Kconfig
@@ -272,6 +272,15 @@ config SDM_DISPCC_845
  Say Y if you want to support display devices and functionality such as
  splash screen.
 
+config SDM_LPASSCC_845
+   tristate "SDM845 Low Power Audio Subsystem (LPAAS) Clock Controller"
+   depends on COMMON_CLK_QCOM
+   select SDM_GCC_845
+   help
+ Support for the LPASS clock controller on SDM845 devices.
+ Say Y if you want to use the LPASS branch clocks of the LPASS clock
+ controller to reset the LPASS subsystem.
+
 config SPMI_PMIC_CLKDIV
tristate "SPMI PMIC clkdiv Support"
depends on (COMMON_CLK_QCOM && SPMI) || COMPILE_TEST
diff --git a/drivers/clk/qcom/Makefile b/drivers/clk/qcom/Makefile
index 935f142..53a5283 100644
--- a/drivers/clk/qcom/Makefile
+++ b/drivers/clk/qcom/Makefile
@@ -42,5 +42,6 @@ obj-$(CONFIG_QCOM_CLK_SMD_RPM) += clk-smd-rpm.o
 obj-$(CONFIG_SDM_CAMCC_845) += camcc-sdm845.o
 obj-$(CONFIG_SDM_DISPCC_845) += dispcc-sdm845.o
 obj-$(CONFIG_SDM_GCC_845) += gcc-sdm845.o
+obj-$(CONFIG_SDM_LPASSCC_845) += lpasscc-sdm845.o
 obj-$(CONFIG_SDM_VIDEOCC_845) += videocc-sdm845.o
 obj-$(CONFIG_SPMI_PMIC_CLKDIV) += clk-spmi-pmic-div.o
diff --git a/drivers/clk/qcom/gcc-sdm845.c b/drivers/clk/qcom/gcc-sdm845.c
index 08d593e..fa8c37c 100644
--- a/drivers/clk/qcom/gcc-sdm845.c
+++ b/drivers/clk/qcom/gcc-sdm845.c
@@ -3169,6 +3169,32 @@ enum {
},
 };
 
+static struct clk_branch gcc_lpass_q6_axi_clk = {
+   .halt_reg = 0x47000,
+   .halt_check = BRANCH_HALT,
+   .clkr = {
+   .enable_reg = 0x47000,
+   .enable_mask = BIT(0),
+   .hw.init = &(struct clk_init_data){
+   .name = "gcc_lpass_q6_axi_clk",
+   .ops = _branch2_ops,
+   },
+   },
+};
+
+static struct clk_branch gcc_lpass_sway_clk = {
+   .halt_reg = 0x47008,
+   .halt_check = BRANCH_HALT,
+   .clkr = {
+   .enable_reg = 0x47008,
+   .enable_mask = BIT(0),
+   .hw.init = &(struct clk_init_data){
+   .name = "gcc_lpass_sway_clk",
+   .ops = _branch2_ops,
+   },
+   },
+};
+
 static struct gdsc pcie_0_gdsc = {
.gdscr = 0x6b004,
.pd = {
@@ -3469,6 +3495,8 @@ enum {
[GCC_QSPI_CORE_CLK_SRC] = _qspi_core_clk_src.clkr,
[GCC_QSPI_CORE_CLK] = _qspi_core_clk.clkr,
[GCC_QSPI_CNOC_PERIPH_AHB_CLK] = _qspi_cnoc_periph_ahb_clk.clkr,
+   [GCC_LPASS_Q6_AXI_CLK] = NULL,
+   [GCC_LPASS_SWAY_CLK] = NULL,
 };
 
 static const struct qcom_reset_map gcc_sdm845_resets[] = {
@@ -3583,6 +3611,13 @@ static int gcc_sdm845_probe(struct platform_device *pdev)
if (ret)
return ret;
 
+   if (of_property_read_bool(pdev->dev.of_node, "qcom,lpass-protected")) {
+   gcc_sdm845_clocks[GCC_LPASS_Q6_AXI_CLK] =
+   _lpass_q6_axi_clk.clkr;
+   gcc_sdm845_clocks[GCC_LPASS_SWAY_CLK] =
+   _lpass_sway_clk.clkr;
+   }
+
return qcom_cc_really_probe(pdev, _sdm845_desc, regmap);
 }
 
diff --git a/drivers/clk/qcom/lpasscc-sdm845.c 
b/drivers/clk/qcom/lpasscc-sdm845.c
new file mode 100644
index 000..72c3cce
--- /dev/null
+++ b/drivers/clk/qcom/lpasscc-sdm845.c
@@ -0,0 +1,195 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "clk-regmap.h"
+#include "clk-branch.h"
+#include "common.h"
+
+static struct clk_branch lpass_audio_wrapper_aon_clk = {
+   .halt_reg = 0x098,
+   .halt_check = BRANCH_VOTED,
+   .clkr = {
+   .enable_reg = 0x098,
+   .enable_mask = BIT(0),
+   .hw.init = &(struct clk_init_data){
+   .name = "lpass_audio_wrapper_aon_clk",
+   .ops = _branch2_ops,
+   },
+   },
+};
+
+static struct clk_branch lpass_q6ss_ahbm_aon_clk = {
+   .halt_reg = 0x12000,
+   .halt_check = BRANCH_VOTED,
+   .clkr = {
+   .enable_reg = 0x12000,
+   

[PATCH v5 1/2] dt-bindings: clock: Introduce QCOM LPASS clock bindings

2018-09-18 Thread Taniya Das
Add device tree bindings for Low Power Audio subsystem clock controller for
Qualcomm Technology Inc's SDM845 SoCs.

Signed-off-by: Taniya Das 
---
 .../devicetree/bindings/clock/qcom,gcc.txt |  2 ++
 .../devicetree/bindings/clock/qcom,lpasscc.txt | 35 ++
 include/dt-bindings/clock/qcom,gcc-sdm845.h|  2 ++
 include/dt-bindings/clock/qcom,lpass-sdm845.h  | 16 ++
 4 files changed, 55 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/qcom,lpasscc.txt
 create mode 100644 include/dt-bindings/clock/qcom,lpass-sdm845.h

diff --git a/Documentation/devicetree/bindings/clock/qcom,gcc.txt 
b/Documentation/devicetree/bindings/clock/qcom,gcc.txt
index 664ea1f..b3ff6e8 100644
--- a/Documentation/devicetree/bindings/clock/qcom,gcc.txt
+++ b/Documentation/devicetree/bindings/clock/qcom,gcc.txt
@@ -32,6 +32,8 @@ be part of GCC and hence the TSENS properties can also be
 part of the GCC/clock-controller node.
 For more details on the TSENS properties please refer
 Documentation/devicetree/bindings/thermal/qcom-tsens.txt
+- qcom,lpass-protected : Indicate that the LPASS clock branches within GCC are
+unusable due to firmware access control restrictions.
 
 Example:
clock-controller@90 {
diff --git a/Documentation/devicetree/bindings/clock/qcom,lpasscc.txt 
b/Documentation/devicetree/bindings/clock/qcom,lpasscc.txt
new file mode 100644
index 000..6a718c8
--- /dev/null
+++ b/Documentation/devicetree/bindings/clock/qcom,lpasscc.txt
@@ -0,0 +1,35 @@
+Qualcomm LPASS Clock Controller Binding
+---
+
+Required properties :
+- compatible   : shall contain "qcom,sdm845-lpasscc"
+- #clock-cells : from common clock binding, shall contain 1.
+- reg  : shall contain base register address and size,
+ in the order
+   Index-0 maps to LPASS_CC register region
+   Index-1 maps to LPASS_QDSP6SS register region
+
+Optional properties :
+- reg-names: register names of LPASS domain
+"cc", "qdsp6ss".
+
+Example:
+
+The below node has to be defined in the cases where the LPASS peripheral loader
+would bring the subsystem out of reset.
+
+   lpasscc: clock-controller@17014000 {
+   compatible = "qcom,sdm845-lpasscc";
+   reg = <0x17014000 0x1f004>, <0x1730 0x200>;
+   reg-names = "cc", "qdsp6ss";
+   #clock-cells = <1>;
+   };
+
+   gcc: clock-controller@10 {
+   reg = <0x10 0x4000>;
+   compatible = "qcom,gcc-sdm845";
+   qcom,lpass-protected;
+   #clock-cells = <1>;
+   #reset-cells = <1>;
+   #power-domain-cells = <1>;
+   };
diff --git a/include/dt-bindings/clock/qcom,gcc-sdm845.h 
b/include/dt-bindings/clock/qcom,gcc-sdm845.h
index b8eae5a..968fa65 100644
--- a/include/dt-bindings/clock/qcom,gcc-sdm845.h
+++ b/include/dt-bindings/clock/qcom,gcc-sdm845.h
@@ -197,6 +197,8 @@
 #define GCC_QSPI_CORE_CLK_SRC  187
 #define GCC_QSPI_CORE_CLK  188
 #define GCC_QSPI_CNOC_PERIPH_AHB_CLK   189
+#define GCC_LPASS_Q6_AXI_CLK   190
+#define GCC_LPASS_SWAY_CLK 191
 
 /* GCC Resets */
 #define GCC_MMSS_BCR   0
diff --git a/include/dt-bindings/clock/qcom,lpass-sdm845.h 
b/include/dt-bindings/clock/qcom,lpass-sdm845.h
new file mode 100644
index 000..015968e
--- /dev/null
+++ b/include/dt-bindings/clock/qcom,lpass-sdm845.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2018, The Linux Foundation. All rights reserved.
+ */
+
+#ifndef _DT_BINDINGS_CLK_SDM_LPASS_SDM845_H
+#define _DT_BINDINGS_CLK_SDM_LPASS_SDM845_H
+
+#define LPASS_AUDIO_WRAPPER_AON_CLK0
+#define LPASS_Q6SS_AHBM_AON_CLK1
+#define LPASS_Q6SS_AHBS_AON_CLK2
+#define LPASS_QDSP6SS_XO_CLK   3
+#define LPASS_QDSP6SS_SLEEP_CLK4
+#define LPASS_QDSP6SS_CORE_CLK 5
+
+#endif
-- 
Qualcomm INDIA, on behalf of Qualcomm Innovation Center, Inc.is a member
of the Code Aurora Forum, hosted by the  Linux Foundation.



[PATCH v2 6/8] staging: rtl8188eu: add missing spaces around operators

2018-09-18 Thread Michael Straube
Add missing spaces around '|', '-', and '&' to follow kernel coding
style. Reported by checkpatch.

Signed-off-by: Michael Straube 
---
 drivers/staging/rtl8188eu/core/rtw_ioctl_set.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c 
b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
index db983f15ddd6..d6d6a232c4ec 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
@@ -141,7 +141,7 @@ u8 rtw_set_802_11_bssid(struct adapter *padapter, u8 *bssid)
else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
goto release_mlme_lock;
 
-   if (check_fwstate(pmlmepriv, _FW_LINKED|WIFI_ADHOC_MASTER_STATE)) {
+   if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE)) {
RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_, ("set_bssid: 
_FW_LINKED||WIFI_ADHOC_MASTER_STATE\n"));
 
if (!memcmp(>cur_network.network.MacAddress, bssid, 
ETH_ALEN)) {
@@ -225,7 +225,7 @@ u8 rtw_set_802_11_ssid(struct adapter *padapter, struct 
ndis_802_11_ssid *ssid)
else if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
goto release_mlme_lock;
 
-   if (check_fwstate(pmlmepriv, _FW_LINKED|WIFI_ADHOC_MASTER_STATE)) {
+   if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE)) {
RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
 ("set_ssid: _FW_LINKED||WIFI_ADHOC_MASTER_STATE\n"));
 
@@ -409,14 +409,14 @@ u8 rtw_set_802_11_bssid_list_scan(struct adapter 
*padapter, struct ndis_802_11_s
goto exit;
}
 
-   if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING) ||
+   if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING) ||
pmlmepriv->LinkDetectInfo.bBusyTraffic) {
/*  Scan or linking is in progress, do nothing. */
RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_, ("%s fail 
since fw_state = %x\n", __func__, get_fwstate(pmlmepriv)));
res = true;
 
if (check_fwstate(pmlmepriv,
- _FW_UNDER_SURVEY|_FW_UNDER_LINKING))
+ _FW_UNDER_SURVEY | _FW_UNDER_LINKING))
RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_, 
("\n###_FW_UNDER_SURVEY|_FW_UNDER_LINKING\n\n"));
else
RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_err_, 
("\n###pmlmepriv->sitesurveyctrl.traffic_busy == true\n\n"));
@@ -550,8 +550,8 @@ u16 rtw_get_cur_max_rate(struct adapter *adapter)
!check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE))
return 0;
 
-   if (pmlmeext->cur_wireless_mode & (WIRELESS_11_24N|WIRELESS_11_5N)) {
-   p = rtw_get_ie(_bss->ies[12], _HT_CAPABILITY_IE_, 
_ielen, pcur_bss->ie_length-12);
+   if (pmlmeext->cur_wireless_mode & (WIRELESS_11_24N | WIRELESS_11_5N)) {
+   p = rtw_get_ie(_bss->ies[12], _HT_CAPABILITY_IE_, 
_ielen, pcur_bss->ie_length - 12);
if (p && ht_ielen > 0) {
/* cur_bwmod is updated by beacon, pmlmeinfo is updated 
by association response */
bw_40MHz = (pmlmeext->cur_bwmode && 
(HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH & pmlmeinfo->HT_info.infos[0])) ? 1 : 0;
@@ -569,7 +569,7 @@ u16 rtw_get_cur_max_rate(struct adapter *adapter)
}
} else {
while (pcur_bss->SupportedRates[i] != 0 && 
pcur_bss->SupportedRates[i] != 0xFF) {
-   rate = pcur_bss->SupportedRates[i]&0x7F;
+   rate = pcur_bss->SupportedRates[i] & 0x7F;
if (rate > max_rate)
max_rate = rate;
i++;
-- 
2.19.0



[PATCH v2 7/8] staging: rtl8188eu: fix lines over 80 characters

2018-09-18 Thread Michael Straube
Wrap lines over 80 characters where appropriate to
clear checkpatch warnings.

Signed-off-by: Michael Straube 
---
 drivers/staging/rtl8188eu/core/rtw_ioctl_set.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c 
b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
index d6d6a232c4ec..c291d3a0fdcc 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
@@ -339,7 +339,8 @@ u8 rtw_set_802_11_infrastructure_mode(struct adapter 
*padapter,
check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE))
rtw_free_assoc_resources(padapter);
 
-   if (*pold_state == Ndis802_11Infrastructure || *pold_state == 
Ndis802_11IBSS) {
+   if (*pold_state == Ndis802_11Infrastructure ||
+   *pold_state == Ndis802_11IBSS) {
if (check_fwstate(pmlmepriv, _FW_LINKED))
rtw_indicate_disconnect(padapter); /* will clr 
Linked_state; before this function, we must have checked whether  issue 
dis-assoc_cmd or not */
   }
@@ -444,7 +445,8 @@ u8 rtw_set_802_11_authentication_mode(struct adapter 
*padapter, enum ndis_802_11
int res;
u8 ret;
 
-   RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_, 
("set_802_11_auth.mode(): mode =%x\n", authmode));
+   RT_TRACE(_module_rtl871x_ioctl_set_c_, _drv_info_,
+("set_802_11_auth.mode(): mode =%x\n", authmode));
 
psecuritypriv->ndisauthtype = authmode;
 
@@ -497,7 +499,8 @@ u8 rtw_set_802_11_add_wep(struct adapter *padapter, struct 
ndis_802_11_wep *wep)
 ("rtw_set_802_11_add_wep:before memcpy, wep->KeyLength = 0x%x 
wep->KeyIndex = 0x%x  keyid =%x\n",
 wep->KeyLength, wep->KeyIndex, keyid));
 
-   memcpy(>dot11DefKey[keyid].skey[0], >KeyMaterial, 
wep->KeyLength);
+   memcpy(>dot11DefKey[keyid].skey[0],
+  >KeyMaterial, wep->KeyLength);
 
psecuritypriv->dot11DefKeylen[keyid] = wep->KeyLength;
 
@@ -551,7 +554,8 @@ u16 rtw_get_cur_max_rate(struct adapter *adapter)
return 0;
 
if (pmlmeext->cur_wireless_mode & (WIRELESS_11_24N | WIRELESS_11_5N)) {
-   p = rtw_get_ie(_bss->ies[12], _HT_CAPABILITY_IE_, 
_ielen, pcur_bss->ie_length - 12);
+   p = rtw_get_ie(_bss->ies[12], _HT_CAPABILITY_IE_,
+  _ielen, pcur_bss->ie_length - 12);
if (p && ht_ielen > 0) {
/* cur_bwmod is updated by beacon, pmlmeinfo is updated 
by association response */
bw_40MHz = (pmlmeext->cur_bwmode && 
(HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH & pmlmeinfo->HT_info.infos[0])) ? 1 : 0;
@@ -568,7 +572,8 @@ u16 rtw_get_cur_max_rate(struct adapter *adapter)
);
}
} else {
-   while (pcur_bss->SupportedRates[i] != 0 && 
pcur_bss->SupportedRates[i] != 0xFF) {
+   while (pcur_bss->SupportedRates[i] != 0 &&
+  pcur_bss->SupportedRates[i] != 0xFF) {
rate = pcur_bss->SupportedRates[i] & 0x7F;
if (rate > max_rate)
max_rate = rate;
-- 
2.19.0



[PATCH v2 8/8] staging: rtl8188eu: simplify function comments

2018-09-18 Thread Michael Straube
Simplify function comments to a single line.

Signed-off-by: Michael Straube 
---
 drivers/staging/rtl8188eu/core/rtw_ioctl_set.c | 15 ++-
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c 
b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
index c291d3a0fdcc..0b3eb0b40975 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
@@ -530,12 +530,7 @@ u8 rtw_set_802_11_add_wep(struct adapter *padapter, struct 
ndis_802_11_wep *wep)
return ret;
 }
 
-/*
-* rtw_get_cur_max_rate -
-* @adapter: pointer to struct adapter structure
-*
-* Return 0 or 100Kbps
-*/
+/* Return 0 or 100Kbps */
 u16 rtw_get_cur_max_rate(struct adapter *adapter)
 {
int i = 0;
@@ -586,13 +581,7 @@ u16 rtw_get_cur_max_rate(struct adapter *adapter)
return max_rate;
 }
 
-/*
-* rtw_set_country -
-* @adapter: pointer to struct adapter structure
-* @country_code: string of country code
-*
-* Return _SUCCESS or _FAIL
-*/
+/* Return _SUCCESS or _FAIL */
 int rtw_set_country(struct adapter *adapter, const char *country_code)
 {
int i;
-- 
2.19.0



[PATCH v2 1/8] staging: rtl8188eu: simplify calculation

2018-09-18 Thread Michael Straube
Simplify calcualation:  * 10 / 2  can be reduced to  * 5
Also cleans missing spaces checkpatch issues.

Signed-off-by: Michael Straube 
---
changes in v2: fixed typo in patch 1/8 commit message
   Simpliy -> Simplify

 drivers/staging/rtl8188eu/core/rtw_ioctl_set.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c 
b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
index c040f185074b..0880f18520a0 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
@@ -575,7 +575,7 @@ u16 rtw_get_cur_max_rate(struct adapter *adapter)
i++;
}
 
-   max_rate = max_rate*10/2;
+   max_rate *= 5;
}
 
return max_rate;
-- 
2.19.0



Re: [PATCH 08/19] vmw_balloon: refactor change size from vmballoon_work

2018-09-18 Thread kbuild test robot
Hi Nadav,

I love your patch! Perhaps something to improve:

[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on v4.19-rc4 next-20180913]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Nadav-Amit/vmw_balloon-compaction-shrinker-64-bit-etc/20180918-152302
config: x86_64-randconfig-x007-201837 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All warnings (new ones prefixed by >>):

   In file included from include/linux/export.h:45:0,
from include/linux/linkage.h:7,
from include/linux/kernel.h:7,
from drivers/misc/vmw_balloon.c:20:
   drivers/misc/vmw_balloon.c: In function 'vmballoon_change.isra.2':
   include/linux/compiler.h:358:38: error: call to '__compiletime_assert_659' 
declared with attribute error: BUILD_BUG failed
 _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
 ^
   include/linux/compiler.h:69:16: note: in definition of macro '__trace_if'
  __r = !!(cond); \
   ^~~~
>> drivers/misc/vmw_balloon.c:659:2: note: in expansion of macro 'if'
 if (target < size && size - target < HPAGE_PMD_NR && target != 0)
 ^~
   include/linux/compiler.h:346:2: note: in expansion of macro 
'__compiletime_assert'
 __compiletime_assert(condition, msg, prefix, suffix)
 ^~~~
   include/linux/compiler.h:358:2: note: in expansion of macro 
'_compiletime_assert'
 _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
 ^~~
   include/linux/build_bug.h:45:37: note: in expansion of macro 
'compiletime_assert'
#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
^~
   include/linux/build_bug.h:79:21: note: in expansion of macro 
'BUILD_BUG_ON_MSG'
#define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed")
^~~~
   include/linux/huge_mm.h:250:28: note: in expansion of macro 'BUILD_BUG'
#define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
   ^
   include/linux/huge_mm.h:80:26: note: in expansion of macro 'HPAGE_PMD_SHIFT'
#define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT)
 ^~~
   include/linux/huge_mm.h:81:26: note: in expansion of macro 'HPAGE_PMD_ORDER'
#define HPAGE_PMD_NR (1<size;
   648  target = b->target;
   649  
   650  /*
   651   * We must cast first because of int sizes
   652   * Otherwise we might get huge positives instead of negatives
   653   */
   654  
   655  if (b->reset_required)
   656  return 0;
   657  
   658  /* consider a 2MB slack on deflate, unless the balloon is 
emptied */
 > 659  if (target < size && size - target < HPAGE_PMD_NR && target != 
 > 0)
   660  return 0;
   661  
   662  return target - size;
   663  }
   664  

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


[PATCH v6 2/2] iio: proximity: vl53l0x: add interrupt support

2018-09-18 Thread Song Qiang
The first version of this driver issues a measuring request and polling
for a status register in the device for measuring completes.
vl53l0x support configuring GPIO1 on it to generate interrupt to
indicate that new measurement is ready. This patch adds support for
using this mechanisim to reduce cpu cost.

Signed-off-by: Song Qiang 
---
 .../bindings/iio/proximity/vl53l0x.txt|  14 +-
 drivers/iio/proximity/vl53l0x-i2c.c   | 135 +++---
 2 files changed, 129 insertions(+), 20 deletions(-)

diff --git a/Documentation/devicetree/bindings/iio/proximity/vl53l0x.txt 
b/Documentation/devicetree/bindings/iio/proximity/vl53l0x.txt
index ab9a9539fec4..40290f8dd70f 100644
--- a/Documentation/devicetree/bindings/iio/proximity/vl53l0x.txt
+++ b/Documentation/devicetree/bindings/iio/proximity/vl53l0x.txt
@@ -4,9 +4,21 @@ Required properties:
- compatible: must be "st,vl53l0x-i2c"
- reg: i2c address where to find the device
 
+Optional properties:
+   - interrupts : Interrupt line receiving GPIO1's measuring complete
+ output, supports IRQ_TYPE_EDGE_FALLING only.
+
+   Refer to interrupt-controller/interrupts.txt for generic
+   interrupt client node bindings.
+
 Example:
 
 vl53l0x@29 {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins>;
+
compatible = "st,vl53l0x-i2c";
reg = <0x29>;
-};
+   interrupt-parent = <>;
+   interrupts = <17 IRQ_TYPE_EDGE_FALLING>;
+}
diff --git a/drivers/iio/proximity/vl53l0x-i2c.c 
b/drivers/iio/proximity/vl53l0x-i2c.c
index 1aad45df8d95..a5cff11f41de 100644
--- a/drivers/iio/proximity/vl53l0x-i2c.c
+++ b/drivers/iio/proximity/vl53l0x-i2c.c
@@ -10,18 +10,21 @@
  *
  * Default 7-bit i2c slave address 0x29.
  *
- * TODO: FIFO buffer, continuous mode, interrupts, range selection,
- * sensor ID check.
+ * TODO: FIFO buffer, continuous mode, range selection.
  */
 
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
+#include 
+
 #define VL_REG_SYSRANGE_START  0x00
 
+/* Mode configuration registers. */
 #define VL_REG_SYSRANGE_MODE_MASK  GENMASK(3, 0)
 #define VL_REG_SYSRANGE_MODE_SINGLESHOT0x00
 #define VL_REG_SYSRANGE_MODE_START_STOPBIT(0)
@@ -29,14 +32,61 @@
 #define VL_REG_SYSRANGE_MODE_TIMED BIT(2)
 #define VL_REG_SYSRANGE_MODE_HISTOGRAM BIT(3)
 
+/* Result registers. */
 #define VL_REG_RESULT_INT_STATUS   0x13
 #define VL_REG_RESULT_RANGE_STATUS 0x14
 #define VL_REG_RESULT_RANGE_STATUS_COMPLETEBIT(0)
 
+/* GPIO function configuration registers. */
+#define VL_REG_GPIO_HV_MUX_ACTIVE_GIGH 0x84
+#define VL_REG_SYS_INT_CFG_GPIO0x0A
+#define VL_GPIOFUNC_NEW_MEASURE_RDYBIT(2)
+
+/* Interrupt configuration registers. */
+#define VL_REG_SYS_INT_CLEAR   0x0B
+#define VL_REG_RESULT_INT_STATUS   0x13
+#define VL_INT_POLARITY_LOW0x00
+#define VL_INT_POLARITY_HIGH   BIT(0)
+
+/* Should be 0xEE if connection is fine. */
+#define VL_REG_MODEL_ID0xC0
+
 struct vl53l0x_data {
struct i2c_client *client;
+   struct completion measuring_done;
+   bool use_interrupt;
 };
 
+static int vl53l0x_clear_interrupt(struct vl53l0x_data *data)
+{
+   int ret;
+   u8 cnt = 0;
+
+   do {
+   /* bit 0 for measuring interrupt, bit 1 for error interrupt.  */
+   i2c_smbus_write_byte_data(data->client,
+   VL_REG_SYS_INT_CLEAR, 1);
+   i2c_smbus_write_byte_data(data->client,
+   VL_REG_SYS_INT_CLEAR, 0);
+   ret = i2c_smbus_read_byte_data(data->client,
+   VL_REG_RESULT_INT_STATUS);
+   cnt++;
+   } while ((ret & 0x07) && (cnt < 3));
+   if (cnt > 2)
+   return -ETIMEDOUT;
+   else
+   return 0;
+}
+
+static irqreturn_t vl53l0x_irq_handler(int irq, void *d)
+{
+   struct vl53l0x_data *data = d;
+
+   complete(>measuring_done);
+
+   return IRQ_HANDLED;
+}
+
 static int vl53l0x_read_proximity(struct vl53l0x_data *data,
  const struct iio_chan_spec *chan,
  int *val)
@@ -46,23 +96,31 @@ static int vl53l0x_read_proximity(struct vl53l0x_data *data,
u8 buffer[12];
int ret;
 
-   ret = i2c_smbus_write_byte_data(client, VL_REG_SYSRANGE_START, 1);
-   if (ret < 0)
-   return ret;
-
-   do {
-   ret = i2c_smbus_read_byte_data(client,
-   VL_REG_RESULT_RANGE_STATUS);
-   if (ret < 0)
-   return ret;
-
-   if (ret & VL_REG_RESULT_RANGE_STATUS_COMPLETE)
-   break;
-

[PATCH v6 1/2] iio: proximity: Add driver support for ST's VL53L0X ToF ranging sensor.

2018-09-18 Thread Song Qiang
This driver was originally written by ST in 2016 as a misc input device
driver, and hasn't been maintained for a long time. I grabbed some code
from it's API and reformed it into an iio proximity device driver.
This version of driver uses i2c bus to talk to the sensor and
polling for measuring completes, so no irq line is needed.
It can be tested with reading from
/sys/bus/iio/devices/iio:deviceX/in_distance_input

Signed-off-by: Song Qiang 
---
Changes in v6:
- Remove '.' in mail address. Google doesn't care, these two
  email address is the same when I log in.
- Clean register table.
- Put some seperated statements into one line.
- Change channel type to *_PROCESSED.
- Remove some unneccessary dev_err.
- changes iio device name to vl53l0x.

Changes in v5:
- Correct some spell problems.
- Change tries-- to --tries to fix the count error.
- Add MODULE_DEVICE_TABLE().
- Add some comments.

Changes in v4:
- Add datasheet link, default i2c address and TODO list.
- Make capitalization of defines consistent.
- Replace i2c_transfer() with i2c_smbus_read_i2c_block_data().
- Remove IIO_CHAN_SOFT_TIMESTAMP() since no buffer/trigger
  support.
- Add information to MAINTAINERS.

Changes in v3:
- Recover ST's copyright.
- Clean up indio_dev member in vl53l0x_data struct since it's
  useless now.
- Replace __le16_to_cpu() with le16_to_cpu().
- Remove the iio_device_{claim|release}_direct_mode() since it's
  only needed when we use buffered mode.
- Clean up some coding style problems.

Changes in v2:
- Clean up the register table.
- Sort header files declarations.
- Replace some bit definations with GENMASK() and BIT().
- Clean up some code and comments that's useless for now.
- Change the order of some the definations of some variables to reversed
  xmas tree order.
- Using do...while() rather while and check.
- Replace pr_err() with dev_err().
- Remove device id declaration since we recommend to use DT.
- Remove .owner = THIS_MODULE.
- Replace probe() with probe_new() hook.
- Remove IIO_BUFFER and IIO_TRIGGERED_BUFFER dependences.
- Change the driver module name to vl53l0x-i2c.
- Align all the parameters if they are in the same function with open
  parentheses.
- Replace iio_device_register() with devm_iio_device_register
  for better resource management.
- Remove the vl53l0x_remove() since it's not needed.
- Remove dev_set_drvdata() since it's already setted above.

 .../bindings/iio/proximity/vl53l0x.txt|  12 ++
 MAINTAINERS   |   7 +
 drivers/iio/proximity/Kconfig |  11 ++
 drivers/iio/proximity/Makefile|   2 +
 drivers/iio/proximity/vl53l0x-i2c.c   | 157 ++
 5 files changed, 189 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/proximity/vl53l0x.txt
 create mode 100644 drivers/iio/proximity/vl53l0x-i2c.c

diff --git a/Documentation/devicetree/bindings/iio/proximity/vl53l0x.txt 
b/Documentation/devicetree/bindings/iio/proximity/vl53l0x.txt
new file mode 100644
index ..ab9a9539fec4
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/proximity/vl53l0x.txt
@@ -0,0 +1,12 @@
+ST VL53L0X ToF ranging sensor
+
+Required properties:
+   - compatible: must be "st,vl53l0x-i2c"
+   - reg: i2c address where to find the device
+
+Example:
+
+vl53l0x@29 {
+   compatible = "st,vl53l0x-i2c";
+   reg = <0x29>;
+};
diff --git a/MAINTAINERS b/MAINTAINERS
index 967ce8cdd1cc..349e2bc97cec 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13510,6 +13510,13 @@ L: linux-...@vger.kernel.org
 S: Maintained
 F: drivers/i2c/busses/i2c-stm32*
 
+ST VL53L0X ToF RANGER(I2C) IIO DRIVER
+M: Song Qiang 
+L: linux-...@vger.kernel.org
+S: Maintained
+F: drivers/iio/proximity/vl53l0x-i2c.c
+F: Documentation/devicetree/bindings/iio/proximity/vl53l0x.txt
+
 STABLE BRANCH
 M: Greg Kroah-Hartman 
 L: sta...@vger.kernel.org
diff --git a/drivers/iio/proximity/Kconfig b/drivers/iio/proximity/Kconfig
index f726f9427602..5f421cbd37f3 100644
--- a/drivers/iio/proximity/Kconfig
+++ b/drivers/iio/proximity/Kconfig
@@ -79,4 +79,15 @@ config SRF08
  To compile this driver as a module, choose M here: the
  module will be called srf08.
 
+config VL53L0X_I2C
+   tristate "STMicroelectronics VL53L0X ToF ranger sensor (I2C)"
+   depends on I2C
+   help
+ Say Y here to build a driver for STMicroelectronics VL53L0X
+ ToF ranger sensors with i2c interface.
+ This driver can be used to measure the distance of objects.
+
+ To compile this driver as a module, choose M here: the
+ module 

Re: [PATCH v2 1/5] spi: spi-mem: Add driver for NXP FlexSPI controller

2018-09-18 Thread Frieder Schrempf

Hi Boris, Yogesh,

On 17.09.2018 13:37, Boris Brezillon wrote:

Hi Yogesh,

On Mon, 17 Sep 2018 15:18:26 +0530
Yogesh Gaur  wrote:


+
+   /*
+* R/W functions for big- or little-endian registers:
+* The FSPI controller's endianness is independent of
+* the CPU core's endianness. So far, although the CPU
+* core is little-endian the FSPI controller can use
+* big-endian or little-endian.
+*/
+   if (of_property_read_bool(np, "big-endian")) {
+   f->write = fspi_writel_be;
+   f->read = fspi_readl_be;
+   } else {
+   f->write = fspi_writel;
+   f->read = fspi_readl;
+   }


Hm, isn't it something you can extract from the compatible string? I'd
rather not allow users to set that in their DT if it's not something
you can change.


This was copied from the QSPI driver, but I think Boris is right. This 
seems to be a fixed SOC-specific setting and we shouldn't set it in the 
DT. This applies to QSPI and FSPI alike.


Regards,
Frieder



Regards,

Boris



Re: [PATCH] ASoC: remove redundant include

2018-09-18 Thread Charles Keepax
On Tue, Sep 18, 2018 at 04:16:24PM +0800, zhong jiang wrote:
> module.h already contained moduleparam.h,  so it is safe to remove
> the redundant include.
> 
> The issue is detected with the help of Coccinelle.
> 
> Signed-off-by: zhong jiang 
> ---

For the Wolfson bits:

Acked-by: Charles Keepax 

Thanks,
Charles


Re: [PATCH] misc: remove redundant include moduleparam.h

2018-09-18 Thread Greg KH
On Tue, Sep 18, 2018 at 04:34:42PM +0800, zhong jiang wrote:
> module.h already contains moduleparam.h,  so it is safe to remove
> the redundant include.
> 
> The issue is detected with the help of Coccinelle.
> 
> eePlease enter the commit message for your changes. Lines starting

Odd line to have in a changelog text :)

Please fix up and resend.

tanks,

greg k-h


Re: [RFC/PATCH 4/5] gpiolib: add support for fetching descriptors from static properties

2018-09-18 Thread Mika Westerberg
Hi,

On Mon, Sep 17, 2018 at 11:16:02AM -0700, Dmitry Torokhov wrote:
> Now that static device properties understand notion of child nodes, let's
> teach gpiolib to tie such children and machine GPIO descriptor tables.
> We will continue using a single table for entire device, but instead of
> using connection ID as a lookup key in the GPIO descriptor table directly,
> we will perform additional translation: fwnode_get_named_gpiod() when
> dealing with property_set-backed fwnodes will try parsing string property
> with name matching connection ID and use result of the lookup as the key in
> the table:
> 
> static const struct property_entry dev_child1_props[] __initconst = {
>   ...
>   PROPERTY_ENTRY_STRING("gpios",  "child-1-gpios"),
>   { }
> };
> 
> static struct gpiod_lookup_table dev_gpiod_table = {
>   .dev_id = "some-device",
>   .table = {
>   ...
>   GPIO_LOOKUP_IDX("B", 1, "child-1-gpios", 1, GPIO_ACTIVE_LOW),
>   ...
>   },
> };

I wonder if instead of passing and parsing strings (and hoping there are
no typos) we could get the compiler to help us bit more?

Something like below:

static const struct property_entry dev_child1_props[] __initconst = {
...
PROPERTY_ENTRY_STRING("gpios","child-1-gpios"),
{ }
};
 
static struct gpiod_lookup_table dev_gpiod_table = {
.dev_id = "some-device",
.table = {
...
GPIO_LOOKUP_IDX("B", 1, dev_child1_props, 
SIZEOF(dev_child1_props),
1, GPIO_ACTIVE_LOW),
...
},
};


Re: [PATCH 14/33] vfs: Implement a filesystem superblock creation/configuration context [ver #11]

2018-09-18 Thread Sergey Senozhatsky
Hi,

On (09/11/18 16:54), Guenter Roeck wrote:
> On Wed, Sep 12, 2018 at 12:17:35AM +0100, David Howells wrote:
> > Guenter Roeck  wrote:
> > 
> > > [8.507672] RIP: 0010:reconfigure_super+0x47/0x210
> > 
> > Can you tell me the file and line this corresponds to?
> > 
> I don't know, but some debugging shows that fc->ops == NULL.

This NULL derefs linux-next.

Emergency (sysrq remount/reboot):

emergency_remount()
 do_emergency_remount()
  do_emergency_remount_callback()
   reconfigure_super()

At fc->ops dereference:

 981 if (fc->ops->reconfigure) {
^
 982 retval = fc->ops->reconfigure(fc);
 983 if (retval == 0) {
 984 security_sb_reconfigure(fc);


So the check either better be

if (fc->ops && fc->ops->reconfigure)

Or, we need to set ->ops properly. But I'm not sure if invoking
->init_fs_context() from emergency-reboot path is going to work
well all the time.

---

 fs/super.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/super.c b/fs/super.c
index efb0567c8389..e2e03c47c817 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -1017,6 +1017,7 @@ int reconfigure_super(struct fs_context *fc)
 static void do_emergency_remount_callback(struct super_block *sb)
 {
struct fs_context fc = {
+   .ops= _fs_context_ops,
.purpose= FS_CONTEXT_FOR_EMERGENCY_RO,
.fs_type= sb->s_type,
.root   = sb->s_root,

---

-ss


Re: [PATCH] tty/sysrq: Make local variable 'killer' in sysrq_handle_crash() global

2018-09-18 Thread Greg Kroah-Hartman
On Tue, Sep 18, 2018 at 02:35:02PM +0530, Sai Prakash Ranjan wrote:
> On 9/18/2018 12:50 PM, Greg Kroah-Hartman wrote:
> > On Tue, Sep 18, 2018 at 12:28:39PM +0530, Sai Prakash Ranjan wrote:
> > > On 9/18/2018 11:41 AM, Jiri Slaby wrote:
> > > > On 09/17/2018, 11:33 PM, Matthias Kaehlcke wrote:
> > > > > sysrq_handle_crash() dereferences a NULL pointer on purpose to force
> > > > > an exception, the local variable 'killer' is assigned to NULL and
> > > > > dereferenced later. Clang detects the NULL pointer dereference at 
> > > > > compile
> > > > > time and emits a BRK instruction (on arm64) instead of the expected 
> > > > > NULL
> > > > > pointer exception. Change 'killer' to a global variable (and rename it
> > > > > to 'sysrq_killer' to avoid possible clashes) to prevent Clang from
> > > > > detecting the condition. By default global variables are initialized
> > > > > with zero/NULL in C, therefore an explicit initialization is not 
> > > > > needed.
> > > > > 
> > > > > Reported-by: Sai Prakash Ranjan 
> > > > > Suggested-by: Evan Green 
> > > > > Signed-off-by: Matthias Kaehlcke 
> > > > > ---
> > > > >drivers/tty/sysrq.c | 6 +++---
> > > > >1 file changed, 3 insertions(+), 3 deletions(-)
> > > > > 
> > > > > diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
> > > > > index 06ed20dd01ba..49fa8e758690 100644
> > > > > --- a/drivers/tty/sysrq.c
> > > > > +++ b/drivers/tty/sysrq.c
> > > > > @@ -132,10 +132,10 @@ static struct sysrq_key_op sysrq_unraw_op = {
> > > > >#define sysrq_unraw_op (*(struct sysrq_key_op *)NULL)
> > > > >#endif /* CONFIG_VT */
> > > > > +char *sysrq_killer;
> > > > > +
> > > > >static void sysrq_handle_crash(int key)
> > > > >{
> > > > > - char *killer = NULL;
> > > > > -
> > > > >   /* we need to release the RCU read lock here,
> > > > >* otherwise we get an annoying
> > > > >* 'BUG: sleeping function called from invalid context'
> > > > > @@ -144,7 +144,7 @@ static void sysrq_handle_crash(int key)
> > > > >   rcu_read_unlock();
> > > > >   panic_on_oops = 1;  /* force panic */
> > > > >   wmb();
> > > > > - *killer = 1;
> > > > > + *sysrq_killer = 1;
> > > > 
> > > > Just because a static analyzer is wrong? Oh wait, even compiler is
> > > > wrong. At least make it a static global. Or what about 
> > > > OPTIMIZER_HIDE_VAR?
> > > > 
> > > 
> > > static global does not work, clang still inserts brk. As for
> > > OPTIMIZE_HIDE_VAR, it seems to work.
> > > But, I dont think it is defined for clang in which case it defaults to 
> > > using
> > > barrier(). There is already one wmb(), so will it be right?
> > 
> > Ick, why is this needed at all?  Why are we trying to "roll our own
> > panic" in this code?
> > 
> 
> Hi Greg, do you mean like why there is a killer var at all or why this
> change is required?

I understand you are using a compiler that thinks it wants to protect
yourself from your code and tries to "fix" it for you.  That's fine, and
is up to the compiler writers (personally that seems not a good idea.)

My question is why we just don't call panic() here instead of trying to
duplicate the logic of that function here.  Why is that happening?

thanks,

greg k-h


Re: [PATCH] docs: fix some broken documentation references

2018-09-18 Thread Jan Kara
On Mon 17-09-18 15:02:34, Mauro Carvalho Chehab wrote:
> Some documentation files received recent changes and are
> pointing to wrong places.
> 
> Those references can easily fixed with the help of a
> script:
> 
>   $ ./scripts/documentation-file-ref-check --fix
> 
> Signed-off-by: Mauro Carvalho Chehab 

Looks good to me. Thanks for fixing this up. You can add:

Reviewed-by: Jan Kara 

Honza
> ---
>  Documentation/filesystems/dax.txt  | 2 +-
>  Documentation/filesystems/ext2.txt | 2 +-
>  MAINTAINERS| 4 ++--
>  net/bridge/Kconfig | 2 +-
>  4 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/Documentation/filesystems/dax.txt 
> b/Documentation/filesystems/dax.txt
> index 70cb68bed2e8..bc393e0a22b8 100644
> --- a/Documentation/filesystems/dax.txt
> +++ b/Documentation/filesystems/dax.txt
> @@ -75,7 +75,7 @@ exposure of uninitialized data through mmap.
>  
>  These filesystems may be used for inspiration:
>  - ext2: see Documentation/filesystems/ext2.txt
> -- ext4: see Documentation/filesystems/ext4.txt
> +- ext4: see Documentation/filesystems/ext4/ext4.rst
>  - xfs:  see Documentation/filesystems/xfs.txt
>  
>  
> diff --git a/Documentation/filesystems/ext2.txt 
> b/Documentation/filesystems/ext2.txt
> index 81c0becab225..a45c9fc0747b 100644
> --- a/Documentation/filesystems/ext2.txt
> +++ b/Documentation/filesystems/ext2.txt
> @@ -358,7 +358,7 @@ and are copied into the filesystem.  If a transaction is 
> incomplete at
>  the time of the crash, then there is no guarantee of consistency for
>  the blocks in that transaction so they are discarded (which means any
>  filesystem changes they represent are also lost).
> -Check Documentation/filesystems/ext4.txt if you want to read more about
> +Check Documentation/filesystems/ext4/ext4.rst if you want to read more about
>  ext4 and journaling.
>  
>  References
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 9989925f658d..078a4cf6d064 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -840,7 +840,7 @@ ANALOG DEVICES INC ADGS1408 DRIVER
>  M:   Mircea Caprioru 
>  S:   Supported
>  F:   drivers/mux/adgs1408.c
> -F:   Documentation/devicetree/bindings/mux/adgs1408.txt
> +F:   Documentation/devicetree/bindings/mux/adi,adgs1408.txt
>  
>  ANALOG DEVICES INC ADP5061 DRIVER
>  M:   Stefan Popa 
> @@ -5515,7 +5515,7 @@ W:  http://ext4.wiki.kernel.org
>  Q:   http://patchwork.ozlabs.org/project/linux-ext4/list/
>  T:   git git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git
>  S:   Maintained
> -F:   Documentation/filesystems/ext4.txt
> +F:   Documentation/filesystems/ext4/ext4.rst
>  F:   fs/ext4/
>  
>  Extended Verification Module (EVM)
> diff --git a/net/bridge/Kconfig b/net/bridge/Kconfig
> index aa0d3b2f1bb7..3625d6ade45c 100644
> --- a/net/bridge/Kconfig
> +++ b/net/bridge/Kconfig
> @@ -17,7 +17,7 @@ config BRIDGE
> other third party bridge products.
>  
> In order to use the Ethernet bridge, you'll need the bridge
> -   configuration tools; see 
> +   configuration tools; see 
> for location. Please read the Bridge mini-HOWTO for more
> information.
>  
> -- 
> 2.17.1
> 
> 
-- 
Jan Kara 
SUSE Labs, CR


[PATCH 3/3] ARM: dspi: Provide support for DSPI slave more operation (Vybryd vf610)

2018-09-18 Thread Lukasz Majewski
The NXP's Vybryd vf610 can work as a SPI slave device (the CS and clock
signal are provided by master).

It is possible to specify a single device to work in that mode. As we do
use DMA for transferring data, the RX channel must be prepared for
incoming data.
Moreover, in slave mode we just set a subset of control fields in
configuration registers (CTAR0, PUSHR).

Signed-off-by: Lukasz Majewski 
---
 drivers/spi/spi-fsl-dspi.c | 40 
 1 file changed, 32 insertions(+), 8 deletions(-)

diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
index 472385f0a842..1d71f6fd2e0b 100644
--- a/drivers/spi/spi-fsl-dspi.c
+++ b/drivers/spi/spi-fsl-dspi.c
@@ -209,6 +209,14 @@ struct fsl_dspi {
struct fsl_dspi_dma *dma;
 };
 
+static inline bool dspi_slave_mode(struct fsl_dspi *dspi)
+{
+   if (!(dspi->cur_chip->mcr_val & SPI_MCR_MASTER))
+   return true;
+
+   return false;
+}
+
 static u32 dspi_pop_tx(struct fsl_dspi *dspi)
 {
u32 txdata = 0;
@@ -230,6 +238,9 @@ static u32 dspi_pop_tx_pushr(struct fsl_dspi *dspi)
 {
u16 cmd = dspi->tx_cmd, data = dspi_pop_tx(dspi);
 
+   if (dspi_slave_mode(dspi))
+   return data;
+
if (dspi->len > 0)
cmd |= SPI_PUSHR_CMD_CONT;
return cmd << 16 | data;
@@ -326,6 +337,11 @@ static int dspi_next_xfer_dma_submit(struct fsl_dspi *dspi)
dma_async_issue_pending(dma->chan_rx);
dma_async_issue_pending(dma->chan_tx);
 
+   if (dspi_slave_mode(dspi)) {
+   wait_for_completion_interruptible(>dma->cmd_rx_complete);
+   return 0;
+   }
+
time_left = wait_for_completion_timeout(>dma->cmd_tx_complete,
DMA_COMPLETION_TIMEOUT);
if (time_left == 0) {
@@ -781,6 +797,10 @@ static int dspi_setup(struct spi_device *spi)
 
of_property_read_u32(spi->dev.of_node, "fsl,spi-sck-cs-delay",
_cs_delay);
+
+   if (of_property_read_bool(spi->dev.of_node,
+ "fsl,spi-slave-mode"))
+   chip->mcr_val &= ~SPI_MCR_MASTER;
} else {
cs_sck_delay = pdata->cs_sck_delay;
sck_cs_delay = pdata->sck_cs_delay;
@@ -798,14 +818,18 @@ static int dspi_setup(struct spi_device *spi)
ns_delay_scale(, , sck_cs_delay, clkrate);
 
chip->ctar_val = SPI_CTAR_CPOL(spi->mode & SPI_CPOL ? 1 : 0)
-   | SPI_CTAR_CPHA(spi->mode & SPI_CPHA ? 1 : 0)
-   | SPI_CTAR_LSBFE(spi->mode & SPI_LSB_FIRST ? 1 : 0)
-   | SPI_CTAR_PCSSCK(pcssck)
-   | SPI_CTAR_CSSCK(cssck)
-   | SPI_CTAR_PASC(pasc)
-   | SPI_CTAR_ASC(asc)
-   | SPI_CTAR_PBR(pbr)
-   | SPI_CTAR_BR(br);
+   | SPI_CTAR_CPHA(spi->mode & SPI_CPHA ? 1 : 0);
+
+   if (chip->mcr_val & SPI_MCR_MASTER) {
+   chip->ctar_val |= SPI_CTAR_LSBFE(spi->mode &
+SPI_LSB_FIRST ? 1 : 0)
+   | SPI_CTAR_PCSSCK(pcssck)
+   | SPI_CTAR_CSSCK(cssck)
+   | SPI_CTAR_PASC(pasc)
+   | SPI_CTAR_ASC(asc)
+   | SPI_CTAR_PBR(pbr)
+   | SPI_CTAR_BR(br);
+   }
 
spi_set_ctldata(spi, chip);
 
-- 
2.11.0



Re: [PATCH v4] USB: serial: ftdi_sio: implement GPIO support for FT-X devices

2018-09-18 Thread Karoly Pados
>> + goto out_free;
>> +
>> + /* Chip-type guessing logic based on libftdi. */
>> + priv->gc.ngpio = 4; /* FT230X, FT231X */
>> + if (le16_to_cpu(serial->dev->descriptor.bcdDevice) != 0x1000)
>> + priv->gc.ngpio = 1; /* FT234XD */
> 
> As I mentioned in my last mail: I've asked FTDI about this, but I fear
> that FTX234XD has bcdDevice 0x1000 and we may need to just always
> register all four pins after all.
> 

To avoid missing 4.20, what is the latest time I should wait for FTDI's answer?
Or should I just submit v5 as it is now and you'll incorporate FTDI's feedback
when you receive it?


>> +static void ftdi_gpio_remove(struct usb_serial_port *port)
>> +{
>> + struct ftdi_private *priv = usb_get_serial_port_data(port);
>> +
>> + if (priv->gpio_used) {
>> + /* Remark: Exiting CBUS-mode does not reset pin states too */
>> + ftdi_exit_cbus_mode(port);
>> + priv->gpio_used = false;
>> + }
> 
> This should go after deregistration or we have a tiny race window here.

Can you elaborate on that to make sure I get it right? 
By "deregistration" do you mean deregistering the GPIO chip below in the same 
method?
Does that mean something can call into our module while this method is running?
If not, I'm clueless about the possible race here.


[PATCH 2/3] ARM: dspi: Provide per DSPI instance of the MCR register (SLAVE mode)

2018-09-18 Thread Lukasz Majewski
The vf610 Vybryd can work in two DSPI modes - namely master and slave.
Already we do support master mode.
This commit serves as a prerequisite to add support for slave mode. For
slave mode we do need to preserve the MCR register value to change its
"mode" bit (31) according to the supported state.

Signed-off-by: Lukasz Majewski 
---
 drivers/spi/spi-fsl-dspi.c | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
index 7cb3ab0a35a0..472385f0a842 100644
--- a/drivers/spi/spi-fsl-dspi.c
+++ b/drivers/spi/spi-fsl-dspi.c
@@ -126,6 +126,7 @@
 #define DMA_COMPLETION_TIMEOUT msecs_to_jiffies(3000)
 
 struct chip_data {
+   u32 mcr_val;
u32 ctar_val;
u16 void_write_data;
 };
@@ -696,9 +697,9 @@ static int dspi_transfer_one_message(struct spi_master 
*master,
else
dspi->bytes_per_word = 4;
 
-   regmap_update_bits(dspi->regmap, SPI_MCR,
-  SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF,
-  SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF);
+   regmap_write(dspi->regmap, SPI_MCR, dspi->cur_chip->mcr_val |
+SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF);
+
regmap_write(dspi->regmap, SPI_CTAR(0),
 dspi->cur_chip->ctar_val |
 SPI_FRAME_BITS(transfer->bits_per_word));
@@ -767,6 +768,11 @@ static int dspi_setup(struct spi_device *spi)
return -ENOMEM;
}
 
+   chip->mcr_val = SPI_MCR_MASTER | SPI_MCR_PCSIS;
+
+   if (dspi->devtype_data->xspi_mode)
+   chip->mcr_val |= SPI_MCR_XSPI;
+
pdata = dev_get_platdata(>pdev->dev);
 
if (!pdata) {
@@ -964,8 +970,6 @@ static const struct regmap_config dspi_xspi_regmap_config[] 
= {
 
 static void dspi_init(struct fsl_dspi *dspi)
 {
-   regmap_write(dspi->regmap, SPI_MCR, SPI_MCR_MASTER | SPI_MCR_PCSIS |
-(dspi->devtype_data->xspi_mode ? SPI_MCR_XSPI : 0));
regmap_write(dspi->regmap, SPI_SR, SPI_SR_CLEAR);
if (dspi->devtype_data->xspi_mode)
regmap_write(dspi->regmap, SPI_CTARE(0),
-- 
2.11.0



[PATCH 1/3] dt-bindings: spi: Provide bindings for fsl dspi working in slave mode

2018-09-18 Thread Lukasz Majewski
This commit provides the description of new property: "fsl,spi-slave-mode"
which enables support for DSPI driver working in slave mode.

As the new compatible shall be used with SPI bus equipped with master
device a new "spidev" based node has been introduced to avoid confusion.

Signed-off-by: Lukasz Majewski 
---
 Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt | 8 
 1 file changed, 8 insertions(+)

diff --git a/Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt 
b/Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt
index 18eeafe359d8..b30af19a2bc5 100644
--- a/Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt
+++ b/Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt
@@ -26,6 +26,7 @@ Optional SPI properties for slave nodes:
 - fsl,spi-sck-cs-delay: a delay in nanoseconds between stopping the clock
   signal and deactivating chip select, at the end of a transfer.
 - bus-num : the slave chip chipselect signal number.
+- fsl,spi-slave-mode: if present, controller runs in slave mode.
 
 Example:
 
@@ -56,6 +57,13 @@ dspi0@4002c000 {
fsl,spi-cs-sck-delay = <100>;
fsl,spi-sck-cs-delay = <50>;
};
+
+   spidev3@1 {
+   compatible = "fsl,vf610-dspi";
+   spi-max-frequency = <3000>;
+   reg = <1>;
+   fsl,spi-slave-mode;
+   };
 };
 
 
-- 
2.11.0



[PATCH 0/3] ARM: dspi: Provide slave mode support for Vybryd vf610

2018-09-18 Thread Lukasz Majewski
This patch series provides support for DSPI slave mode operation.
It tries to maximally reuse current DMA driver (including its limitations).

For testing the spidev_test program has been used.
Test script for this patch can be found here:
https://github.com/lmajewski/tests-spi/blob/master/tests/spi/spi_tests.sh

Lukasz Majewski (3):
  dt-bindings: spi: Provide bindings for fsl dspi working in slave mode
  ARM: dspi: Provide per DSPI instance of the MCR register (SLAVE mode)
  ARM: dspi: Provide support for DSPI slave more operation (Vybryd
vf610)

 .../devicetree/bindings/spi/spi-fsl-dspi.txt   |  8 
 drivers/spi/spi-fsl-dspi.c | 54 --
 2 files changed, 49 insertions(+), 13 deletions(-)

-- 
2.11.0



[PATCH v3 06/20] tpm: move tpm1_pcr_extend to tpm1-cmd.c

2018-09-18 Thread Tomas Winkler
Move tpm1_pcr_extend to tpm1-cmd.c and remove
unused pcrextend_header structure.

Fixes warning:
drivers/char/tpm/tpm-interface.c:609:38: warning: ‘pcrextend_header’ defined 
but not used [-Wunused-const-variable=]
 static const struct tpm_input_header pcrextend_header = {
  ^~~~
Signed-off-by: Tomas Winkler 
---
V2-V3: Rebase
 drivers/char/tpm/tpm-interface.c | 28 
 drivers/char/tpm/tpm.h   |  2 ++
 drivers/char/tpm/tpm1-cmd.c  | 22 ++
 3 files changed, 24 insertions(+), 28 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 55f9094a8f11..03134f2e1c39 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -604,34 +604,6 @@ int tpm_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 
*res_buf)
 }
 EXPORT_SYMBOL_GPL(tpm_pcr_read);
 
-#define TPM_ORD_PCR_EXTEND 20
-#define EXTEND_PCR_RESULT_SIZE 34
-#define EXTEND_PCR_RESULT_BODY_SIZE 20
-static const struct tpm_input_header pcrextend_header = {
-   .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
-   .length = cpu_to_be32(34),
-   .ordinal = cpu_to_be32(TPM_ORD_PCR_EXTEND)
-};
-
-static int tpm1_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash,
-  char *log_msg)
-{
-   struct tpm_buf buf;
-   int rc;
-
-   rc = tpm_buf_init(, TPM_TAG_RQU_COMMAND, TPM_ORD_PCR_EXTEND);
-   if (rc)
-   return rc;
-
-   tpm_buf_append_u32(, pcr_idx);
-   tpm_buf_append(, hash, TPM_DIGEST_SIZE);
-
-   rc = tpm_transmit_cmd(chip, NULL, buf.data, EXTEND_PCR_RESULT_SIZE,
- EXTEND_PCR_RESULT_BODY_SIZE, 0, log_msg);
-   tpm_buf_destroy();
-   return rc;
-}
-
 /**
  * tpm_pcr_extend - extend a PCR value in SHA1 bank.
  * @chip:  a  tpm_chip instance, %NULL for the default chip
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index a97d72fcda5b..3fb268f43955 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -549,6 +549,8 @@ int tpm_do_selftest(struct tpm_chip *chip);
 int tpm1_auto_startup(struct tpm_chip *chip);
 int tpm1_get_timeouts(struct tpm_chip *chip);
 unsigned long tpm1_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
+int tpm1_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash,
+   const char *log_msg);
 unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
 int tpm_pm_suspend(struct device *dev);
 int tpm_pm_resume(struct device *dev);
diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c
index cce2f83d90e3..5c441e1ad8a8 100644
--- a/drivers/char/tpm/tpm1-cmd.c
+++ b/drivers/char/tpm/tpm1-cmd.c
@@ -413,3 +413,25 @@ int tpm1_get_timeouts(struct tpm_chip *chip)
chip->flags |= TPM_CHIP_FLAG_HAVE_TIMEOUTS;
return 0;
 }
+
+#define TPM_ORD_PCR_EXTEND 20
+#define EXTEND_PCR_RESULT_SIZE 34
+#define EXTEND_PCR_RESULT_BODY_SIZE 20
+int tpm1_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash,
+   const char *log_msg)
+{
+   struct tpm_buf buf;
+   int rc;
+
+   rc = tpm_buf_init(, TPM_TAG_RQU_COMMAND, TPM_ORD_PCR_EXTEND);
+   if (rc)
+   return rc;
+
+   tpm_buf_append_u32(, pcr_idx);
+   tpm_buf_append(, hash, TPM_DIGEST_SIZE);
+
+   rc = tpm_transmit_cmd(chip, NULL, buf.data, EXTEND_PCR_RESULT_SIZE,
+ EXTEND_PCR_RESULT_BODY_SIZE, 0, log_msg);
+   tpm_buf_destroy();
+   return rc;
+}
-- 
2.14.4



[PATCH v3 11/20] tpm: factor out tpm_startup function

2018-09-18 Thread Tomas Winkler
tpm manual startup is used only from within tpm1 or tpm2
code, hence remove tpm_startup function from tpm-interface.c
and add two static functions implementations tpm1_startup
and tpm2_startup into to tpm1-cmd.c and tpm2-cmd.c respectively.

Signed-off-by: Tomas Winkler 
---
V2-V3: Rebase

 drivers/char/tpm/tpm-interface.c | 41 
 drivers/char/tpm/tpm.h   |  1 -
 drivers/char/tpm/tpm1-cmd.c  | 37 +++-
 drivers/char/tpm/tpm2-cmd.c  | 34 +++--
 4 files changed, 68 insertions(+), 45 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 1ddf9d7e2069..3a2eef9e8665 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -403,47 +403,6 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct 
tpm_space *space,
 }
 EXPORT_SYMBOL_GPL(tpm_transmit_cmd);
 
-#define TPM_ORD_STARTUP 153
-#define TPM_ST_CLEAR 1
-
-/**
- * tpm_startup - turn on the TPM
- * @chip: TPM chip to use
- *
- * Normally the firmware should start the TPM. This function is provided as a
- * workaround if this does not happen. A legal case for this could be for
- * example when a TPM emulator is used.
- *
- * Return: same as tpm_transmit_cmd()
- */
-int tpm_startup(struct tpm_chip *chip)
-{
-   struct tpm_buf buf;
-   int rc;
-
-   dev_info(>dev, "starting up the TPM manually\n");
-
-   if (chip->flags & TPM_CHIP_FLAG_TPM2) {
-   rc = tpm_buf_init(, TPM2_ST_NO_SESSIONS, TPM2_CC_STARTUP);
-   if (rc < 0)
-   return rc;
-
-   tpm_buf_append_u16(, TPM2_SU_CLEAR);
-   } else {
-   rc = tpm_buf_init(, TPM_TAG_RQU_COMMAND, TPM_ORD_STARTUP);
-   if (rc < 0)
-   return rc;
-
-   tpm_buf_append_u16(, TPM_ST_CLEAR);
-   }
-
-   rc = tpm_transmit_cmd(chip, NULL, buf.data, PAGE_SIZE, 0, 0,
- "attempting to start the TPM");
-
-   tpm_buf_destroy();
-   return rc;
-}
-
 int tpm_get_timeouts(struct tpm_chip *chip)
 {
if (chip->flags & TPM_CHIP_FLAG_HAVE_TIMEOUTS)
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 862c9262e037..fa88102a0cab 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -540,7 +540,6 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct 
tpm_space *space,
 void *buf, size_t bufsiz,
 size_t min_rsp_body_length, unsigned int flags,
 const char *desc);
-int tpm_startup(struct tpm_chip *chip);
 int tpm_get_timeouts(struct tpm_chip *);
 
 int tpm1_pm_suspend(struct tpm_chip *chip, int tpm_suspend_pcr);
diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c
index 5fdc44feea0f..f93776621e49 100644
--- a/drivers/char/tpm/tpm1-cmd.c
+++ b/drivers/char/tpm/tpm1-cmd.c
@@ -307,6 +307,40 @@ unsigned long tpm1_calc_ordinal_duration(struct tpm_chip 
*chip, u32 ordinal)
return duration;
 }
 
+#define TPM_ORD_STARTUP 153
+#define TPM_ST_CLEAR 1
+
+/**
+ * tpm_startup - turn on the TPM
+ * @chip: TPM chip to use
+ *
+ * Normally the firmware should start the TPM. This function is provided as a
+ * workaround if this does not happen. A legal case for this could be for
+ * example when a TPM emulator is used.
+ *
+ * Return: same as tpm_transmit_cmd()
+ */
+static int tpm1_startup(struct tpm_chip *chip)
+{
+   struct tpm_buf buf;
+   int rc;
+
+   dev_info(>dev, "starting up the TPM manually\n");
+
+   rc = tpm_buf_init(, TPM_TAG_RQU_COMMAND, TPM_ORD_STARTUP);
+   if (rc < 0)
+   return rc;
+
+   tpm_buf_append_u16(, TPM_ST_CLEAR);
+
+   rc = tpm_transmit_cmd(chip, NULL, buf.data, PAGE_SIZE, 0, 0,
+ "attempting to start the TPM");
+
+   tpm_buf_destroy();
+
+   return rc;
+}
+
 int tpm1_get_timeouts(struct tpm_chip *chip)
 {
cap_t cap;
@@ -316,7 +350,7 @@ int tpm1_get_timeouts(struct tpm_chip *chip)
rc = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, , NULL,
 sizeof(cap.timeout));
if (rc == TPM_ERR_INVALID_POSTINIT) {
-   if (tpm_startup(chip))
+   if (tpm1_startup(chip))
return rc;
 
rc = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, ,
@@ -721,3 +755,4 @@ int tpm1_pm_suspend(struct tpm_chip *chip, int 
tpm_suspend_pcr)
 
return rc;
 }
+
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 4ca0555f23c8..333631eab4c7 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -943,6 +943,36 @@ static int tpm2_get_cc_attrs_tbl(struct tpm_chip *chip)
return rc;
 }
 
+/**
+ * tpm2_startup - turn on the TPM
+ * @chip: TPM chip to use
+ *
+ * Normally the firmware should start the TPM. This function is provided as a
+ * 

[PATCH v3 08/20] tpm: factor out tpm1_get_random into tpm1-cmd.c

2018-09-18 Thread Tomas Winkler
Factor out get random implementation from tpm-interface.c
into tpm1_get_random function in tpm1-cmd.c.
No functional changes.

Signed-off-by: Tomas Winkler 
---
V2-V3: Rebase

 drivers/char/tpm/tpm-interface.c | 58 +---
 drivers/char/tpm/tpm.h   |  1 +
 drivers/char/tpm/tpm1-cmd.c  | 55 +
 3 files changed, 63 insertions(+), 51 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 59ca0cdda811..c15957fef08f 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -801,14 +801,6 @@ int tpm_pm_resume(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(tpm_pm_resume);
 
-#define TPM_ORD_GET_RANDOM 70
-#define TPM_GETRANDOM_RESULT_SIZE  18
-static const struct tpm_input_header tpm_getrandom_header = {
-   .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
-   .length = cpu_to_be32(14),
-   .ordinal = cpu_to_be32(TPM_ORD_GET_RANDOM)
-};
-
 /**
  * tpm_get_random() - get random bytes from the TPM's RNG
  * @chip:  a  tpm_chip instance, %NULL for the default chip
@@ -819,58 +811,22 @@ static const struct tpm_input_header tpm_getrandom_header 
= {
  */
 int tpm_get_random(struct tpm_chip *chip, u8 *out, size_t max)
 {
-   struct tpm_cmd_t tpm_cmd;
-   u32 recd, num_bytes = min_t(u32, max, TPM_MAX_RNG_DATA), rlength;
-   int err, total = 0, retries = 5;
-   u8 *dest = out;
+   int rc;
 
-   if (!out || !num_bytes || max > TPM_MAX_RNG_DATA)
+   if (!out || max > TPM_MAX_RNG_DATA)
return -EINVAL;
 
chip = tpm_find_get_ops(chip);
if (!chip)
return -ENODEV;
 
-   if (chip->flags & TPM_CHIP_FLAG_TPM2) {
-   err = tpm2_get_random(chip, out, max);
-   tpm_put_ops(chip);
-   return err;
-   }
-
-   do {
-   tpm_cmd.header.in = tpm_getrandom_header;
-   tpm_cmd.params.getrandom_in.num_bytes = cpu_to_be32(num_bytes);
-
-   err = tpm_transmit_cmd(chip, NULL, _cmd,
-  TPM_GETRANDOM_RESULT_SIZE + num_bytes,
-  offsetof(struct tpm_getrandom_out,
-   rng_data),
-  0, "attempting get random");
-   if (err)
-   break;
-
-   recd = be32_to_cpu(tpm_cmd.params.getrandom_out.rng_data_len);
-   if (recd > num_bytes) {
-   total = -EFAULT;
-   break;
-   }
-
-   rlength = be32_to_cpu(tpm_cmd.header.out.length);
-   if (rlength < TPM_HEADER_SIZE +
- offsetof(struct tpm_getrandom_out, rng_data) +
- recd) {
-   total = -EFAULT;
-   break;
-   }
-   memcpy(dest, tpm_cmd.params.getrandom_out.rng_data, recd);
-
-   dest += recd;
-   total += recd;
-   num_bytes -= recd;
-   } while (retries-- && total < max);
+   if (chip->flags & TPM_CHIP_FLAG_TPM2)
+   rc = tpm2_get_random(chip, out, max);
+   else
+   rc = tpm1_get_random(chip, out, max);
 
tpm_put_ops(chip);
-   return total ? total : -EIO;
+   return rc;
 }
 EXPORT_SYMBOL_GPL(tpm_get_random);
 
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 1c1980c79c30..496a56156e77 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -551,6 +551,7 @@ int tpm1_pcr_extend(struct tpm_chip *chip, int pcr_idx, 
const u8 *hash,
const char *log_msg);
 ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
const char *desc, size_t min_cap_length);
+int tpm1_get_random(struct tpm_chip *chip, u8 *out, size_t max);
 unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
 int tpm_pm_suspend(struct device *dev);
 int tpm_pm_resume(struct device *dev);
diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c
index 8aa3e3cfed71..e7e0528e2e06 100644
--- a/drivers/char/tpm/tpm1-cmd.c
+++ b/drivers/char/tpm/tpm1-cmd.c
@@ -470,3 +470,58 @@ ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, 
cap_t *cap,
return rc;
 }
 EXPORT_SYMBOL_GPL(tpm1_getcap);
+
+#define TPM_ORD_GET_RANDOM 70
+#define TPM_GETRANDOM_RESULT_SIZE  18
+static const struct tpm_input_header tpm_getrandom_header = {
+   .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
+   .length = cpu_to_be32(14),
+   .ordinal = cpu_to_be32(TPM_ORD_GET_RANDOM)
+};
+
+int tpm1_get_random(struct tpm_chip *chip, u8 *out, size_t max)
+{
+   struct tpm_cmd_t tpm_cmd;
+   u32 recd;
+   u32 num_bytes = min_t(u32, max, TPM_MAX_RNG_DATA);
+   u32 rlength;
+   int err, total = 0, retries = 5;
+   u8 *dest = out;
+

[PATCH v3 13/20] tpm: add tpm_auto_startup into tpm-interface

2018-09-18 Thread Tomas Winkler
Add wrapper tpm_auto_startup() to tpm-interface.c
instead of open coded decision between tpm 1.2 and tpm 2.0
in tpm-chip.c

Signed-off-by: Tomas Winkler 
---
V3: new in the series

 drivers/char/tpm/tpm-chip.c  | 11 +++
 drivers/char/tpm/tpm-interface.c | 15 +++
 drivers/char/tpm/tpm.h   |  1 +
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index 46caadca916a..32db84683c40 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -451,14 +451,9 @@ int tpm_chip_register(struct tpm_chip *chip)
 {
int rc;
 
-   if (chip->ops->flags & TPM_OPS_AUTO_STARTUP) {
-   if (chip->flags & TPM_CHIP_FLAG_TPM2)
-   rc = tpm2_auto_startup(chip);
-   else
-   rc = tpm1_auto_startup(chip);
-   if (rc)
-   return rc;
-   }
+   rc = tpm_auto_startup(chip);
+   if (rc)
+   return rc;
 
tpm_sysfs_add_device(chip);
 
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 54e2cc592bd9..a8f8e0bcb434 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -520,6 +520,21 @@ int tpm_send(struct tpm_chip *chip, void *cmd, size_t 
buflen)
 }
 EXPORT_SYMBOL_GPL(tpm_send);
 
+int tpm_auto_startup(struct tpm_chip *chip)
+{
+   int rc;
+
+   if (!(chip->ops->flags & TPM_OPS_AUTO_STARTUP))
+   return 0;
+
+   if (chip->flags & TPM_CHIP_FLAG_TPM2)
+   rc = tpm2_auto_startup(chip);
+   else
+   rc = tpm1_auto_startup(chip);
+
+   return rc;
+}
+
 /*
  * We are about to suspend. Save the TPM state
  * so that it can be restored.
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index f0963a0a8acd..4ccffbb56864 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -541,6 +541,7 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct 
tpm_space *space,
 size_t min_rsp_body_length, unsigned int flags,
 const char *desc);
 int tpm_get_timeouts(struct tpm_chip *);
+int tpm_auto_startup(struct tpm_chip *chip);
 
 int tpm1_pm_suspend(struct tpm_chip *chip, int tpm_suspend_pcr);
 int tpm1_do_selftest(struct tpm_chip *chip);
-- 
2.14.4



[PATCH v3 12/20] tpm: move pcr extend code to tpm2-cmd.c

2018-09-18 Thread Tomas Winkler
Add tpm2_pcr_extend() function to tpm2-cmd.c with signature required
by tpm-interface.c. It wraps the original open code
implementation. The original original tpm2_pcr_extend() function
is renamed and made static, called only from new tpm2_pcr_extend()

Signed-off-by: Tomas Winkler 
---
V3: fix commit message
 drivers/char/tpm/tpm-interface.c | 24 +---
 drivers/char/tpm/tpm.h   |  3 +--
 drivers/char/tpm/tpm1-cmd.c  |  1 +
 drivers/char/tpm/tpm2-cmd.c  | 24 ++--
 4 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 3a2eef9e8665..54e2cc592bd9 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -481,31 +481,17 @@ EXPORT_SYMBOL_GPL(tpm_pcr_read);
 int tpm_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash)
 {
int rc;
-   struct tpm2_digest digest_list[ARRAY_SIZE(chip->active_banks)];
-   u32 count = 0;
-   int i;
 
chip = tpm_find_get_ops(chip);
if (!chip)
return -ENODEV;
 
-   if (chip->flags & TPM_CHIP_FLAG_TPM2) {
-   memset(digest_list, 0, sizeof(digest_list));
-
-   for (i = 0; i < ARRAY_SIZE(chip->active_banks) &&
-   chip->active_banks[i] != TPM2_ALG_ERROR; i++) {
-   digest_list[i].alg_id = chip->active_banks[i];
-   memcpy(digest_list[i].digest, hash, TPM_DIGEST_SIZE);
-   count++;
-   }
-
-   rc = tpm2_pcr_extend(chip, pcr_idx, count, digest_list);
-   tpm_put_ops(chip);
-   return rc;
-   }
+   if (chip->flags & TPM_CHIP_FLAG_TPM2)
+   rc = tpm2_pcr_extend(chip, pcr_idx, hash);
+   else
+   rc = tpm1_pcr_extend(chip, pcr_idx, hash,
+"attempting extend a PCR value");
 
-   rc = tpm1_pcr_extend(chip, pcr_idx, hash,
-"attempting extend a PCR value");
tpm_put_ops(chip);
return rc;
 }
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index fa88102a0cab..f0963a0a8acd 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -592,8 +592,7 @@ static inline u32 tpm2_rc_value(u32 rc)
 
 int tpm2_get_timeouts(struct tpm_chip *chip);
 int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf);
-int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, u32 count,
-   struct tpm2_digest *digests);
+int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash);
 int tpm2_get_random(struct tpm_chip *chip, u8 *dest, size_t max);
 void tpm2_flush_context_cmd(struct tpm_chip *chip, u32 handle,
unsigned int flags);
diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c
index f93776621e49..90e5bc1720ad 100644
--- a/drivers/char/tpm/tpm1-cmd.c
+++ b/drivers/char/tpm/tpm1-cmd.c
@@ -466,6 +466,7 @@ int tpm1_pcr_extend(struct tpm_chip *chip, int pcr_idx, 
const u8 *hash,
 
rc = tpm_transmit_cmd(chip, NULL, buf.data, EXTEND_PCR_RESULT_SIZE,
  EXTEND_PCR_RESULT_BODY_SIZE, 0, log_msg);
+
tpm_buf_destroy();
return rc;
 }
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 333631eab4c7..b0b714309440 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -178,8 +178,8 @@ struct tpm2_null_auth_area {
  *
  * Return: Same as with tpm_transmit_cmd.
  */
-int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, u32 count,
-   struct tpm2_digest *digests)
+static int __tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, u32 count,
+struct tpm2_digest *digests)
 {
struct tpm_buf buf;
struct tpm2_null_auth_area auth_area;
@@ -225,6 +225,26 @@ int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, 
u32 count,
return rc;
 }
 
+int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash)
+{
+   int rc;
+   struct tpm2_digest digest_list[ARRAY_SIZE(chip->active_banks)];
+   u32 count = 0;
+   unsigned int i;
+
+   memset(digest_list, 0, sizeof(digest_list));
+   for (i = 0; i < ARRAY_SIZE(chip->active_banks); i++) {
+   if (chip->active_banks[i] == TPM2_ALG_ERROR)
+   break;
+   digest_list[i].alg_id = chip->active_banks[i];
+   memcpy(digest_list[i].digest, hash, TPM_DIGEST_SIZE);
+   count++;
+   }
+
+   rc = __tpm2_pcr_extend(chip, pcr_idx, count, digest_list);
+   return rc;
+}
+
 
 struct tpm2_get_random_out {
__be16 size;
-- 
2.14.4



[PATCH v3 10/20] tpm: factor out tpm1 pm suspend flow into tpm1-cmd.c

2018-09-18 Thread Tomas Winkler
Factor out tpm1 suspend flow from tpm-interface.c into a new function
tpm1_pm_suspend in tpm1-cmd.c

Signed-off-by: Tomas Winkler 
---
V2-V3: Rebase
 drivers/char/tpm/tpm-interface.c | 55 
 drivers/char/tpm/tpm.h   |  1 +
 drivers/char/tpm/tpm1-cmd.c  | 54 +++
 3 files changed, 60 insertions(+), 50 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 8396cf6735ec..1ddf9d7e2069 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -575,15 +575,6 @@ int tpm_send(struct tpm_chip *chip, void *cmd, size_t 
buflen)
 }
 EXPORT_SYMBOL_GPL(tpm_send);
 
-#define TPM_ORD_SAVESTATE 152
-#define SAVESTATE_RESULT_SIZE 10
-
-static const struct tpm_input_header savestate_header = {
-   .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
-   .length = cpu_to_be32(10),
-   .ordinal = cpu_to_be32(TPM_ORD_SAVESTATE)
-};
-
 /*
  * We are about to suspend. Save the TPM state
  * so that it can be restored.
@@ -591,54 +582,18 @@ static const struct tpm_input_header savestate_header = {
 int tpm_pm_suspend(struct device *dev)
 {
struct tpm_chip *chip = dev_get_drvdata(dev);
-   struct tpm_cmd_t cmd;
-   int rc, try;
-
-   u8 dummy_hash[TPM_DIGEST_SIZE] = { 0 };
+   int rc = 0;
 
-   if (chip == NULL)
+   if (!chip)
return -ENODEV;
 
if (chip->flags & TPM_CHIP_FLAG_ALWAYS_POWERED)
return 0;
 
-   if (chip->flags & TPM_CHIP_FLAG_TPM2) {
+   if (chip->flags & TPM_CHIP_FLAG_TPM2)
tpm2_shutdown(chip, TPM2_SU_STATE);
-   return 0;
-   }
-
-   /* for buggy tpm, flush pcrs with extend to selected dummy */
-   if (tpm_suspend_pcr)
-   rc = tpm1_pcr_extend(chip, tpm_suspend_pcr, dummy_hash,
-"extending dummy pcr before suspend");
-
-   /* now do the actual savestate */
-   for (try = 0; try < TPM_RETRY; try++) {
-   cmd.header.in = savestate_header;
-   rc = tpm_transmit_cmd(chip, NULL, , SAVESTATE_RESULT_SIZE,
- 0, 0, NULL);
-
-   /*
-* If the TPM indicates that it is too busy to respond to
-* this command then retry before giving up.  It can take
-* several seconds for this TPM to be ready.
-*
-* This can happen if the TPM has already been sent the
-* SaveState command before the driver has loaded.  TCG 1.2
-* specification states that any communication after SaveState
-* may cause the TPM to invalidate previously saved state.
-*/
-   if (rc != TPM_WARN_RETRY)
-   break;
-   tpm_msleep(TPM_TIMEOUT_RETRY);
-   }
-
-   if (rc)
-   dev_err(>dev,
-   "Error (%d) sending savestate before suspend\n", rc);
-   else if (try > 0)
-   dev_warn(>dev, "TPM savestate took %dms\n",
-try * TPM_TIMEOUT_RETRY);
+   else
+   rc = tpm1_pm_suspend(chip, tpm_suspend_pcr);
 
return rc;
 }
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index fd945fc828b6..862c9262e037 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -543,6 +543,7 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct 
tpm_space *space,
 int tpm_startup(struct tpm_chip *chip);
 int tpm_get_timeouts(struct tpm_chip *);
 
+int tpm1_pm_suspend(struct tpm_chip *chip, int tpm_suspend_pcr);
 int tpm1_do_selftest(struct tpm_chip *chip);
 int tpm1_auto_startup(struct tpm_chip *chip);
 int tpm1_get_timeouts(struct tpm_chip *chip);
diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c
index 3f561736f066..5fdc44feea0f 100644
--- a/drivers/char/tpm/tpm1-cmd.c
+++ b/drivers/char/tpm/tpm1-cmd.c
@@ -667,3 +667,57 @@ int tpm1_auto_startup(struct tpm_chip *chip)
rc = -ENODEV;
return rc;
 }
+
+#define TPM_ORD_SAVESTATE 152
+#define SAVESTATE_RESULT_SIZE 10
+static const struct tpm_input_header savestate_header = {
+   .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
+   .length = cpu_to_be32(10),
+   .ordinal = cpu_to_be32(TPM_ORD_SAVESTATE)
+};
+
+/*
+ * We are about to suspend. Save the TPM state
+ * so that it can be restored.
+ */
+int tpm1_pm_suspend(struct tpm_chip *chip, int tpm_suspend_pcr)
+{
+   u8 dummy_hash[TPM_DIGEST_SIZE] = { 0 };
+   struct tpm_cmd_t cmd;
+   int rc, try;
+
+   /* for buggy tpm, flush pcrs with extend to selected dummy */
+   if (tpm_suspend_pcr)
+   rc = tpm1_pcr_extend(chip, tpm_suspend_pcr, dummy_hash,
+"extending dummy pcr before suspend");
+
+   /* now do the actual savestate */
+   for (try = 0; try < TPM_RETRY; try++) {

[PATCH v3 07/20] tpm: move tpm_getcap to tpm1-cmd.c

2018-09-18 Thread Tomas Winkler
1. Move tpm_getcap to tpm1-cmd. Rename the function to tpm1_getcap.
2. Remove unused tpm_getcap_header with unused constant
as this functionality is already implemented using tpm_buf construct.

Fixes warning:
drivers/char/tpm/tpm-interface.c:452:38: warning: ‘tpm_getcap_header’ defined 
but not used [-Wunused-const-variable=]
 static const struct tpm_input_header tpm_getcap_header = {
  ^
3. Drop unused TPM_DIGEST_SIZE. It's already defined in
include/linux/tpm.h

Signed-off-by: Tomas Winkler 
---
V2-V3: Rebase
 drivers/char/tpm/tpm-interface.c | 47 +---
 drivers/char/tpm/tpm-sysfs.c | 48 ++---
 drivers/char/tpm/tpm.h   |  4 ++--
 drivers/char/tpm/tpm1-cmd.c  | 51 +---
 drivers/char/tpm/tpm_tis_core.c  |  2 +-
 5 files changed, 71 insertions(+), 81 deletions(-)

diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 03134f2e1c39..59ca0cdda811 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -444,52 +444,6 @@ int tpm_startup(struct tpm_chip *chip)
return rc;
 }
 
-#define TPM_DIGEST_SIZE 20
-#define TPM_RET_CODE_IDX 6
-#define TPM_INTERNAL_RESULT_SIZE 200
-#define TPM_ORD_GET_CAP 101
-#define TPM_ORD_GET_RANDOM 70
-
-static const struct tpm_input_header tpm_getcap_header = {
-   .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
-   .length = cpu_to_be32(22),
-   .ordinal = cpu_to_be32(TPM_ORD_GET_CAP)
-};
-
-ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
-  const char *desc, size_t min_cap_length)
-{
-   struct tpm_buf buf;
-   int rc;
-
-   rc = tpm_buf_init(, TPM_TAG_RQU_COMMAND, TPM_ORD_GET_CAP);
-   if (rc)
-   return rc;
-
-   if (subcap_id == TPM_CAP_VERSION_1_1 ||
-   subcap_id == TPM_CAP_VERSION_1_2) {
-   tpm_buf_append_u32(, subcap_id);
-   tpm_buf_append_u32(, 0);
-   } else {
-   if (subcap_id == TPM_CAP_FLAG_PERM ||
-   subcap_id == TPM_CAP_FLAG_VOL)
-   tpm_buf_append_u32(, TPM_CAP_FLAG);
-   else
-   tpm_buf_append_u32(, TPM_CAP_PROP);
-
-   tpm_buf_append_u32(, 4);
-   tpm_buf_append_u32(, subcap_id);
-   }
-   rc = tpm_transmit_cmd(chip, NULL, buf.data, PAGE_SIZE,
- min_cap_length, 0, desc);
-   if (!rc)
-   *cap = *(cap_t *)[TPM_HEADER_SIZE + 4];
-
-   tpm_buf_destroy();
-   return rc;
-}
-EXPORT_SYMBOL_GPL(tpm_getcap);
-
 int tpm_get_timeouts(struct tpm_chip *chip)
 {
if (chip->flags & TPM_CHIP_FLAG_HAVE_TIMEOUTS)
@@ -847,6 +801,7 @@ int tpm_pm_resume(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(tpm_pm_resume);
 
+#define TPM_ORD_GET_RANDOM 70
 #define TPM_GETRANDOM_RESULT_SIZE  18
 static const struct tpm_input_header tpm_getrandom_header = {
.tag = cpu_to_be16(TPM_TAG_RQU_COMMAND),
diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c
index 83a77a445538..008515314ae3 100644
--- a/drivers/char/tpm/tpm-sysfs.c
+++ b/drivers/char/tpm/tpm-sysfs.c
@@ -106,9 +106,9 @@ static ssize_t pcrs_show(struct device *dev, struct 
device_attribute *attr,
char *str = buf;
struct tpm_chip *chip = to_tpm_chip(dev);
 
-   rc = tpm_getcap(chip, TPM_CAP_PROP_PCR, ,
-   "attempting to determine the number of PCRS",
-   sizeof(cap.num_pcrs));
+   rc = tpm1_getcap(chip, TPM_CAP_PROP_PCR, ,
+"attempting to determine the number of PCRS",
+sizeof(cap.num_pcrs));
if (rc)
return 0;
 
@@ -132,9 +132,9 @@ static ssize_t enabled_show(struct device *dev, struct 
device_attribute *attr,
cap_t cap;
ssize_t rc;
 
-   rc = tpm_getcap(to_tpm_chip(dev), TPM_CAP_FLAG_PERM, ,
-   "attempting to determine the permanent enabled state",
-   sizeof(cap.perm_flags));
+   rc = tpm1_getcap(to_tpm_chip(dev), TPM_CAP_FLAG_PERM, ,
+"attempting to determine the permanent enabled state",
+sizeof(cap.perm_flags));
if (rc)
return 0;
 
@@ -149,9 +149,9 @@ static ssize_t active_show(struct device *dev, struct 
device_attribute *attr,
cap_t cap;
ssize_t rc;
 
-   rc = tpm_getcap(to_tpm_chip(dev), TPM_CAP_FLAG_PERM, ,
-   "attempting to determine the permanent active state",
-   sizeof(cap.perm_flags));
+   rc = tpm1_getcap(to_tpm_chip(dev), TPM_CAP_FLAG_PERM, ,
+"attempting to determine the permanent active state",
+sizeof(cap.perm_flags));
if (rc)
return 0;
 
@@ -166,9 +166,9 @@ static ssize_t 

Re: [PATCH RESEND 3/6] arm64: add sysfs vulnerability show for spectre v1

2018-09-18 Thread Robert Richter
On 18.09.18 09:38:05, Will Deacon wrote:
> On Mon, Sep 17, 2018 at 07:22:07PM +0200, Robert Richter wrote:
> > On 27.08.18 16:33:07, Mian Yousaf Kaukab wrote:
> > > Hard-coded since patches are merged and there are no configuration
> > > options.
> >
> > Could you add a list of upstream patches to the description that are
> > required to solve this? This would be a strict definition for the
> > mitigation being enabled and makes it easier to check if backports are
> > affected or not. A build-time check would be ideal (e.g. checking for
> > certain macros).
> 
> Hmm, I don't grok what you're proposing here. Why do we need a build-time
> check (and to check what?)

My concern is, that for kernel backports (esp. distro kernels) there
could be various interpretations of what "Mitigation: __user pointer
sanitization" means. So a list of upstream patches that need to be
backported in addition to this patch as a requirement would be good to
agree on. That should be documented in the patch description.

If these mitigations are available in a kernel backport, that could be
even checked at build time. E.g. we could have a sanity check if the
macro array_index_nospec() is defined. But such a check does not
replace a code review of a kernel backport.

I hope that makes sense?

-Robert


Re: [PATCH] tty/sysrq: Make local variable 'killer' in sysrq_handle_crash() global

2018-09-18 Thread Jiri Slaby
On 09/17/2018, 11:33 PM, Matthias Kaehlcke wrote:
> sysrq_handle_crash() dereferences a NULL pointer on purpose to force
> an exception, the local variable 'killer' is assigned to NULL and
> dereferenced later. Clang detects the NULL pointer dereference at compile
> time and emits a BRK instruction (on arm64) instead of the expected NULL
> pointer exception. Change 'killer' to a global variable (and rename it
> to 'sysrq_killer' to avoid possible clashes) to prevent Clang from
> detecting the condition. By default global variables are initialized
> with zero/NULL in C, therefore an explicit initialization is not needed.
> 
> Reported-by: Sai Prakash Ranjan 
> Suggested-by: Evan Green 
> Signed-off-by: Matthias Kaehlcke 
> ---
>  drivers/tty/sysrq.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
> index 06ed20dd01ba..49fa8e758690 100644
> --- a/drivers/tty/sysrq.c
> +++ b/drivers/tty/sysrq.c
> @@ -132,10 +132,10 @@ static struct sysrq_key_op sysrq_unraw_op = {
>  #define sysrq_unraw_op (*(struct sysrq_key_op *)NULL)
>  #endif /* CONFIG_VT */
>  
> +char *sysrq_killer;
> +
>  static void sysrq_handle_crash(int key)
>  {
> - char *killer = NULL;
> -
>   /* we need to release the RCU read lock here,
>* otherwise we get an annoying
>* 'BUG: sleeping function called from invalid context'
> @@ -144,7 +144,7 @@ static void sysrq_handle_crash(int key)
>   rcu_read_unlock();
>   panic_on_oops = 1;  /* force panic */
>   wmb();
> - *killer = 1;
> + *sysrq_killer = 1;

Just because a static analyzer is wrong? Oh wait, even compiler is
wrong. At least make it a static global. Or what about OPTIMIZER_HIDE_VAR?

thanks,
-- 
js
suse labs


[PATCH 07/19] vmw_balloon: treat all refused pages equally

2018-09-18 Thread Nadav Amit
Currently, when the hypervisor rejects a page during lock operation, the
VM treats pages differently according to the error-code: in certain
cases the page is immediately freed, and in others it is put on a
rejection list and only freed later.

The behavior does not make too much sense. If the page is freed
immediately it is very likely to be used again in the next batch of
allocations, and be rejected again.

In addition, for support of compaction and OOM notifiers, we wish to
separate the logic that communicates with the hypervisor (as well as
analyzes the status of each page) from the logic that allocates or free
pages.

Treat all errors the same way, queuing the pages on the refuse list.
Move to the next allocation size (4k) when too many pages are refused.
Free the refused pages when moving to the next size to avoid situations
in which too much memory is waiting to be freed on the refused list.

Reviewed-by: Xavier Deguillard 
Signed-off-by: Nadav Amit 
---
 drivers/misc/vmw_balloon.c | 52 +-
 1 file changed, 29 insertions(+), 23 deletions(-)

diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
index e1b704d3d5cb..74fff1e314a7 100644
--- a/drivers/misc/vmw_balloon.c
+++ b/drivers/misc/vmw_balloon.c
@@ -542,29 +542,13 @@ static int vmballoon_lock(struct vmballoon *b, unsigned 
int num_pages,
/* Error occurred */
STATS_INC(b->stats.refused_alloc[is_2m_pages]);
 
-   switch (status) {
-   case VMW_BALLOON_ERROR_PPN_PINNED:
-   case VMW_BALLOON_ERROR_PPN_INVALID:
-   /*
-* Place page on the list of non-balloonable pages
-* and retry allocation, unless we already accumulated
-* too many of them, in which case take a breather.
-*/
-   if (page_size->n_refused_pages
-   < VMW_BALLOON_MAX_REFUSED) {
-   list_add(>lru, _size->refused_pages);
-   page_size->n_refused_pages++;
-   break;
-   }
-   /* Fallthrough */
-   case VMW_BALLOON_ERROR_RESET:
-   case VMW_BALLOON_ERROR_PPN_NOTNEEDED:
-   vmballoon_free_page(p, is_2m_pages);
-   break;
-   default:
-   /* This should never happen */
-   WARN_ON_ONCE(true);
-   }
+   /*
+* Place page on the list of non-balloonable pages
+* and retry allocation, unless we already accumulated
+* too many of them, in which case take a breather.
+*/
+   list_add(>lru, _size->refused_pages);
+   page_size->n_refused_pages++;
}
 
return batch_status == VMW_BALLOON_SUCCESS ? 0 : -EIO;
@@ -711,9 +695,31 @@ static void vmballoon_inflate(struct vmballoon *b)
 
vmballoon_add_page(b, num_pages++, page);
if (num_pages == b->batch_max_pages) {
+   struct vmballoon_page_size *page_size =
+   >page_sizes[is_2m_pages];
+
error = vmballoon_lock(b, num_pages, is_2m_pages);
 
num_pages = 0;
+
+   /*
+* Stop allocating this page size if we already
+* accumulated too many pages that the hypervisor
+* refused.
+*/
+   if (page_size->n_refused_pages >=
+   VMW_BALLOON_MAX_REFUSED) {
+   if (!is_2m_pages)
+   break;
+
+   /*
+* Release the refused pages as we move to 4k
+* pages.
+*/
+   vmballoon_release_refused_pages(b, true);
+   is_2m_pages = true;
+   }
+
if (error)
break;
}
-- 
2.17.1



[PATCH 06/19] vmw_balloon: change batch/single lock abstractions

2018-09-18 Thread Nadav Amit
The current abstractions for batch vs single operations seem suboptimal
and complicate the implementation of additional features (OOM,
compaction).

The immediate problem of the current abstractions is that they cause
differences in how operations are handled when batching is on or off.
For example, the refused_alloc counter is not updated when batching is
on. These discrepancies are caused by code redundancies.

Instead, this patch presents three type of operations, according to
whether batching is on or off: (1) add page, (2) communication with the
hypervisor and (3) retrieving the status of a page.

To avoid the overhead of virtual functions, and since we do not expect
additional interfaces for communication with the hypervisor, we use
static keys instead of virtual functions.

Finally, while we are at it, change vmballoon_init_batching() to return
int instead of bool, to be consistent in the return type and avoid
potential coding errors.

Reviewed-by: Xavier Deguillard 
Signed-off-by: Nadav Amit 
---
 drivers/misc/vmw_balloon.c | 358 +
 1 file changed, 165 insertions(+), 193 deletions(-)

diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
index abcc8678e51e..e1b704d3d5cb 100644
--- a/drivers/misc/vmw_balloon.c
+++ b/drivers/misc/vmw_balloon.c
@@ -165,15 +165,7 @@ struct vmballoon_stats {
 #define STATS_INC(stat)
 #endif
 
-struct vmballoon;
-
-struct vmballoon_ops {
-   void (*add_page)(struct vmballoon *b, int idx, struct page *p);
-   int (*lock)(struct vmballoon *b, unsigned int num_pages,
-   bool is_2m_pages);
-   int (*unlock)(struct vmballoon *b, unsigned int num_pages,
- bool is_2m_pages);
-};
+static DEFINE_STATIC_KEY_TRUE(vmw_balloon_batching);
 
 struct vmballoon_page_size {
/* list of reserved physical pages */
@@ -223,8 +215,6 @@ struct vmballoon {
unsigned int batch_max_pages;
struct page *page;
 
-   const struct vmballoon_ops *ops;
-
 #ifdef CONFIG_DEBUG_FS
/* statistics */
struct vmballoon_stats stats;
@@ -393,53 +383,6 @@ static bool vmballoon_send_get_target(struct vmballoon *b)
return false;
 }
 
-/*
- * Notify the host about allocated page so that host can use it without
- * fear that guest will need it. Host may reject some pages, we need to
- * check the return value and maybe submit a different page.
- */
-static int vmballoon_send_lock_page(struct vmballoon *b, unsigned long pfn,
-   unsigned int *hv_status, bool lock)
-{
-   unsigned long status, cmd;
-   u32 pfn32;
-
-   pfn32 = (u32)pfn;
-   if (pfn32 != pfn)
-   return -EINVAL;
-
-   cmd = lock ? VMW_BALLOON_CMD_LOCK : VMW_BALLOON_CMD_UNLOCK;
-
-   *hv_status = status = vmballoon_cmd(b, cmd, pfn, 0);
-
-   if (status == VMW_BALLOON_SUCCESS)
-   return 0;
-
-   return -EIO;
-}
-
-static int vmballoon_send_batched_lock(struct vmballoon *b,
-  unsigned int num_pages, bool is_2m_pages,
-  bool lock)
-{
-   unsigned long pfn = PHYS_PFN(virt_to_phys(b->batch_page));
-   unsigned long status, cmd;
-
-   if (lock)
-   cmd = is_2m_pages ? VMW_BALLOON_CMD_BATCHED_2M_LOCK :
-   VMW_BALLOON_CMD_BATCHED_LOCK;
-   else
-   cmd = is_2m_pages ? VMW_BALLOON_CMD_BATCHED_2M_UNLOCK :
-   VMW_BALLOON_CMD_BATCHED_UNLOCK;
-
-   status = vmballoon_cmd(b, cmd, pfn, num_pages);
-
-   if (status == VMW_BALLOON_SUCCESS)
-   return 0;
-
-   return 1;
-}
-
 static struct page *vmballoon_alloc_page(bool is_2m_page)
 {
if (is_2m_page)
@@ -487,88 +430,126 @@ static void vmballoon_pop(struct vmballoon *b)
b->batch_page = NULL;
 }
 
-/*
- * Notify the host of a ballooned page. If host rejects the page put it on the
- * refuse list, those refused page are then released at the end of the
- * inflation cycle.
+/**
+ * vmballoon_status_page - returns the status of (un)lock operation
+ *
+ * @b: pointer to the balloon.
+ * @idx: index for the page for which the operation is performed.
+ * @p: pointer to where the page struct is returned.
+ *
+ * Following a lock or unlock operation, returns the status of the operation 
for
+ * an individual page. Provides the page that the operation was performed on on
+ * the @page argument.
+ *
+ * Returns: The status of a lock or unlock operation for an individual page.
  */
-static int vmballoon_lock_page(struct vmballoon *b, unsigned int num_pages,
-   bool is_2m_pages)
+static unsigned long vmballoon_status_page(struct vmballoon *b, int idx,
+  struct page **p)
 {
-   int locked, hv_status;
-   struct page *page = b->page;
-   struct vmballoon_page_size *page_size = >page_sizes[false];
-
-   

  1   2   3   4   5   6   7   8   9   10   >