[PATCH v3 18/47] filelock: have fs/locks.c deal with file_lock_core directly
Convert fs/locks.c to access fl_core fields direcly rather than using the backward-compatibility macros. Most of this was done with coccinelle, with a few by-hand fixups. Signed-off-by: Jeff Layton --- fs/locks.c | 467 include/trace/events/filelock.h | 32 +-- 2 files changed, 254 insertions(+), 245 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index 097254ab35d3..f418c6e31219 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -48,8 +48,6 @@ * children. * */ -#define _NEED_FILE_LOCK_FIELD_MACROS - #include #include #include @@ -73,16 +71,16 @@ static bool lease_breaking(struct file_lock *fl) { - return fl->fl_flags & (FL_UNLOCK_PENDING | FL_DOWNGRADE_PENDING); + return fl->c.flc_flags & (FL_UNLOCK_PENDING | FL_DOWNGRADE_PENDING); } static int target_leasetype(struct file_lock *fl) { - if (fl->fl_flags & FL_UNLOCK_PENDING) + if (fl->c.flc_flags & FL_UNLOCK_PENDING) return F_UNLCK; - if (fl->fl_flags & FL_DOWNGRADE_PENDING) + if (fl->c.flc_flags & FL_DOWNGRADE_PENDING) return F_RDLCK; - return fl->fl_type; + return fl->c.flc_type; } static int leases_enable = 1; @@ -201,8 +199,10 @@ locks_dump_ctx_list(struct list_head *list, char *list_type) { struct file_lock *fl; - list_for_each_entry(fl, list, fl_list) { - pr_warn("%s: fl_owner=%p fl_flags=0x%x fl_type=0x%x fl_pid=%u\n", list_type, fl->fl_owner, fl->fl_flags, fl->fl_type, fl->fl_pid); + list_for_each_entry(fl, list, c.flc_list) { + pr_warn("%s: fl_owner=%p fl_flags=0x%x fl_type=0x%x fl_pid=%u\n", list_type, + fl->c.flc_owner, fl->c.flc_flags, + fl->c.flc_type, fl->c.flc_pid); } } @@ -230,13 +230,14 @@ locks_check_ctx_file_list(struct file *filp, struct list_head *list, struct file_lock *fl; struct inode *inode = file_inode(filp); - list_for_each_entry(fl, list, fl_list) - if (fl->fl_file == filp) + list_for_each_entry(fl, list, c.flc_list) + if (fl->c.flc_file == filp) pr_warn("Leaked %s lock on dev=0x%x:0x%x ino=0x%lx " " fl_owner=%p fl_flags=0x%x fl_type=0x%x fl_pid=%u\n", list_type, MAJOR(inode->i_sb->s_dev), MINOR(inode->i_sb->s_dev), inode->i_ino, - fl->fl_owner, fl->fl_flags, fl->fl_type, fl->fl_pid); + fl->c.flc_owner, fl->c.flc_flags, + fl->c.flc_type, fl->c.flc_pid); } void @@ -250,13 +251,13 @@ locks_free_lock_context(struct inode *inode) } } -static void locks_init_lock_heads(struct file_lock *fl) +static void locks_init_lock_heads(struct file_lock_core *flc) { - INIT_HLIST_NODE(&fl->fl_link); - INIT_LIST_HEAD(&fl->fl_list); - INIT_LIST_HEAD(&fl->fl_blocked_requests); - INIT_LIST_HEAD(&fl->fl_blocked_member); - init_waitqueue_head(&fl->fl_wait); + INIT_HLIST_NODE(&flc->flc_link); + INIT_LIST_HEAD(&flc->flc_list); + INIT_LIST_HEAD(&flc->flc_blocked_requests); + INIT_LIST_HEAD(&flc->flc_blocked_member); + init_waitqueue_head(&flc->flc_wait); } /* Allocate an empty lock structure. */ @@ -265,7 +266,7 @@ struct file_lock *locks_alloc_lock(void) struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL); if (fl) - locks_init_lock_heads(fl); + locks_init_lock_heads(&fl->c); return fl; } @@ -273,11 +274,11 @@ EXPORT_SYMBOL_GPL(locks_alloc_lock); void locks_release_private(struct file_lock *fl) { - BUG_ON(waitqueue_active(&fl->fl_wait)); - BUG_ON(!list_empty(&fl->fl_list)); - BUG_ON(!list_empty(&fl->fl_blocked_requests)); - BUG_ON(!list_empty(&fl->fl_blocked_member)); - BUG_ON(!hlist_unhashed(&fl->fl_link)); + BUG_ON(waitqueue_active(&fl->c.flc_wait)); + BUG_ON(!list_empty(&fl->c.flc_list)); + BUG_ON(!list_empty(&fl->c.flc_blocked_requests)); + BUG_ON(!list_empty(&fl->c.flc_blocked_member)); + BUG_ON(!hlist_unhashed(&fl->c.flc_link)); if (fl->fl_ops) { if (fl->fl_ops->fl_release_private) @@ -287,8 +288,8 @@ void locks_release_private(struct file_lock *fl) if (fl->fl_lmops) { if (fl->fl_lmops->lm_put_owner) { - fl->fl_lmops->lm_put_owner(fl->fl_owner); - fl->fl_owner = NULL; + fl->fl_lmops->lm_put_owner(fl->c.flc_owner); + fl->c.flc_owner = NULL; } fl->fl_lmops = NULL; } @@ -310,10 +311,10 @@ bool locks_owner_has_blockers(struct file_lock_context *flctx, struct file_lock *fl; spin_lock(&flctx->flc_lock); -
[PATCH v2 12/41] filelock: have fs/locks.c deal with file_lock_core directly
Convert fs/locks.c to access fl_core fields direcly rather than using the backward-compatability macros. Most of this was done with coccinelle, with a few by-hand fixups. Signed-off-by: Jeff Layton --- fs/locks.c | 479 include/trace/events/filelock.h | 32 +-- 2 files changed, 260 insertions(+), 251 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index cee3f183a872..b06fa4dea298 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -48,8 +48,6 @@ * children. * */ -#define _NEED_FILE_LOCK_FIELD_MACROS - #include #include #include @@ -73,16 +71,16 @@ static bool lease_breaking(struct file_lock *fl) { - return fl->fl_flags & (FL_UNLOCK_PENDING | FL_DOWNGRADE_PENDING); + return fl->fl_core.flc_flags & (FL_UNLOCK_PENDING | FL_DOWNGRADE_PENDING); } static int target_leasetype(struct file_lock *fl) { - if (fl->fl_flags & FL_UNLOCK_PENDING) + if (fl->fl_core.flc_flags & FL_UNLOCK_PENDING) return F_UNLCK; - if (fl->fl_flags & FL_DOWNGRADE_PENDING) + if (fl->fl_core.flc_flags & FL_DOWNGRADE_PENDING) return F_RDLCK; - return fl->fl_type; + return fl->fl_core.flc_type; } static int leases_enable = 1; @@ -201,8 +199,10 @@ locks_dump_ctx_list(struct list_head *list, char *list_type) { struct file_lock *fl; - list_for_each_entry(fl, list, fl_list) { - pr_warn("%s: fl_owner=%p fl_flags=0x%x fl_type=0x%x fl_pid=%u\n", list_type, fl->fl_owner, fl->fl_flags, fl->fl_type, fl->fl_pid); + list_for_each_entry(fl, list, fl_core.flc_list) { + pr_warn("%s: fl_owner=%p fl_flags=0x%x fl_type=0x%x fl_pid=%u\n", list_type, + fl->fl_core.flc_owner, fl->fl_core.flc_flags, + fl->fl_core.flc_type, fl->fl_core.flc_pid); } } @@ -230,13 +230,14 @@ locks_check_ctx_file_list(struct file *filp, struct list_head *list, struct file_lock *fl; struct inode *inode = file_inode(filp); - list_for_each_entry(fl, list, fl_list) - if (fl->fl_file == filp) + list_for_each_entry(fl, list, fl_core.flc_list) + if (fl->fl_core.flc_file == filp) pr_warn("Leaked %s lock on dev=0x%x:0x%x ino=0x%lx " " fl_owner=%p fl_flags=0x%x fl_type=0x%x fl_pid=%u\n", list_type, MAJOR(inode->i_sb->s_dev), MINOR(inode->i_sb->s_dev), inode->i_ino, - fl->fl_owner, fl->fl_flags, fl->fl_type, fl->fl_pid); + fl->fl_core.flc_owner, fl->fl_core.flc_flags, + fl->fl_core.flc_type, fl->fl_core.flc_pid); } void @@ -252,11 +253,11 @@ locks_free_lock_context(struct inode *inode) static void locks_init_lock_heads(struct file_lock *fl) { - INIT_HLIST_NODE(&fl->fl_link); - INIT_LIST_HEAD(&fl->fl_list); - INIT_LIST_HEAD(&fl->fl_blocked_requests); - INIT_LIST_HEAD(&fl->fl_blocked_member); - init_waitqueue_head(&fl->fl_wait); + INIT_HLIST_NODE(&fl->fl_core.flc_link); + INIT_LIST_HEAD(&fl->fl_core.flc_list); + INIT_LIST_HEAD(&fl->fl_core.flc_blocked_requests); + INIT_LIST_HEAD(&fl->fl_core.flc_blocked_member); + init_waitqueue_head(&fl->fl_core.flc_wait); } /* Allocate an empty lock structure. */ @@ -273,11 +274,11 @@ EXPORT_SYMBOL_GPL(locks_alloc_lock); void locks_release_private(struct file_lock *fl) { - BUG_ON(waitqueue_active(&fl->fl_wait)); - BUG_ON(!list_empty(&fl->fl_list)); - BUG_ON(!list_empty(&fl->fl_blocked_requests)); - BUG_ON(!list_empty(&fl->fl_blocked_member)); - BUG_ON(!hlist_unhashed(&fl->fl_link)); + BUG_ON(waitqueue_active(&fl->fl_core.flc_wait)); + BUG_ON(!list_empty(&fl->fl_core.flc_list)); + BUG_ON(!list_empty(&fl->fl_core.flc_blocked_requests)); + BUG_ON(!list_empty(&fl->fl_core.flc_blocked_member)); + BUG_ON(!hlist_unhashed(&fl->fl_core.flc_link)); if (fl->fl_ops) { if (fl->fl_ops->fl_release_private) @@ -287,8 +288,8 @@ void locks_release_private(struct file_lock *fl) if (fl->fl_lmops) { if (fl->fl_lmops->lm_put_owner) { - fl->fl_lmops->lm_put_owner(fl->fl_owner); - fl->fl_owner = NULL; + fl->fl_lmops->lm_put_owner(fl->fl_core.flc_owner); + fl->fl_core.flc_owner = NULL; } fl->fl_lmops = NULL; } @@ -310,10 +311,10 @@ bool locks_owner_has_blockers(struct file_lock_context *flctx, struct file_lock *fl; spin_lock(&flctx->flc_lock); - list_for_each_entry(fl, &flctx->flc_posix, fl_list) { - if (fl->fl_owner != owner) + list_for_each_entry(fl, &flctx->flc_posix, fl_core.flc_list) { +
[PATCH 11/57] staging: rtl8723bs: core: rtw_mlme_ext: Deal with a bunch of unused variables
Some are used inside debug prints. These get marked as __maybe_unused. Others are used within #ifery. These are defined inside the same #ifery. Lastly, ones that are truly unused are removed entirely. Fixes the following W=1 kernel build warning(s): drivers/staging/rtl8723bs/core/rtw_mlme_ext.c: In function ‘OnAssocReq’: drivers/staging/rtl8723bs/core/rtw_mlme_ext.c:1058:17: warning: variable ‘reassoc’ set but not used [-Wunused-but-set-variable] drivers/staging/rtl8723bs/core/rtw_mlme_ext.c: In function ‘OnAction_back’: drivers/staging/rtl8723bs/core/rtw_mlme_ext.c:1792:30: warning: variable ‘reason_code’ set but not used [-Wunused-but-set-variable] drivers/staging/rtl8723bs/core/rtw_mlme_ext.c: In function ‘_linked_info_dump’: drivers/staging/rtl8723bs/core/rtw_mlme_ext.c:5393:21: warning: variable ‘psta’ set but not used [-Wunused-but-set-variable] drivers/staging/rtl8723bs/core/rtw_mlme_ext.c: In function ‘led_blink_hdl’: drivers/staging/rtl8723bs/core/rtw_mlme_ext.c:6517:25: warning: variable ‘ledBlink_param’ set but not used [-Wunused-but-set-variable] Cc: Greg Kroah-Hartman Cc: Ross Schmidt Cc: linux-stag...@lists.linux.dev Signed-off-by: Lee Jones --- drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 12 +--- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c index f19a15a3924b6..d1dbf234e9e02 100644 --- a/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +++ b/drivers/staging/rtl8723bs/core/rtw_mlme_ext.c @@ -1019,7 +1019,7 @@ unsigned int OnAssocReq(struct adapter *padapter, union recv_frame *precv_frame) u16 capab_info; struct rtw_ieee802_11_elems elems; struct sta_info *pstat; - unsigned char reassoc, *p, *pos, *wpa_ie; + unsigned char __maybe_unused reassoc, *p, *pos, *wpa_ie; unsigned char WMM_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01}; int i, ie_len, wpa_ie_len, left; unsigned char supportRate[16]; @@ -1719,7 +1719,7 @@ unsigned int OnAction_back(struct adapter *padapter, union recv_frame *precv_fra struct recv_reorder_ctrl *preorder_ctrl; unsigned char *frame_body; unsigned char category, action; - unsigned short tid, status, reason_code = 0; + unsigned short tid, status, __maybe_unused reason_code = 0; struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); u8 *pframe = precv_frame->u.hdr.rx_data; @@ -5121,7 +5121,7 @@ void _linked_info_dump(struct adapter *padapter) } else if ((pmlmeinfo->state&0x03) == _HW_STATE_AP_) { struct list_head*phead, *plist; - struct sta_info *psta = NULL; + struct sta_info __maybe_unused *psta = NULL; struct sta_priv *pstapriv = &padapter->stapriv; spin_lock_bh(&pstapriv->asoc_list_lock); @@ -5980,7 +5980,8 @@ u8 set_tx_beacon_cmd(struct adapter *padapter) u8 mlme_evt_hdl(struct adapter *padapter, unsigned char *pbuf) { - u8 evt_code, evt_seq; + u8 evt_seq; + u8 evt_code; u16 evt_sz; uint*peventbuf; void (*event_callback)(struct adapter *dev, u8 *pbuf); @@ -6191,12 +6192,9 @@ u8 set_chplan_hdl(struct adapter *padapter, unsigned char *pbuf) u8 led_blink_hdl(struct adapter *padapter, unsigned char *pbuf) { - struct LedBlink_param *ledBlink_param; - if (!pbuf) return H2C_PARAMETERS_ERROR; - ledBlink_param = (struct LedBlink_param *)pbuf; return H2C_SUCCESS; } -- 2.27.0
[PATCH] staging: qlge: deal with the case that devlink_health_reporter_create fails
From: Coiby Xu devlink_health_reporter_create may fail. In that case, do the cleanup work. Reported-by: Dan Carpenter Signed-off-by: Coiby Xu --- drivers/staging/qlge/qlge_devlink.c | 10 +++--- drivers/staging/qlge/qlge_devlink.h | 2 +- drivers/staging/qlge/qlge_main.c| 8 +++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/staging/qlge/qlge_devlink.c b/drivers/staging/qlge/qlge_devlink.c index 86834d96cebf..0ab02d6d3817 100644 --- a/drivers/staging/qlge/qlge_devlink.c +++ b/drivers/staging/qlge/qlge_devlink.c @@ -148,16 +148,20 @@ static const struct devlink_health_reporter_ops qlge_reporter_ops = { .dump = qlge_reporter_coredump, }; -void qlge_health_create_reporters(struct qlge_adapter *priv) +long qlge_health_create_reporters(struct qlge_adapter *priv) { struct devlink *devlink; + long err = 0; devlink = priv_to_devlink(priv); priv->reporter = devlink_health_reporter_create(devlink, &qlge_reporter_ops, 0, priv); - if (IS_ERR(priv->reporter)) + if (IS_ERR(priv->reporter)) { + err = PTR_ERR(priv->reporter); netdev_warn(priv->ndev, "Failed to create reporter, err = %ld\n", - PTR_ERR(priv->reporter)); + err); + } + return err; } diff --git a/drivers/staging/qlge/qlge_devlink.h b/drivers/staging/qlge/qlge_devlink.h index 19078e1ac694..94538e923f2f 100644 --- a/drivers/staging/qlge/qlge_devlink.h +++ b/drivers/staging/qlge/qlge_devlink.h @@ -4,6 +4,6 @@ #include -void qlge_health_create_reporters(struct qlge_adapter *priv); +long qlge_health_create_reporters(struct qlge_adapter *priv); #endif /* QLGE_DEVLINK_H */ diff --git a/drivers/staging/qlge/qlge_main.c b/drivers/staging/qlge/qlge_main.c index 5516be3af898..59d1ec580696 100644 --- a/drivers/staging/qlge/qlge_main.c +++ b/drivers/staging/qlge/qlge_main.c @@ -4620,7 +4620,11 @@ static int qlge_probe(struct pci_dev *pdev, if (err) goto netdev_free; - qlge_health_create_reporters(qdev); + err = qlge_health_create_reporters(qdev); + + if (err) + goto devlink_unregister; + /* Start up the timer to trigger EEH if * the bus goes dead */ @@ -4632,6 +4636,8 @@ static int qlge_probe(struct pci_dev *pdev, cards_found++; return 0; +devlink_unregister: + devlink_unregister(devlink); netdev_free: free_netdev(ndev); devlink_free: -- 2.31.0
[PATCH 5.10 124/290] net: dsa: tag_ar9331: let DSA core deal with TX reallocation
From: Greg Kroah-Hartman From: Vladimir Oltean [ Upstream commit 86c4ad9a7876777c12fd5a7010152e4141fcb94d ] Now that we have a central TX reallocation procedure that accounts for the tagger's needed headroom in a generic way, we can remove the skb_cow_head call. Cc: Per Forlin Cc: Oleksij Rempel Signed-off-by: Vladimir Oltean Tested-by: Oleksij Rempel Reviewed-by: Florian Fainelli Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/dsa/tag_ar9331.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/net/dsa/tag_ar9331.c b/net/dsa/tag_ar9331.c index 55b00694cdba..002cf7f952e2 100644 --- a/net/dsa/tag_ar9331.c +++ b/net/dsa/tag_ar9331.c @@ -31,9 +31,6 @@ static struct sk_buff *ar9331_tag_xmit(struct sk_buff *skb, __le16 *phdr; u16 hdr; - if (skb_cow_head(skb, AR9331_HDR_LEN) < 0) - return NULL; - phdr = skb_push(skb, AR9331_HDR_LEN); hdr = FIELD_PREP(AR9331_HDR_VERSION_MASK, AR9331_HDR_VERSION); -- 2.30.1
[PATCH 5.10 123/290] net: dsa: tag_gswip: let DSA core deal with TX reallocation
From: Greg Kroah-Hartman From: Vladimir Oltean [ Upstream commit 9b9826ae117f211bcbdc75db844d5fd8b159fc59 ] Now that we have a central TX reallocation procedure that accounts for the tagger's needed headroom in a generic way, we can remove the skb_cow_head call. This one is interesting, the DSA tag is 8 bytes on RX and 4 bytes on TX. Because DSA is unaware of asymmetrical tag lengths, the overhead/needed headroom is declared as 8 bytes and therefore 4 bytes larger than it needs to be. If this becomes a problem, and the GSWIP driver can't be converted to a uniform header length, we might need to make DSA aware of separate RX/TX overhead values. Cc: Hauke Mehrtens Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/dsa/tag_gswip.c | 5 - 1 file changed, 5 deletions(-) diff --git a/net/dsa/tag_gswip.c b/net/dsa/tag_gswip.c index 408d4af390a0..2f5bd5e338ab 100644 --- a/net/dsa/tag_gswip.c +++ b/net/dsa/tag_gswip.c @@ -60,13 +60,8 @@ static struct sk_buff *gswip_tag_xmit(struct sk_buff *skb, struct net_device *dev) { struct dsa_port *dp = dsa_slave_to_port(dev); - int err; u8 *gswip_tag; - err = skb_cow_head(skb, GSWIP_TX_HEADER_LEN); - if (err) - return NULL; - skb_push(skb, GSWIP_TX_HEADER_LEN); gswip_tag = skb->data; -- 2.30.1
[PATCH 5.10 122/290] net: dsa: tag_dsa: let DSA core deal with TX reallocation
From: Greg Kroah-Hartman From: Vladimir Oltean [ Upstream commit 952a06345015867e3bd37f8d9045fc1429637d43 ] Now that we have a central TX reallocation procedure that accounts for the tagger's needed headroom in a generic way, we can remove the skb_cow_head call. Similar to the EtherType DSA tagger, the old Marvell tagger can transform an 802.1Q header if present into a DSA tag, so there is no headroom required in that case. But we are ensuring that it exists, regardless (practically speaking, the headroom must be 4 bytes larger than it needs to be). Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/dsa/tag_dsa.c | 5 - 1 file changed, 5 deletions(-) diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c index 0b756fae68a5..63d690a0fca6 100644 --- a/net/dsa/tag_dsa.c +++ b/net/dsa/tag_dsa.c @@ -23,9 +23,6 @@ static struct sk_buff *dsa_xmit(struct sk_buff *skb, struct net_device *dev) * the ethertype field for untagged packets. */ if (skb->protocol == htons(ETH_P_8021Q)) { - if (skb_cow_head(skb, 0) < 0) - return NULL; - /* * Construct tagged FROM_CPU DSA tag from 802.1q tag. */ @@ -41,8 +38,6 @@ static struct sk_buff *dsa_xmit(struct sk_buff *skb, struct net_device *dev) dsa_header[2] &= ~0x10; } } else { - if (skb_cow_head(skb, DSA_HLEN) < 0) - return NULL; skb_push(skb, DSA_HLEN); memmove(skb->data, skb->data + DSA_HLEN, 2 * ETH_ALEN); -- 2.30.1
[PATCH 5.10 121/290] net: dsa: tag_brcm: let DSA core deal with TX reallocation
From: Greg Kroah-Hartman From: Vladimir Oltean [ Upstream commit 2f0d030c5ffec6660f79a32b4f522155f75a9d71 ] Now that we have a central TX reallocation procedure that accounts for the tagger's needed headroom in a generic way, we can remove the skb_cow_head call. Cc: Florian Fainelli Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/dsa/tag_brcm.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c index ad72dff8d524..e934dace3922 100644 --- a/net/dsa/tag_brcm.c +++ b/net/dsa/tag_brcm.c @@ -66,9 +66,6 @@ static struct sk_buff *brcm_tag_xmit_ll(struct sk_buff *skb, u16 queue = skb_get_queue_mapping(skb); u8 *brcm_tag; - if (skb_cow_head(skb, BRCM_TAG_LEN) < 0) - return NULL; - /* The Ethernet switch we are interfaced with needs packets to be at * least 64 bytes (including FCS) otherwise they will be discarded when * they enter the switch port logic. When Broadcom tags are enabled, we -- 2.30.1
[PATCH 5.10 120/290] net: dsa: tag_edsa: let DSA core deal with TX reallocation
From: Greg Kroah-Hartman From: Vladimir Oltean [ Upstream commit c6c4e1237dfe731644e79fa06d073625f28cd945 ] Now that we have a central TX reallocation procedure that accounts for the tagger's needed headroom in a generic way, we can remove the skb_cow_head call. Note that the VLAN code path needs a smaller extra headroom than the regular EtherType DSA path. That isn't a problem, because this tagger declares the larger tag length (8 bytes vs 4) as the protocol overhead, so we are covered in both cases. Cc: Andrew Lunn Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/dsa/tag_edsa.c | 4 1 file changed, 4 deletions(-) diff --git a/net/dsa/tag_edsa.c b/net/dsa/tag_edsa.c index 120614240319..abf70a29deb4 100644 --- a/net/dsa/tag_edsa.c +++ b/net/dsa/tag_edsa.c @@ -35,8 +35,6 @@ static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev) * current ethertype field if the packet is untagged. */ if (skb->protocol == htons(ETH_P_8021Q)) { - if (skb_cow_head(skb, DSA_HLEN) < 0) - return NULL; skb_push(skb, DSA_HLEN); memmove(skb->data, skb->data + DSA_HLEN, 2 * ETH_ALEN); @@ -60,8 +58,6 @@ static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev) edsa_header[6] &= ~0x10; } } else { - if (skb_cow_head(skb, EDSA_HLEN) < 0) - return NULL; skb_push(skb, EDSA_HLEN); memmove(skb->data, skb->data + EDSA_HLEN, 2 * ETH_ALEN); -- 2.30.1
[PATCH 5.10 118/290] net: dsa: tag_mtk: let DSA core deal with TX reallocation
From: Greg Kroah-Hartman From: Vladimir Oltean [ Upstream commit 941f66beb7bb4e0e4726aa31336d9ccc1c3a3dc2 ] Now that we have a central TX reallocation procedure that accounts for the tagger's needed headroom in a generic way, we can remove the skb_cow_head call. Cc: DENG Qingfang Cc: Sean Wang Cc: John Crispin Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/dsa/tag_mtk.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/net/dsa/tag_mtk.c b/net/dsa/tag_mtk.c index 4cdd9cf428fb..38dcdded74c0 100644 --- a/net/dsa/tag_mtk.c +++ b/net/dsa/tag_mtk.c @@ -34,9 +34,6 @@ static struct sk_buff *mtk_tag_xmit(struct sk_buff *skb, * table with VID. */ if (!skb_vlan_tagged(skb)) { - if (skb_cow_head(skb, MTK_HDR_LEN) < 0) - return NULL; - skb_push(skb, MTK_HDR_LEN); memmove(skb->data, skb->data + MTK_HDR_LEN, 2 * ETH_ALEN); is_vlan_skb = false; -- 2.30.1
[PATCH 5.10 119/290] net: dsa: tag_lan9303: let DSA core deal with TX reallocation
From: Greg Kroah-Hartman From: Vladimir Oltean [ Upstream commit 6ed94135f58372cdec34cafb60f7596893b0b371 ] Now that we have a central TX reallocation procedure that accounts for the tagger's needed headroom in a generic way, we can remove the skb_cow_head call. Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/dsa/tag_lan9303.c | 9 - 1 file changed, 9 deletions(-) diff --git a/net/dsa/tag_lan9303.c b/net/dsa/tag_lan9303.c index ccfb6f641bbf..aa1318dccaf0 100644 --- a/net/dsa/tag_lan9303.c +++ b/net/dsa/tag_lan9303.c @@ -58,15 +58,6 @@ static struct sk_buff *lan9303_xmit(struct sk_buff *skb, struct net_device *dev) __be16 *lan9303_tag; u16 tag; - /* insert a special VLAN tag between the MAC addresses -* and the current ethertype field. -*/ - if (skb_cow_head(skb, LAN9303_TAG_LEN) < 0) { - dev_dbg(&dev->dev, - "Cannot make room for the special tag. Dropping packet\n"); - return NULL; - } - /* provide 'LAN9303_TAG_LEN' bytes additional space */ skb_push(skb, LAN9303_TAG_LEN); -- 2.30.1
[PATCH 5.10 117/290] net: dsa: tag_ocelot: let DSA core deal with TX reallocation
From: Greg Kroah-Hartman From: Vladimir Oltean [ Upstream commit 9c5c3bd00557e57c1049f7861f11e5e39f0fb42d ] Now that we have a central TX reallocation procedure that accounts for the tagger's needed headroom in a generic way, we can remove the skb_cow_head call. Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/dsa/tag_ocelot.c | 7 --- 1 file changed, 7 deletions(-) diff --git a/net/dsa/tag_ocelot.c b/net/dsa/tag_ocelot.c index 3b468aca5c53..16a1afd5b8e1 100644 --- a/net/dsa/tag_ocelot.c +++ b/net/dsa/tag_ocelot.c @@ -143,13 +143,6 @@ static struct sk_buff *ocelot_xmit(struct sk_buff *skb, struct ocelot_port *ocelot_port; u8 *prefix, *injection; u64 qos_class, rew_op; - int err; - - err = skb_cow_head(skb, OCELOT_TOTAL_TAG_LEN); - if (unlikely(err < 0)) { - netdev_err(netdev, "Cannot make room for tag.\n"); - return NULL; - } ocelot_port = ocelot->ports[dp->index]; -- 2.30.1
[PATCH 5.10 116/290] net: dsa: tag_qca: let DSA core deal with TX reallocation
From: Greg Kroah-Hartman From: Vladimir Oltean [ Upstream commit 9bbda29ae1044bc4c1c01a5b7c44688c4765785f ] Now that we have a central TX reallocation procedure that accounts for the tagger's needed headroom in a generic way, we can remove the skb_cow_head call. Cc: John Crispin Cc: Alexander Lobakin Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/dsa/tag_qca.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/net/dsa/tag_qca.c b/net/dsa/tag_qca.c index 1b9e8507112b..88181b52f480 100644 --- a/net/dsa/tag_qca.c +++ b/net/dsa/tag_qca.c @@ -34,9 +34,6 @@ static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev) __be16 *phdr; u16 hdr; - if (skb_cow_head(skb, QCA_HDR_LEN) < 0) - return NULL; - skb_push(skb, QCA_HDR_LEN); memmove(skb->data, skb->data + QCA_HDR_LEN, 2 * ETH_ALEN); -- 2.30.1
[PATCH v8 13/17] remoteproc: Properly deal with a kernel panic when attached
The panic handler operation of registered remote processors should also be called when remote processors have been attached to. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 37b3b7d494e5..c00f3f8bdfcc 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2728,7 +2728,11 @@ static int rproc_panic_handler(struct notifier_block *nb, unsigned long event, rcu_read_lock(); list_for_each_entry_rcu(rproc, &rproc_list, node) { - if (!rproc->ops->panic || rproc->state != RPROC_RUNNING) + if (!rproc->ops->panic) + continue; + + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) continue; d = rproc->ops->panic(rproc); -- 2.25.1
[PATCH v8 16/17] remoteproc: Properly deal with a detach request when attached
This patch introduces the capability to detach a remote processor that has been attached to by the remoteproc core. For that to happen a rproc::ops::detach() operation needs to be available. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_cdev.c | 5 + drivers/remoteproc/remoteproc_sysfs.c | 5 + 2 files changed, 10 insertions(+) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index 0249d8f6c3f8..2db494816d5f 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -43,6 +43,11 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ return -EINVAL; rproc_shutdown(rproc); + } else if (!strncmp(cmd, "detach", len)) { + if (rproc->state != RPROC_ATTACHED) + return -EINVAL; + + ret = rproc_detach(rproc); } else { dev_err(&rproc->dev, "Unrecognized option\n"); ret = -EINVAL; diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 09eb700c5e7e..ad3dd208024c 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -207,6 +207,11 @@ static ssize_t state_store(struct device *dev, return -EINVAL; rproc_shutdown(rproc); + } else if (sysfs_streq(buf, "detach")) { + if (rproc->state != RPROC_ATTACHED) + return -EINVAL; + + ret = rproc_detach(rproc); } else { dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); ret = -EINVAL; -- 2.25.1
[PATCH v8 14/17] remoteproc: Properly deal with a start request when attached
This patch takes into account scenarios where a remote processor has been attached to when receiving a "start" command from sysfs. As with the case with the running state, the command can't be carried out if the remote processor is already in operation. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_cdev.c | 3 ++- drivers/remoteproc/remoteproc_sysfs.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index b19ea3057bde..b2cee9afb41b 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -32,7 +32,8 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ return -EFAULT; if (!strncmp(cmd, "start", len)) { - if (rproc->state == RPROC_RUNNING) + if (rproc->state == RPROC_RUNNING || + rproc->state == RPROC_ATTACHED) return -EBUSY; ret = rproc_boot(rproc); diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index f9694def9b54..66801e6fe5cd 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -194,7 +194,8 @@ static ssize_t state_store(struct device *dev, int ret = 0; if (sysfs_streq(buf, "start")) { - if (rproc->state == RPROC_RUNNING) + if (rproc->state == RPROC_RUNNING || + rproc->state == RPROC_ATTACHED) return -EBUSY; ret = rproc_boot(rproc); -- 2.25.1
[PATCH v8 15/17] remoteproc: Properly deal with a stop request when attached
Allow a remote processor that was started by another entity to be switched off by the remoteproc core. For that to happen a rproc::ops::stop() operation needs to be available. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_cdev.c | 3 ++- drivers/remoteproc/remoteproc_core.c | 4 drivers/remoteproc/remoteproc_sysfs.c | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index b2cee9afb41b..0249d8f6c3f8 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -38,7 +38,8 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ ret = rproc_boot(rproc); } else if (!strncmp(cmd, "stop", len)) { - if (rproc->state != RPROC_RUNNING) + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) return -EINVAL; rproc_shutdown(rproc); diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index c00f3f8bdfcc..c985c5f6f2f8 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1796,6 +1796,10 @@ static int rproc_stop(struct rproc *rproc, bool crashed) struct device *dev = &rproc->dev; int ret; + /* No need to continue if a stop() operation has not been provided */ + if (!rproc->ops->stop) + return -EINVAL; + /* Stop any subdevices for the remote processor */ rproc_stop_subdevices(rproc, crashed); diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 66801e6fe5cd..09eb700c5e7e 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -202,7 +202,8 @@ static ssize_t state_store(struct device *dev, if (ret) dev_err(&rproc->dev, "Boot failed: %d\n", ret); } else if (sysfs_streq(buf, "stop")) { - if (rproc->state != RPROC_RUNNING) + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) return -EINVAL; rproc_shutdown(rproc); -- 2.25.1
[PATCH v8 11/17] remoteproc: Properly deal with the resource table when detaching
If it is possible to detach the remote processor, keep an untouched copy of the resource table. That way we can start from the same resource table without having to worry about original values or what elements the startup code has changed when re-attaching to the remote processor. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- New for V8: - Checking return code for error in __rproc_datch(). --- drivers/remoteproc/remoteproc_core.c | 82 include/linux/remoteproc.h | 3 + 2 files changed, 85 insertions(+) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 5eaa47c3ba92..0f151dbcdc36 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1556,6 +1556,24 @@ static int rproc_set_rsc_table(struct rproc *rproc) return ret; } + /* +* If it is possible to detach the remote processor, keep an untouched +* copy of the resource table. That way we can start fresh again when +* the remote processor is re-attached, that is: +* +* DETACHED -> ATTACHED -> DETACHED -> ATTACHED +* +* Free'd in rproc_reset_rsc_table_on_detach() and +* rproc_reset_rsc_table_on_stop(). +*/ + if (rproc->ops->detach) { + rproc->clean_table = kmemdup(table_ptr, table_sz, GFP_KERNEL); + if (!rproc->clean_table) + return -ENOMEM; + } else { + rproc->clean_table = NULL; + } + rproc->cached_table = NULL; rproc->table_ptr = table_ptr; rproc->table_sz = table_sz; @@ -1563,6 +1581,59 @@ static int rproc_set_rsc_table(struct rproc *rproc) return 0; } +static int rproc_reset_rsc_table_on_detach(struct rproc *rproc) +{ + struct resource_table *table_ptr; + + /* A resource table was never retrieved, nothing to do here */ + if (!rproc->table_ptr) + return 0; + + /* +* If we made it to this point a clean_table _must_ have been +* allocated in rproc_set_rsc_table(). If one isn't present +* something went really wrong and we must complain. +*/ + if (WARN_ON(!rproc->clean_table)) + return -EINVAL; + + /* Remember where the external entity installed the resource table */ + table_ptr = rproc->table_ptr; + + /* +* If we made it here the remote processor was started by another +* entity and a cache table doesn't exist. As such make a copy of +* the resource table currently used by the remote processor and +* use that for the rest of the shutdown process. The memory +* allocated here is free'd in rproc_detach(). +*/ + rproc->cached_table = kmemdup(rproc->table_ptr, + rproc->table_sz, GFP_KERNEL); + if (!rproc->cached_table) + return -ENOMEM; + + /* +* Use a copy of the resource table for the remainder of the +* shutdown process. +*/ + rproc->table_ptr = rproc->cached_table; + + /* +* Reset the memory area where the firmware loaded the resource table +* to its original value. That way when we re-attach the remote +* processor the resource table is clean and ready to be used again. +*/ + memcpy(table_ptr, rproc->clean_table, rproc->table_sz); + + /* +* The clean resource table is no longer needed. Allocated in +* rproc_set_rsc_table(). +*/ + kfree(rproc->clean_table); + + return 0; +} + /* * Attach to remote processor - similar to rproc_fw_boot() but without * the steps that deal with the firmware image. @@ -1721,6 +1792,14 @@ static int __rproc_detach(struct rproc *rproc) /* Stop any subdevices for the remote processor */ rproc_stop_subdevices(rproc, false); + /* the installed resource table is no longer accessible */ + ret = rproc_reset_rsc_table_on_detach(rproc); + if (ret) { + dev_err(dev, "can't reset resource table: %d\n", ret); + return ret; + } + + /* Tell the remote processor the core isn't available anymore */ ret = rproc->ops->detach(rproc); if (ret) { @@ -1997,6 +2076,9 @@ int rproc_detach(struct rproc *rproc) rproc_disable_iommu(rproc); + /* Free the copy of the resource table */ + kfree(rproc->cached_table); + rproc->cached_table = NULL; rproc->table_ptr = NULL; out: mutex_unlock(&rproc->lock); diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index e1c843c19cc6..e5f52a12a650 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h
[PATCH v8 12/17] remoteproc: Properly deal with the resource table when stopping
When a remote processor that was attached to is stopped, special care must be taken to make sure the shutdown process is similar to what it would be had it been started by the remoteproc core. This patch takes care of that by making a copy of the resource table currently used by the remote processor. From that point on the copy is used, as if the remote processor had been started by the remoteproc core. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen Reported-by: kernel test robot --- New for V8: - Removed variable @table_ptr as it served no purpose. --- drivers/remoteproc/remoteproc_core.c | 48 +++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 0f151dbcdc36..37b3b7d494e5 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1634,6 +1634,47 @@ static int rproc_reset_rsc_table_on_detach(struct rproc *rproc) return 0; } +static int rproc_reset_rsc_table_on_stop(struct rproc *rproc) +{ + /* A resource table was never retrieved, nothing to do here */ + if (!rproc->table_ptr) + return 0; + + /* +* If a cache table exists the remote processor was started by +* the remoteproc core. That cache table should be used for +* the rest of the shutdown process. +*/ + if (rproc->cached_table) + goto out; + + /* +* If we made it here the remote processor was started by another +* entity and a cache table doesn't exist. As such make a copy of +* the resource table currently used by the remote processor and +* use that for the rest of the shutdown process. The memory +* allocated here is free'd in rproc_shutdown(). +*/ + rproc->cached_table = kmemdup(rproc->table_ptr, + rproc->table_sz, GFP_KERNEL); + if (!rproc->cached_table) + return -ENOMEM; + + /* +* Since the remote processor is being switched off the clean table +* won't be needed. Allocated in rproc_set_rsc_table(). +*/ + kfree(rproc->clean_table); + +out: + /* +* Use a copy of the resource table for the remainder of the +* shutdown process. +*/ + rproc->table_ptr = rproc->cached_table; + return 0; +} + /* * Attach to remote processor - similar to rproc_fw_boot() but without * the steps that deal with the firmware image. @@ -1759,7 +1800,12 @@ static int rproc_stop(struct rproc *rproc, bool crashed) rproc_stop_subdevices(rproc, crashed); /* the installed resource table is no longer accessible */ - rproc->table_ptr = rproc->cached_table; + ret = rproc_reset_rsc_table_on_stop(rproc); + if (ret) { + dev_err(dev, "can't reset resource table: %d\n", ret); + return ret; + } + /* power off the remote processor */ ret = rproc->ops->stop(rproc); -- 2.25.1
Re: [PATCH v7 12/17] remoteproc: Properly deal with the resource table when stopping
On Wed, Mar 10, 2021 at 05:53:04PM -0600, Bjorn Andersson wrote: > On Wed 10 Mar 15:10 CST 2021, Mathieu Poirier wrote: > > > When a remote processor that was attached to is stopped, special care > > must be taken to make sure the shutdown process is similar to what > > it would be had it been started by the remoteproc core. > > > > This patch takes care of that by making a copy of the resource > > table currently used by the remote processor. From that point on > > the copy is used, as if the remote processor had been started by > > the remoteproc core. > > > > Signed-off-by: Mathieu Poirier > > --- > > New for V7: > > New Patch, used to be part of 11/16 in V6. > > --- > > drivers/remoteproc/remoteproc_core.c | 53 +++- > > 1 file changed, 52 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/remoteproc/remoteproc_core.c > > b/drivers/remoteproc/remoteproc_core.c > > index e9ea2558432d..c488b1aa6119 100644 > > --- a/drivers/remoteproc/remoteproc_core.c > > +++ b/drivers/remoteproc/remoteproc_core.c > > @@ -1634,6 +1634,52 @@ static int rproc_reset_rsc_table_on_detach(struct > > rproc *rproc) > > return 0; > > } > > > > +static int rproc_reset_rsc_table_on_stop(struct rproc *rproc) > > +{ > > + struct resource_table *table_ptr; > > + > > + /* A resource table was never retrieved, nothing to do here */ > > + if (!rproc->table_ptr) > > + return 0; > > + > > + /* > > +* If a cache table exists the remote processor was started by > > +* the remoteproc core. That cache table should be used for > > +* the rest of the shutdown process. > > +*/ > > + if (rproc->cached_table) > > + goto out; > > + > > + /* Remember where the external entity installed the resource table */ > > + table_ptr = rproc->table_ptr; > > + > > Afaict this is just a remnant from the detach case. > > I think the series looks really good now, please let me know and I can > drop the local "table_ptr" as I apply the patches. (sigh) No matter how long you stare at a patchset there is always one that gets away. I will address Arnaud's comment and fix this in a new revision. Thanks, Mathieu > > Regards, > Bjorn > > > + /* > > +* If we made it here the remote processor was started by another > > +* entity and a cache table doesn't exist. As such make a copy of > > +* the resource table currently used by the remote processor and > > +* use that for the rest of the shutdown process. The memory > > +* allocated here is free'd in rproc_shutdown(). > > +*/ > > + rproc->cached_table = kmemdup(rproc->table_ptr, > > + rproc->table_sz, GFP_KERNEL); > > + if (!rproc->cached_table) > > + return -ENOMEM; > > + > > + /* > > +* Since the remote processor is being switched off the clean table > > +* won't be needed. Allocated in rproc_set_rsc_table(). > > +*/ > > + kfree(rproc->clean_table); > > + > > +out: > > + /* > > +* Use a copy of the resource table for the remainder of the > > +* shutdown process. > > +*/ > > + rproc->table_ptr = rproc->cached_table; > > + return 0; > > +} > > + > > /* > > * Attach to remote processor - similar to rproc_fw_boot() but without > > * the steps that deal with the firmware image. > > @@ -1759,7 +1805,12 @@ static int rproc_stop(struct rproc *rproc, bool > > crashed) > > rproc_stop_subdevices(rproc, crashed); > > > > /* the installed resource table is no longer accessible */ > > - rproc->table_ptr = rproc->cached_table; > > + ret = rproc_reset_rsc_table_on_stop(rproc); > > + if (ret) { > > + dev_err(dev, "can't reset resource table: %d\n", ret); > > + return ret; > > + } > > + > > > > /* power off the remote processor */ > > ret = rproc->ops->stop(rproc); > > -- > > 2.25.1 > >
Re: [PATCH v7 12/17] remoteproc: Properly deal with the resource table when stopping
On 3/11/21 12:53 AM, Bjorn Andersson wrote: > On Wed 10 Mar 15:10 CST 2021, Mathieu Poirier wrote: > >> When a remote processor that was attached to is stopped, special care >> must be taken to make sure the shutdown process is similar to what >> it would be had it been started by the remoteproc core. >> >> This patch takes care of that by making a copy of the resource >> table currently used by the remote processor. From that point on >> the copy is used, as if the remote processor had been started by >> the remoteproc core. >> >> Signed-off-by: Mathieu Poirier >> --- >> New for V7: >> New Patch, used to be part of 11/16 in V6. >> --- >> drivers/remoteproc/remoteproc_core.c | 53 +++- >> 1 file changed, 52 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/remoteproc/remoteproc_core.c >> b/drivers/remoteproc/remoteproc_core.c >> index e9ea2558432d..c488b1aa6119 100644 >> --- a/drivers/remoteproc/remoteproc_core.c >> +++ b/drivers/remoteproc/remoteproc_core.c >> @@ -1634,6 +1634,52 @@ static int rproc_reset_rsc_table_on_detach(struct >> rproc *rproc) >> return 0; >> } >> >> +static int rproc_reset_rsc_table_on_stop(struct rproc *rproc) >> +{ >> +struct resource_table *table_ptr; >> + >> +/* A resource table was never retrieved, nothing to do here */ >> +if (!rproc->table_ptr) >> +return 0; >> + >> +/* >> + * If a cache table exists the remote processor was started by >> + * the remoteproc core. That cache table should be used for >> + * the rest of the shutdown process. >> + */ >> +if (rproc->cached_table) >> +goto out; >> + >> +/* Remember where the external entity installed the resource table */ >> +table_ptr = rproc->table_ptr; >> + > > Afaict this is just a remnant from the detach case. > > I think the series looks really good now, please let me know and I can > drop the local "table_ptr" as I apply the patches. > Just a minor comment on patch 11, then the series LGTM also, For this one Reviewed-by: Arnaud Pouliquen Thanks, Arnaud > Regards, > Bjorn > >> +/* >> + * If we made it here the remote processor was started by another >> + * entity and a cache table doesn't exist. As such make a copy of >> + * the resource table currently used by the remote processor and >> + * use that for the rest of the shutdown process. The memory >> + * allocated here is free'd in rproc_shutdown(). >> + */ >> +rproc->cached_table = kmemdup(rproc->table_ptr, >> + rproc->table_sz, GFP_KERNEL); >> +if (!rproc->cached_table) >> +return -ENOMEM; >> + >> +/* >> + * Since the remote processor is being switched off the clean table >> + * won't be needed. Allocated in rproc_set_rsc_table(). >> + */ >> +kfree(rproc->clean_table); >> + >> +out: >> +/* >> + * Use a copy of the resource table for the remainder of the >> + * shutdown process. >> + */ >> +rproc->table_ptr = rproc->cached_table; >> +return 0; >> +} >> + >> /* >> * Attach to remote processor - similar to rproc_fw_boot() but without >> * the steps that deal with the firmware image. >> @@ -1759,7 +1805,12 @@ static int rproc_stop(struct rproc *rproc, bool >> crashed) >> rproc_stop_subdevices(rproc, crashed); >> >> /* the installed resource table is no longer accessible */ >> -rproc->table_ptr = rproc->cached_table; >> +ret = rproc_reset_rsc_table_on_stop(rproc); >> +if (ret) { >> +dev_err(dev, "can't reset resource table: %d\n", ret); >> +return ret; >> +} >> + >> >> /* power off the remote processor */ >> ret = rproc->ops->stop(rproc); >> -- >> 2.25.1 >>
Re: [PATCH v7 11/17] remoteproc: Properly deal with the resource table when detaching
Hi Mathieu, Just a minor comment, with that Reviewed-by: Arnaud Pouliquen On 3/10/21 10:10 PM, Mathieu Poirier wrote: > If it is possible to detach the remote processor, keep an untouched > copy of the resource table. That way we can start from the same > resource table without having to worry about original values or what > elements the startup code has changed when re-attaching to the remote > processor. > > Signed-off-by: Mathieu Poirier > --- > New for V7: > New Patch, used to be part of 11/16 in V6. > --- > drivers/remoteproc/remoteproc_core.c | 77 > include/linux/remoteproc.h | 3 ++ > 2 files changed, 80 insertions(+) > > diff --git a/drivers/remoteproc/remoteproc_core.c > b/drivers/remoteproc/remoteproc_core.c > index 5eaa47c3ba92..e9ea2558432d 100644 > --- a/drivers/remoteproc/remoteproc_core.c > +++ b/drivers/remoteproc/remoteproc_core.c > @@ -1556,6 +1556,24 @@ static int rproc_set_rsc_table(struct rproc *rproc) > return ret; > } > > + /* > + * If it is possible to detach the remote processor, keep an untouched > + * copy of the resource table. That way we can start fresh again when > + * the remote processor is re-attached, that is: > + * > + * DETACHED -> ATTACHED -> DETACHED -> ATTACHED > + * > + * Free'd in rproc_reset_rsc_table_on_detach() and > + * rproc_reset_rsc_table_on_stop(). > + */ > + if (rproc->ops->detach) { > + rproc->clean_table = kmemdup(table_ptr, table_sz, GFP_KERNEL); > + if (!rproc->clean_table) > + return -ENOMEM; > + } else { > + rproc->clean_table = NULL; > + } > + > rproc->cached_table = NULL; > rproc->table_ptr = table_ptr; > rproc->table_sz = table_sz; > @@ -1563,6 +1581,59 @@ static int rproc_set_rsc_table(struct rproc *rproc) > return 0; > } > > +static int rproc_reset_rsc_table_on_detach(struct rproc *rproc) > +{ > + struct resource_table *table_ptr; > + > + /* A resource table was never retrieved, nothing to do here */ > + if (!rproc->table_ptr) > + return 0; > + > + /* > + * If we made it to this point a clean_table _must_ have been > + * allocated in rproc_set_rsc_table(). If one isn't present > + * something went really wrong and we must complain. > + */ > + if (WARN_ON(!rproc->clean_table)) > + return -EINVAL; > + > + /* Remember where the external entity installed the resource table */ > + table_ptr = rproc->table_ptr; > + > + /* > + * If we made it here the remote processor was started by another > + * entity and a cache table doesn't exist. As such make a copy of > + * the resource table currently used by the remote processor and > + * use that for the rest of the shutdown process. The memory > + * allocated here is free'd in rproc_detach(). > + */ > + rproc->cached_table = kmemdup(rproc->table_ptr, > + rproc->table_sz, GFP_KERNEL); > + if (!rproc->cached_table) > + return -ENOMEM; > + > + /* > + * Use a copy of the resource table for the remainder of the > + * shutdown process. > + */ > + rproc->table_ptr = rproc->cached_table; > + > + /* > + * Reset the memory area where the firmware loaded the resource table > + * to its original value. That way when we re-attach the remote > + * processor the resource table is clean and ready to be used again. > + */ > + memcpy(table_ptr, rproc->clean_table, rproc->table_sz); > + > + /* > + * The clean resource table is no longer needed. Allocated in > + * rproc_set_rsc_table(). > + */ > + kfree(rproc->clean_table); > + > + return 0; > +} > + > /* > * Attach to remote processor - similar to rproc_fw_boot() but without > * the steps that deal with the firmware image. > @@ -1721,6 +1792,9 @@ static int __rproc_detach(struct rproc *rproc) > /* Stop any subdevices for the remote processor */ > rproc_stop_subdevices(rproc, false); > > + /* the installed resource table is no longer accessible */ > + ret = rproc_reset_rsc_table_on_detach(rproc); > + Something seems missing here to treat the error case. Regards, Arnaud > /* Tell the remote processor the core isn't available anymore */ > ret = rproc->ops->detach(rproc); > if (ret) { > @@ -1997,6 +2071,9 @@ int rproc_detac
Re: [PATCH v7 12/17] remoteproc: Properly deal with the resource table when stopping
On Wed 10 Mar 15:10 CST 2021, Mathieu Poirier wrote: > When a remote processor that was attached to is stopped, special care > must be taken to make sure the shutdown process is similar to what > it would be had it been started by the remoteproc core. > > This patch takes care of that by making a copy of the resource > table currently used by the remote processor. From that point on > the copy is used, as if the remote processor had been started by > the remoteproc core. > > Signed-off-by: Mathieu Poirier > --- > New for V7: > New Patch, used to be part of 11/16 in V6. > --- > drivers/remoteproc/remoteproc_core.c | 53 +++- > 1 file changed, 52 insertions(+), 1 deletion(-) > > diff --git a/drivers/remoteproc/remoteproc_core.c > b/drivers/remoteproc/remoteproc_core.c > index e9ea2558432d..c488b1aa6119 100644 > --- a/drivers/remoteproc/remoteproc_core.c > +++ b/drivers/remoteproc/remoteproc_core.c > @@ -1634,6 +1634,52 @@ static int rproc_reset_rsc_table_on_detach(struct > rproc *rproc) > return 0; > } > > +static int rproc_reset_rsc_table_on_stop(struct rproc *rproc) > +{ > + struct resource_table *table_ptr; > + > + /* A resource table was never retrieved, nothing to do here */ > + if (!rproc->table_ptr) > + return 0; > + > + /* > + * If a cache table exists the remote processor was started by > + * the remoteproc core. That cache table should be used for > + * the rest of the shutdown process. > + */ > + if (rproc->cached_table) > + goto out; > + > + /* Remember where the external entity installed the resource table */ > + table_ptr = rproc->table_ptr; > + Afaict this is just a remnant from the detach case. I think the series looks really good now, please let me know and I can drop the local "table_ptr" as I apply the patches. Regards, Bjorn > + /* > + * If we made it here the remote processor was started by another > + * entity and a cache table doesn't exist. As such make a copy of > + * the resource table currently used by the remote processor and > + * use that for the rest of the shutdown process. The memory > + * allocated here is free'd in rproc_shutdown(). > + */ > + rproc->cached_table = kmemdup(rproc->table_ptr, > + rproc->table_sz, GFP_KERNEL); > + if (!rproc->cached_table) > + return -ENOMEM; > + > + /* > + * Since the remote processor is being switched off the clean table > + * won't be needed. Allocated in rproc_set_rsc_table(). > + */ > + kfree(rproc->clean_table); > + > +out: > + /* > + * Use a copy of the resource table for the remainder of the > + * shutdown process. > + */ > + rproc->table_ptr = rproc->cached_table; > + return 0; > +} > + > /* > * Attach to remote processor - similar to rproc_fw_boot() but without > * the steps that deal with the firmware image. > @@ -1759,7 +1805,12 @@ static int rproc_stop(struct rproc *rproc, bool > crashed) > rproc_stop_subdevices(rproc, crashed); > > /* the installed resource table is no longer accessible */ > - rproc->table_ptr = rproc->cached_table; > + ret = rproc_reset_rsc_table_on_stop(rproc); > + if (ret) { > + dev_err(dev, "can't reset resource table: %d\n", ret); > + return ret; > + } > + > > /* power off the remote processor */ > ret = rproc->ops->stop(rproc); > -- > 2.25.1 >
Re: [PATCH v7 12/17] remoteproc: Properly deal with the resource table when stopping
Hi Mathieu, I love your patch! Perhaps something to improve: [auto build test WARNING on linux/master] [also build test WARNING on linus/master v5.12-rc2 next-20210310] [cannot apply to remoteproc/for-next rpmsg/for-next] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch] url: https://github.com/0day-ci/linux/commits/Mathieu-Poirier/remoteproc-Add-support-for-detaching-a-remote-processor/20210311-051242 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 144c79ef33536b4ecb4951e07dbc1f2b7fa99d32 config: arm-randconfig-r036-20210310 (attached as .config) compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/0day-ci/linux/commit/6715f51e2b7ade7b5121eced81cad8065d4f5525 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Mathieu-Poirier/remoteproc-Add-support-for-detaching-a-remote-processor/20210311-051242 git checkout 6715f51e2b7ade7b5121eced81cad8065d4f5525 # save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot All warnings (new ones prefixed by >>): drivers/remoteproc/remoteproc_core.c: In function 'rproc_reset_rsc_table_on_stop': >> drivers/remoteproc/remoteproc_core.c:1639:25: warning: variable 'table_ptr' >> set but not used [-Wunused-but-set-variable] 1639 | struct resource_table *table_ptr; | ^ vim +/table_ptr +1639 drivers/remoteproc/remoteproc_core.c 1636 1637 static int rproc_reset_rsc_table_on_stop(struct rproc *rproc) 1638 { > 1639 struct resource_table *table_ptr; 1640 1641 /* A resource table was never retrieved, nothing to do here */ 1642 if (!rproc->table_ptr) 1643 return 0; 1644 1645 /* 1646 * If a cache table exists the remote processor was started by 1647 * the remoteproc core. That cache table should be used for 1648 * the rest of the shutdown process. 1649 */ 1650 if (rproc->cached_table) 1651 goto out; 1652 1653 /* Remember where the external entity installed the resource table */ 1654 table_ptr = rproc->table_ptr; 1655 1656 /* 1657 * If we made it here the remote processor was started by another 1658 * entity and a cache table doesn't exist. As such make a copy of 1659 * the resource table currently used by the remote processor and 1660 * use that for the rest of the shutdown process. The memory 1661 * allocated here is free'd in rproc_shutdown(). 1662 */ 1663 rproc->cached_table = kmemdup(rproc->table_ptr, 1664rproc->table_sz, GFP_KERNEL); 1665 if (!rproc->cached_table) 1666 return -ENOMEM; 1667 1668 /* 1669 * Since the remote processor is being switched off the clean table 1670 * won't be needed. Allocated in rproc_set_rsc_table(). 1671 */ 1672 kfree(rproc->clean_table); 1673 1674 out: 1675 /* 1676 * Use a copy of the resource table for the remainder of the 1677 * shutdown process. 1678 */ 1679 rproc->table_ptr = rproc->cached_table; 1680 return 0; 1681 } 1682 --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org .config.gz Description: application/gzip
[PATCH v7 16/17] remoteproc: Properly deal with a detach request when attached
This patch introduces the capability to detach a remote processor that has been attached to by the remoteproc core. For that to happen a rproc::ops::detach() operation needs to be available. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_cdev.c | 5 + drivers/remoteproc/remoteproc_sysfs.c | 5 + 2 files changed, 10 insertions(+) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index 0249d8f6c3f8..2db494816d5f 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -43,6 +43,11 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ return -EINVAL; rproc_shutdown(rproc); + } else if (!strncmp(cmd, "detach", len)) { + if (rproc->state != RPROC_ATTACHED) + return -EINVAL; + + ret = rproc_detach(rproc); } else { dev_err(&rproc->dev, "Unrecognized option\n"); ret = -EINVAL; diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 09eb700c5e7e..ad3dd208024c 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -207,6 +207,11 @@ static ssize_t state_store(struct device *dev, return -EINVAL; rproc_shutdown(rproc); + } else if (sysfs_streq(buf, "detach")) { + if (rproc->state != RPROC_ATTACHED) + return -EINVAL; + + ret = rproc_detach(rproc); } else { dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); ret = -EINVAL; -- 2.25.1
[PATCH v7 15/17] remoteproc: Properly deal with a stop request when attached
Allow a remote processor that was started by another entity to be switched off by the remoteproc core. For that to happen a rproc::ops::stop() operation needs to be available. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_cdev.c | 3 ++- drivers/remoteproc/remoteproc_core.c | 4 drivers/remoteproc/remoteproc_sysfs.c | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index b2cee9afb41b..0249d8f6c3f8 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -38,7 +38,8 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ ret = rproc_boot(rproc); } else if (!strncmp(cmd, "stop", len)) { - if (rproc->state != RPROC_RUNNING) + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) return -EINVAL; rproc_shutdown(rproc); diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index f6f0813dade5..3670b70390dd 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1801,6 +1801,10 @@ static int rproc_stop(struct rproc *rproc, bool crashed) struct device *dev = &rproc->dev; int ret; + /* No need to continue if a stop() operation has not been provided */ + if (!rproc->ops->stop) + return -EINVAL; + /* Stop any subdevices for the remote processor */ rproc_stop_subdevices(rproc, crashed); diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 66801e6fe5cd..09eb700c5e7e 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -202,7 +202,8 @@ static ssize_t state_store(struct device *dev, if (ret) dev_err(&rproc->dev, "Boot failed: %d\n", ret); } else if (sysfs_streq(buf, "stop")) { - if (rproc->state != RPROC_RUNNING) + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) return -EINVAL; rproc_shutdown(rproc); -- 2.25.1
[PATCH v7 13/17] remoteproc: Properly deal with a kernel panic when attached
The panic handler operation of registered remote processors should also be called when remote processors have been attached to. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index c488b1aa6119..f6f0813dade5 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2728,7 +2728,11 @@ static int rproc_panic_handler(struct notifier_block *nb, unsigned long event, rcu_read_lock(); list_for_each_entry_rcu(rproc, &rproc_list, node) { - if (!rproc->ops->panic || rproc->state != RPROC_RUNNING) + if (!rproc->ops->panic) + continue; + + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) continue; d = rproc->ops->panic(rproc); -- 2.25.1
[PATCH v7 12/17] remoteproc: Properly deal with the resource table when stopping
When a remote processor that was attached to is stopped, special care must be taken to make sure the shutdown process is similar to what it would be had it been started by the remoteproc core. This patch takes care of that by making a copy of the resource table currently used by the remote processor. From that point on the copy is used, as if the remote processor had been started by the remoteproc core. Signed-off-by: Mathieu Poirier --- New for V7: New Patch, used to be part of 11/16 in V6. --- drivers/remoteproc/remoteproc_core.c | 53 +++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index e9ea2558432d..c488b1aa6119 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1634,6 +1634,52 @@ static int rproc_reset_rsc_table_on_detach(struct rproc *rproc) return 0; } +static int rproc_reset_rsc_table_on_stop(struct rproc *rproc) +{ + struct resource_table *table_ptr; + + /* A resource table was never retrieved, nothing to do here */ + if (!rproc->table_ptr) + return 0; + + /* +* If a cache table exists the remote processor was started by +* the remoteproc core. That cache table should be used for +* the rest of the shutdown process. +*/ + if (rproc->cached_table) + goto out; + + /* Remember where the external entity installed the resource table */ + table_ptr = rproc->table_ptr; + + /* +* If we made it here the remote processor was started by another +* entity and a cache table doesn't exist. As such make a copy of +* the resource table currently used by the remote processor and +* use that for the rest of the shutdown process. The memory +* allocated here is free'd in rproc_shutdown(). +*/ + rproc->cached_table = kmemdup(rproc->table_ptr, + rproc->table_sz, GFP_KERNEL); + if (!rproc->cached_table) + return -ENOMEM; + + /* +* Since the remote processor is being switched off the clean table +* won't be needed. Allocated in rproc_set_rsc_table(). +*/ + kfree(rproc->clean_table); + +out: + /* +* Use a copy of the resource table for the remainder of the +* shutdown process. +*/ + rproc->table_ptr = rproc->cached_table; + return 0; +} + /* * Attach to remote processor - similar to rproc_fw_boot() but without * the steps that deal with the firmware image. @@ -1759,7 +1805,12 @@ static int rproc_stop(struct rproc *rproc, bool crashed) rproc_stop_subdevices(rproc, crashed); /* the installed resource table is no longer accessible */ - rproc->table_ptr = rproc->cached_table; + ret = rproc_reset_rsc_table_on_stop(rproc); + if (ret) { + dev_err(dev, "can't reset resource table: %d\n", ret); + return ret; + } + /* power off the remote processor */ ret = rproc->ops->stop(rproc); -- 2.25.1
[PATCH v7 14/17] remoteproc: Properly deal with a start request when attached
This patch takes into account scenarios where a remote processor has been attached to when receiving a "start" command from sysfs. As with the case with the running state, the command can't be carried out if the remote processor is already in operation. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_cdev.c | 3 ++- drivers/remoteproc/remoteproc_sysfs.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index b19ea3057bde..b2cee9afb41b 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -32,7 +32,8 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ return -EFAULT; if (!strncmp(cmd, "start", len)) { - if (rproc->state == RPROC_RUNNING) + if (rproc->state == RPROC_RUNNING || + rproc->state == RPROC_ATTACHED) return -EBUSY; ret = rproc_boot(rproc); diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index f9694def9b54..66801e6fe5cd 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -194,7 +194,8 @@ static ssize_t state_store(struct device *dev, int ret = 0; if (sysfs_streq(buf, "start")) { - if (rproc->state == RPROC_RUNNING) + if (rproc->state == RPROC_RUNNING || + rproc->state == RPROC_ATTACHED) return -EBUSY; ret = rproc_boot(rproc); -- 2.25.1
[PATCH v7 11/17] remoteproc: Properly deal with the resource table when detaching
If it is possible to detach the remote processor, keep an untouched copy of the resource table. That way we can start from the same resource table without having to worry about original values or what elements the startup code has changed when re-attaching to the remote processor. Signed-off-by: Mathieu Poirier --- New for V7: New Patch, used to be part of 11/16 in V6. --- drivers/remoteproc/remoteproc_core.c | 77 include/linux/remoteproc.h | 3 ++ 2 files changed, 80 insertions(+) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 5eaa47c3ba92..e9ea2558432d 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1556,6 +1556,24 @@ static int rproc_set_rsc_table(struct rproc *rproc) return ret; } + /* +* If it is possible to detach the remote processor, keep an untouched +* copy of the resource table. That way we can start fresh again when +* the remote processor is re-attached, that is: +* +* DETACHED -> ATTACHED -> DETACHED -> ATTACHED +* +* Free'd in rproc_reset_rsc_table_on_detach() and +* rproc_reset_rsc_table_on_stop(). +*/ + if (rproc->ops->detach) { + rproc->clean_table = kmemdup(table_ptr, table_sz, GFP_KERNEL); + if (!rproc->clean_table) + return -ENOMEM; + } else { + rproc->clean_table = NULL; + } + rproc->cached_table = NULL; rproc->table_ptr = table_ptr; rproc->table_sz = table_sz; @@ -1563,6 +1581,59 @@ static int rproc_set_rsc_table(struct rproc *rproc) return 0; } +static int rproc_reset_rsc_table_on_detach(struct rproc *rproc) +{ + struct resource_table *table_ptr; + + /* A resource table was never retrieved, nothing to do here */ + if (!rproc->table_ptr) + return 0; + + /* +* If we made it to this point a clean_table _must_ have been +* allocated in rproc_set_rsc_table(). If one isn't present +* something went really wrong and we must complain. +*/ + if (WARN_ON(!rproc->clean_table)) + return -EINVAL; + + /* Remember where the external entity installed the resource table */ + table_ptr = rproc->table_ptr; + + /* +* If we made it here the remote processor was started by another +* entity and a cache table doesn't exist. As such make a copy of +* the resource table currently used by the remote processor and +* use that for the rest of the shutdown process. The memory +* allocated here is free'd in rproc_detach(). +*/ + rproc->cached_table = kmemdup(rproc->table_ptr, + rproc->table_sz, GFP_KERNEL); + if (!rproc->cached_table) + return -ENOMEM; + + /* +* Use a copy of the resource table for the remainder of the +* shutdown process. +*/ + rproc->table_ptr = rproc->cached_table; + + /* +* Reset the memory area where the firmware loaded the resource table +* to its original value. That way when we re-attach the remote +* processor the resource table is clean and ready to be used again. +*/ + memcpy(table_ptr, rproc->clean_table, rproc->table_sz); + + /* +* The clean resource table is no longer needed. Allocated in +* rproc_set_rsc_table(). +*/ + kfree(rproc->clean_table); + + return 0; +} + /* * Attach to remote processor - similar to rproc_fw_boot() but without * the steps that deal with the firmware image. @@ -1721,6 +1792,9 @@ static int __rproc_detach(struct rproc *rproc) /* Stop any subdevices for the remote processor */ rproc_stop_subdevices(rproc, false); + /* the installed resource table is no longer accessible */ + ret = rproc_reset_rsc_table_on_detach(rproc); + /* Tell the remote processor the core isn't available anymore */ ret = rproc->ops->detach(rproc); if (ret) { @@ -1997,6 +2071,9 @@ int rproc_detach(struct rproc *rproc) rproc_disable_iommu(rproc); + /* Free the copy of the resource table */ + kfree(rproc->cached_table); + rproc->cached_table = NULL; rproc->table_ptr = NULL; out: mutex_unlock(&rproc->lock); diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index e1c843c19cc6..e5f52a12a650 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -514,6 +514,8 @@ struct rproc_dump_segment { * @recovery_disabled: flag that state if recovery was disabled * @max_notifyid: largest allocated notify id. * @table_pt
Re: [PATCH v6 11/16] remoteproc: Properly deal with the resource table when attached
On Fri, Feb 26, 2021 at 05:21:15PM +0100, Arnaud POULIQUEN wrote: > > > On 2/24/21 12:35 AM, Mathieu Poirier wrote: > > If it is possible to detach the remote processor, keep an untouched > > copy of the resource table. That way we can start from the same > > resource table without having to worry about original values or what > > elements the startup code has changed when re-attaching to the remote > > processor. > > > > Signed-off-by: Mathieu Poirier > > --- > > New for V6: > > - Double free of the cached table has been fixed. > > - rproc_reset_loaded_rsc_table() has seen a complete re-write. > > - rproc_stop() now calls rproc_reset_loaded_rsc_table() rather than > > dealing with the cached. This allows to properly shutdown a > > remote processor that was attached to. > > --- > > > > drivers/remoteproc/remoteproc_core.c | 86 +++- > > include/linux/remoteproc.h | 3 + > > 2 files changed, 88 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/remoteproc/remoteproc_core.c > > b/drivers/remoteproc/remoteproc_core.c > > index fc01b29290a6..3a4692cc5220 100644 > > --- a/drivers/remoteproc/remoteproc_core.c > > +++ b/drivers/remoteproc/remoteproc_core.c > > @@ -1556,6 +1556,21 @@ static int rproc_set_loaded_rsc_table(struct rproc > > *rproc) > > return ret; > > } > > > > + /* > > +* If it is possible to detach the remote processor, keep an untouched > > +* copy of the resource table. That way we can start fresh again when > > +* the remote processor is re-attached, that is: > > +* > > +* DETACHED -> ATTACHED -> DETACHED -> ATTACHED > > +* > > +* Free'd in rproc_reset_loaded_rsc_table(). > > +*/ > > + if (rproc->ops->detach) { > > + rproc->clean_table = kmemdup(table_ptr, table_sz, GFP_KERNEL); > > + if (!rproc->clean_table) > > + return -ENOMEM; > > + } > > + > > rproc->cached_table = NULL; > > rproc->table_ptr = table_ptr; > > rproc->table_sz = table_sz; > > @@ -1563,6 +1578,65 @@ static int rproc_set_loaded_rsc_table(struct rproc > > *rproc) > > return 0; > > } > > > > +static int rproc_reset_loaded_rsc_table(struct rproc *rproc) > > I spent some time to review this function that handles both the resource table > for both the stop and detach. To make it easier to read, I would divide it > into > two functions. I suspected rproc_reset_loaded_rsc_table() was trying to do too many things for its own good and you just confirmed that. > I added a proposal at the end of this mail. > > Regards, > Arnaud > > > +{ > > + struct resource_table *table_ptr; > > + > > + /* > > +* The cached table is already set if the remote processor was started > > +* by the remoteproc core. > > +*/ > > + if (rproc->state == RPROC_RUNNING) { > > + rproc->table_ptr = rproc->cached_table; > > + return 0; > > + } > > + > > + /* A resource table was never retrieved, nothing to do here */ > > + if (!rproc->table_ptr) > > + return 0; > > + > > + /* > > +* If we made it to this point a cached_table _must_ have been > > +* allocated in rproc_set_loaded_rsc_table(). If one isn't present > > +* something went really wrong and we must complain. > > +*/ > > + if (WARN_ON(!rproc->clean_table)) > > + return -EINVAL; > > + > > + /* Remember where the external entity installed the resource table */ > > + table_ptr = rproc->table_ptr; > > + > > + /* > > +* Make a copy of the resource table currently used by the remote > > +* processor. Free'd in rproc_detach() or rproc_shutdown(). > > +*/ > > + rproc->cached_table = kmemdup(rproc->table_ptr, > > + rproc->table_sz, GFP_KERNEL); > > + if (!rproc->cached_table) > > + return -ENOMEM; > > + > > + /* > > +* Use a copy of the resource table for the remainder of the > > +* shutdown process. > > +*/ > > + rproc->table_ptr = rproc->cached_table; > > + > > + /* > > +* Reset the memory area where the firmware loaded the resource table > > +* to its original value. That way when we re-attach the remote > > +* processor the resource table is clean an
Re: [PATCH v6 15/16] remoteproc: Properly deal with a detach request when attached
On 2/24/21 12:35 AM, Mathieu Poirier wrote: > This patch introduces the capability to detach a remote processor > that has been attached by the remoteproc core. For that to happen > a rproc::ops::detach() operation needs to be available. > > Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen Thanks, Arnaud > --- > New for V6: > - The RPROC_RUNNING -> RPROC_DETACHED transition is no longer permitted > to avoid dealing with complex resource table management problems. > - Removed Peng and Arnaud's RB tags because of the above. > --- > > drivers/remoteproc/remoteproc_cdev.c | 5 + > drivers/remoteproc/remoteproc_sysfs.c | 5 + > 2 files changed, 10 insertions(+) > > diff --git a/drivers/remoteproc/remoteproc_cdev.c > b/drivers/remoteproc/remoteproc_cdev.c > index 0249d8f6c3f8..2db494816d5f 100644 > --- a/drivers/remoteproc/remoteproc_cdev.c > +++ b/drivers/remoteproc/remoteproc_cdev.c > @@ -43,6 +43,11 @@ static ssize_t rproc_cdev_write(struct file *filp, const > char __user *buf, size_ > return -EINVAL; > > rproc_shutdown(rproc); > + } else if (!strncmp(cmd, "detach", len)) { > + if (rproc->state != RPROC_ATTACHED) > + return -EINVAL; > + > + ret = rproc_detach(rproc); > } else { > dev_err(&rproc->dev, "Unrecognized option\n"); > ret = -EINVAL; > diff --git a/drivers/remoteproc/remoteproc_sysfs.c > b/drivers/remoteproc/remoteproc_sysfs.c > index 09eb700c5e7e..ad3dd208024c 100644 > --- a/drivers/remoteproc/remoteproc_sysfs.c > +++ b/drivers/remoteproc/remoteproc_sysfs.c > @@ -207,6 +207,11 @@ static ssize_t state_store(struct device *dev, > return -EINVAL; > > rproc_shutdown(rproc); > + } else if (sysfs_streq(buf, "detach")) { > + if (rproc->state != RPROC_ATTACHED) > + return -EINVAL; > + > + ret = rproc_detach(rproc); > } else { > dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); > ret = -EINVAL; >
Re: [PATCH v6 14/16] remoteproc: Properly deal with a stop request when attached
On 2/24/21 12:35 AM, Mathieu Poirier wrote: > Allow a remote processor that was started by another entity to be > switched off by the remoteproc core. For that to happen a > rproc::ops::stop() operation needs to be available. > > Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen Thanks, Arnaud > --- > New for V6: > - Removed state check in rproc_shutdown() as it is already done in > in calling functions. > - rproc_shutdown() doesn't return an error code to keep legacy behevior. > - Removed Peng and Arnaud's RB tags because of the above. > --- > > drivers/remoteproc/remoteproc_cdev.c | 3 ++- > drivers/remoteproc/remoteproc_core.c | 4 > drivers/remoteproc/remoteproc_sysfs.c | 3 ++- > 3 files changed, 8 insertions(+), 2 deletions(-) > > diff --git a/drivers/remoteproc/remoteproc_cdev.c > b/drivers/remoteproc/remoteproc_cdev.c > index b2cee9afb41b..0249d8f6c3f8 100644 > --- a/drivers/remoteproc/remoteproc_cdev.c > +++ b/drivers/remoteproc/remoteproc_cdev.c > @@ -38,7 +38,8 @@ static ssize_t rproc_cdev_write(struct file *filp, const > char __user *buf, size_ > > ret = rproc_boot(rproc); > } else if (!strncmp(cmd, "stop", len)) { > - if (rproc->state != RPROC_RUNNING) > + if (rproc->state != RPROC_RUNNING && > + rproc->state != RPROC_ATTACHED) > return -EINVAL; > > rproc_shutdown(rproc); > diff --git a/drivers/remoteproc/remoteproc_core.c > b/drivers/remoteproc/remoteproc_core.c > index 0dc518a24104..00452da25fba 100644 > --- a/drivers/remoteproc/remoteproc_core.c > +++ b/drivers/remoteproc/remoteproc_core.c > @@ -1758,6 +1758,10 @@ static int rproc_stop(struct rproc *rproc, bool > crashed) > struct device *dev = &rproc->dev; > int ret; > > + /* No need to continue if a stop() operation has not been provided */ > + if (!rproc->ops->stop) > + return -EINVAL; > + > /* Stop any subdevices for the remote processor */ > rproc_stop_subdevices(rproc, crashed); > > diff --git a/drivers/remoteproc/remoteproc_sysfs.c > b/drivers/remoteproc/remoteproc_sysfs.c > index 66801e6fe5cd..09eb700c5e7e 100644 > --- a/drivers/remoteproc/remoteproc_sysfs.c > +++ b/drivers/remoteproc/remoteproc_sysfs.c > @@ -202,7 +202,8 @@ static ssize_t state_store(struct device *dev, > if (ret) > dev_err(&rproc->dev, "Boot failed: %d\n", ret); > } else if (sysfs_streq(buf, "stop")) { > - if (rproc->state != RPROC_RUNNING) > + if (rproc->state != RPROC_RUNNING && > + rproc->state != RPROC_ATTACHED) > return -EINVAL; > > rproc_shutdown(rproc); >
Re: [PATCH v6 11/16] remoteproc: Properly deal with the resource table when attached
On 2/24/21 12:35 AM, Mathieu Poirier wrote: > If it is possible to detach the remote processor, keep an untouched > copy of the resource table. That way we can start from the same > resource table without having to worry about original values or what > elements the startup code has changed when re-attaching to the remote > processor. > > Signed-off-by: Mathieu Poirier > --- > New for V6: > - Double free of the cached table has been fixed. > - rproc_reset_loaded_rsc_table() has seen a complete re-write. > - rproc_stop() now calls rproc_reset_loaded_rsc_table() rather than > dealing with the cached. This allows to properly shutdown a > remote processor that was attached to. > --- > > drivers/remoteproc/remoteproc_core.c | 86 +++- > include/linux/remoteproc.h | 3 + > 2 files changed, 88 insertions(+), 1 deletion(-) > > diff --git a/drivers/remoteproc/remoteproc_core.c > b/drivers/remoteproc/remoteproc_core.c > index fc01b29290a6..3a4692cc5220 100644 > --- a/drivers/remoteproc/remoteproc_core.c > +++ b/drivers/remoteproc/remoteproc_core.c > @@ -1556,6 +1556,21 @@ static int rproc_set_loaded_rsc_table(struct rproc > *rproc) > return ret; > } > > + /* > + * If it is possible to detach the remote processor, keep an untouched > + * copy of the resource table. That way we can start fresh again when > + * the remote processor is re-attached, that is: > + * > + * DETACHED -> ATTACHED -> DETACHED -> ATTACHED > + * > + * Free'd in rproc_reset_loaded_rsc_table(). > + */ > + if (rproc->ops->detach) { > + rproc->clean_table = kmemdup(table_ptr, table_sz, GFP_KERNEL); > + if (!rproc->clean_table) > + return -ENOMEM; > + } > + > rproc->cached_table = NULL; > rproc->table_ptr = table_ptr; > rproc->table_sz = table_sz; > @@ -1563,6 +1578,65 @@ static int rproc_set_loaded_rsc_table(struct rproc > *rproc) > return 0; > } > > +static int rproc_reset_loaded_rsc_table(struct rproc *rproc) I spent some time to review this function that handles both the resource table for both the stop and detach. To make it easier to read, I would divide it into two functions. I added a proposal at the end of this mail. Regards, Arnaud > +{ > + struct resource_table *table_ptr; > + > + /* > + * The cached table is already set if the remote processor was started > + * by the remoteproc core. > + */ > + if (rproc->state == RPROC_RUNNING) { > + rproc->table_ptr = rproc->cached_table; > + return 0; > + } > + > + /* A resource table was never retrieved, nothing to do here */ > + if (!rproc->table_ptr) > + return 0; > + > + /* > + * If we made it to this point a cached_table _must_ have been > + * allocated in rproc_set_loaded_rsc_table(). If one isn't present > + * something went really wrong and we must complain. > + */ > + if (WARN_ON(!rproc->clean_table)) > + return -EINVAL; > + > + /* Remember where the external entity installed the resource table */ > + table_ptr = rproc->table_ptr; > + > + /* > + * Make a copy of the resource table currently used by the remote > + * processor. Free'd in rproc_detach() or rproc_shutdown(). > + */ > + rproc->cached_table = kmemdup(rproc->table_ptr, > + rproc->table_sz, GFP_KERNEL); > + if (!rproc->cached_table) > + return -ENOMEM; > + > + /* > + * Use a copy of the resource table for the remainder of the > + * shutdown process. > + */ > + rproc->table_ptr = rproc->cached_table; > + > + /* > + * Reset the memory area where the firmware loaded the resource table > + * to its original value. That way when we re-attach the remote > + * processor the resource table is clean and ready to be used again. > + */ > + memcpy(table_ptr, rproc->clean_table, rproc->table_sz); > + > + /* > + * The clean resource table is no longer needed. Allocated in > + * rproc_set_loaded_rsc_table(). > + */ > + kfree(rproc->clean_table); > + > + return 0; > +} > + > /* > * Attach to remote processor - similar to rproc_fw_boot() but without > * the steps that deal with the firmware image. > @@ -1688,7 +1762,11 @@ static int rproc_stop(struct rproc *rproc, bool > crashed) > rproc_stop_subdevices(rproc, crashed); >
[PATCH v6 11/16] remoteproc: Properly deal with the resource table when attached
If it is possible to detach the remote processor, keep an untouched copy of the resource table. That way we can start from the same resource table without having to worry about original values or what elements the startup code has changed when re-attaching to the remote processor. Signed-off-by: Mathieu Poirier --- New for V6: - Double free of the cached table has been fixed. - rproc_reset_loaded_rsc_table() has seen a complete re-write. - rproc_stop() now calls rproc_reset_loaded_rsc_table() rather than dealing with the cached. This allows to properly shutdown a remote processor that was attached to. --- drivers/remoteproc/remoteproc_core.c | 86 +++- include/linux/remoteproc.h | 3 + 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index fc01b29290a6..3a4692cc5220 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1556,6 +1556,21 @@ static int rproc_set_loaded_rsc_table(struct rproc *rproc) return ret; } + /* +* If it is possible to detach the remote processor, keep an untouched +* copy of the resource table. That way we can start fresh again when +* the remote processor is re-attached, that is: +* +* DETACHED -> ATTACHED -> DETACHED -> ATTACHED +* +* Free'd in rproc_reset_loaded_rsc_table(). +*/ + if (rproc->ops->detach) { + rproc->clean_table = kmemdup(table_ptr, table_sz, GFP_KERNEL); + if (!rproc->clean_table) + return -ENOMEM; + } + rproc->cached_table = NULL; rproc->table_ptr = table_ptr; rproc->table_sz = table_sz; @@ -1563,6 +1578,65 @@ static int rproc_set_loaded_rsc_table(struct rproc *rproc) return 0; } +static int rproc_reset_loaded_rsc_table(struct rproc *rproc) +{ + struct resource_table *table_ptr; + + /* +* The cached table is already set if the remote processor was started +* by the remoteproc core. +*/ + if (rproc->state == RPROC_RUNNING) { + rproc->table_ptr = rproc->cached_table; + return 0; + } + + /* A resource table was never retrieved, nothing to do here */ + if (!rproc->table_ptr) + return 0; + + /* +* If we made it to this point a cached_table _must_ have been +* allocated in rproc_set_loaded_rsc_table(). If one isn't present +* something went really wrong and we must complain. +*/ + if (WARN_ON(!rproc->clean_table)) + return -EINVAL; + + /* Remember where the external entity installed the resource table */ + table_ptr = rproc->table_ptr; + + /* +* Make a copy of the resource table currently used by the remote +* processor. Free'd in rproc_detach() or rproc_shutdown(). +*/ + rproc->cached_table = kmemdup(rproc->table_ptr, + rproc->table_sz, GFP_KERNEL); + if (!rproc->cached_table) + return -ENOMEM; + + /* +* Use a copy of the resource table for the remainder of the +* shutdown process. +*/ + rproc->table_ptr = rproc->cached_table; + + /* +* Reset the memory area where the firmware loaded the resource table +* to its original value. That way when we re-attach the remote +* processor the resource table is clean and ready to be used again. +*/ + memcpy(table_ptr, rproc->clean_table, rproc->table_sz); + + /* +* The clean resource table is no longer needed. Allocated in +* rproc_set_loaded_rsc_table(). +*/ + kfree(rproc->clean_table); + + return 0; +} + /* * Attach to remote processor - similar to rproc_fw_boot() but without * the steps that deal with the firmware image. @@ -1688,7 +1762,11 @@ static int rproc_stop(struct rproc *rproc, bool crashed) rproc_stop_subdevices(rproc, crashed); /* the installed resource table is no longer accessible */ - rproc->table_ptr = rproc->cached_table; + ret = rproc_reset_loaded_rsc_table(rproc); + if (ret) { + dev_err(dev, "can't reset resource table: %d\n", ret); + return ret; + } /* power off the remote processor */ ret = rproc->ops->stop(rproc); @@ -1721,6 +1799,9 @@ static int __rproc_detach(struct rproc *rproc) /* Stop any subdevices for the remote processor */ rproc_stop_subdevices(rproc, false); + /* the installed resource table is no longer accessible */ + ret = rproc_reset_loaded_rsc_table(rproc); + /* Tell the remote processor the
[PATCH v6 12/16] remoteproc: Properly deal with a kernel panic when attached
The panic handler operation of registered remote processors should also be called when remote processors have been attached to. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 3a4692cc5220..0dc518a24104 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2684,7 +2684,11 @@ static int rproc_panic_handler(struct notifier_block *nb, unsigned long event, rcu_read_lock(); list_for_each_entry_rcu(rproc, &rproc_list, node) { - if (!rproc->ops->panic || rproc->state != RPROC_RUNNING) + if (!rproc->ops->panic) + continue; + + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) continue; d = rproc->ops->panic(rproc); -- 2.25.1
[PATCH v6 13/16] remoteproc: Properly deal with a start request when attached
This patch takes into account scenarios where a remote processor has been attached to when receiving a "start" command from sysfs. As with the case with the running state, the command can't be carried out if the remote processor is already in operation. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_cdev.c | 3 ++- drivers/remoteproc/remoteproc_sysfs.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index b19ea3057bde..b2cee9afb41b 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -32,7 +32,8 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ return -EFAULT; if (!strncmp(cmd, "start", len)) { - if (rproc->state == RPROC_RUNNING) + if (rproc->state == RPROC_RUNNING || + rproc->state == RPROC_ATTACHED) return -EBUSY; ret = rproc_boot(rproc); diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index f9694def9b54..66801e6fe5cd 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -194,7 +194,8 @@ static ssize_t state_store(struct device *dev, int ret = 0; if (sysfs_streq(buf, "start")) { - if (rproc->state == RPROC_RUNNING) + if (rproc->state == RPROC_RUNNING || + rproc->state == RPROC_ATTACHED) return -EBUSY; ret = rproc_boot(rproc); -- 2.25.1
[PATCH v6 14/16] remoteproc: Properly deal with a stop request when attached
Allow a remote processor that was started by another entity to be switched off by the remoteproc core. For that to happen a rproc::ops::stop() operation needs to be available. Signed-off-by: Mathieu Poirier --- New for V6: - Removed state check in rproc_shutdown() as it is already done in in calling functions. - rproc_shutdown() doesn't return an error code to keep legacy behevior. - Removed Peng and Arnaud's RB tags because of the above. --- drivers/remoteproc/remoteproc_cdev.c | 3 ++- drivers/remoteproc/remoteproc_core.c | 4 drivers/remoteproc/remoteproc_sysfs.c | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index b2cee9afb41b..0249d8f6c3f8 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -38,7 +38,8 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ ret = rproc_boot(rproc); } else if (!strncmp(cmd, "stop", len)) { - if (rproc->state != RPROC_RUNNING) + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) return -EINVAL; rproc_shutdown(rproc); diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 0dc518a24104..00452da25fba 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1758,6 +1758,10 @@ static int rproc_stop(struct rproc *rproc, bool crashed) struct device *dev = &rproc->dev; int ret; + /* No need to continue if a stop() operation has not been provided */ + if (!rproc->ops->stop) + return -EINVAL; + /* Stop any subdevices for the remote processor */ rproc_stop_subdevices(rproc, crashed); diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 66801e6fe5cd..09eb700c5e7e 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -202,7 +202,8 @@ static ssize_t state_store(struct device *dev, if (ret) dev_err(&rproc->dev, "Boot failed: %d\n", ret); } else if (sysfs_streq(buf, "stop")) { - if (rproc->state != RPROC_RUNNING) + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) return -EINVAL; rproc_shutdown(rproc); -- 2.25.1
[PATCH v6 15/16] remoteproc: Properly deal with a detach request when attached
This patch introduces the capability to detach a remote processor that has been attached by the remoteproc core. For that to happen a rproc::ops::detach() operation needs to be available. Signed-off-by: Mathieu Poirier --- New for V6: - The RPROC_RUNNING -> RPROC_DETACHED transition is no longer permitted to avoid dealing with complex resource table management problems. - Removed Peng and Arnaud's RB tags because of the above. --- drivers/remoteproc/remoteproc_cdev.c | 5 + drivers/remoteproc/remoteproc_sysfs.c | 5 + 2 files changed, 10 insertions(+) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index 0249d8f6c3f8..2db494816d5f 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -43,6 +43,11 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ return -EINVAL; rproc_shutdown(rproc); + } else if (!strncmp(cmd, "detach", len)) { + if (rproc->state != RPROC_ATTACHED) + return -EINVAL; + + ret = rproc_detach(rproc); } else { dev_err(&rproc->dev, "Unrecognized option\n"); ret = -EINVAL; diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 09eb700c5e7e..ad3dd208024c 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -207,6 +207,11 @@ static ssize_t state_store(struct device *dev, return -EINVAL; rproc_shutdown(rproc); + } else if (sysfs_streq(buf, "detach")) { + if (rproc->state != RPROC_ATTACHED) + return -EINVAL; + + ret = rproc_detach(rproc); } else { dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); ret = -EINVAL; -- 2.25.1
Re: [PATCH v5 13/19] remoteproc: Properly deal with the resource table
On 2/12/21 12:46 AM, Mathieu Poirier wrote: > If it is possible to detach the remote processor, keep an untouched > copy of the resource table. That way we can start from the same > resource table without having to worry about original values or what > elements the startup code has changed when re-attaching to the remote > processor. > > Reported-by: Arnaud POULIQUEN > Signed-off-by: Mathieu Poirier > --- > drivers/remoteproc/remoteproc_core.c | 70 ++ > drivers/remoteproc/remoteproc_elf_loader.c | 24 +++- > include/linux/remoteproc.h | 3 + > 3 files changed, 95 insertions(+), 2 deletions(-) > > diff --git a/drivers/remoteproc/remoteproc_core.c > b/drivers/remoteproc/remoteproc_core.c > index 660dcc002ff6..9a77cb6d6470 100644 > --- a/drivers/remoteproc/remoteproc_core.c > +++ b/drivers/remoteproc/remoteproc_core.c > @@ -1527,7 +1527,9 @@ static int rproc_fw_boot(struct rproc *rproc, const > struct firmware *fw) > clean_up_resources: > rproc_resource_cleanup(rproc); > kfree(rproc->cached_table); > + kfree(rproc->clean_table); > rproc->cached_table = NULL; > + rproc->clean_table = NULL; > rproc->table_ptr = NULL; > unprepare_rproc: > /* release HW resources if needed */ > @@ -1555,6 +1557,23 @@ static int rproc_set_loaded_rsc_table(struct rproc > *rproc) > return ret; > } > > + /* > + * If it is possible to detach the remote processor, keep an untouched > + * copy of the resource table. That way we can start fresh again when > + * the remote processor is re-attached, that is: > + * > + * DETACHED -> ATTACHED -> DETACHED -> ATTACHED > + * > + * A clean copy of the table is also taken in rproc_elf_load_rsc_table() > + * for cases where the remote processor is booted by the remoteproc > + * core and later detached from. > + */ > + if (rproc->ops->detach) { > + rproc->clean_table = kmemdup(table_ptr, table_sz, GFP_KERNEL); > + if (!rproc->clean_table) > + return -ENOMEM; > + } > + > /* >* The resource table is already loaded in device memory, no need >* to work with a cached table. > @@ -1566,6 +1585,40 @@ static int rproc_set_loaded_rsc_table(struct rproc > *rproc) > return 0; > } > > +static int rproc_reset_loaded_rsc_table(struct rproc *rproc) > +{ > + /* > + * In order to detach() from a remote processor a clean resource table > + * _must_ have been allocated at boot time, either from rproc_fw_boot() > + * or from rproc_attach(). If one isn't present something went really > + * wrong and we must complain. > + */ > + if (WARN_ON(!rproc->clean_table)) > + return -EINVAL; > + > + /* > + * Install the clean resource table where the firmware, i.e > + * rproc_get_loaded_rsc_table(), expects it. > + */ > + memcpy(rproc->table_ptr, rproc->clean_table, rproc->table_sz); > + > + /* > + * If the remote processors was started by the core then a cached_table > + * is present and we must follow the same cleanup sequence as we would > + * for a shutdown(). As it is in rproc_stop(), use the cached resource > + * table for the rest of the detach process since ->table_ptr will > + * become invalid as soon as carveouts are released in > + * rproc_resource_cleanup(). > + * > + * If the remote processor was started by an external entity the > + * cached_table is NULL and the rest of the cleanup code in > + * rproc_free_vring() can deal with that. > + */ > + rproc->table_ptr = rproc->cached_table; > + > + return 0; > +} > + > /* > * Attach to remote processor - similar to rproc_fw_boot() but without > * the steps that deal with the firmware image. > @@ -1947,7 +2000,10 @@ void rproc_shutdown(struct rproc *rproc) > > /* Free the copy of the resource table */ > kfree(rproc->cached_table); > + /* Free the clean resource table */ > + kfree(rproc->clean_table); > rproc->cached_table = NULL; > + rproc->clean_table = NULL; > rproc->table_ptr = NULL; > out: > mutex_unlock(&rproc->lock); > @@ -2000,6 +2056,16 @@ int rproc_detach(struct rproc *rproc) > goto out; > } > > + /* > + * Install a clean resource table for re-attach while > + * rproc->table_ptr is still valid. > + */ > + ret = rproc_reset_loaded_rsc_table(rp
Re: [PATCH v5 13/19] remoteproc: Properly deal with the resource table
Hi Mathieu, url: https://github.com/0day-ci/linux/commits/Mathieu-Poirier/remoteproc-Add-support-for-detaching-a-remote-processor/20210212-075607 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next config: ia64-randconfig-m031-20210209 (attached as .config) compiler: ia64-linux-gcc (GCC) 9.3.0 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot Reported-by: Dan Carpenter smatch warnings: drivers/remoteproc/remoteproc_core.c:2080 rproc_detach() error: double free of 'rproc->cached_table' vim +2080 drivers/remoteproc/remoteproc_core.c eab58da78fe46f Mathieu Poirier 2021-02-11 2069 /* clean up all acquired resources */ eab58da78fe46f Mathieu Poirier 2021-02-11 2070 rproc_resource_cleanup(rproc); eab58da78fe46f Mathieu Poirier 2021-02-11 2071 eab58da78fe46f Mathieu Poirier 2021-02-11 2072 /* release HW resources if needed */ eab58da78fe46f Mathieu Poirier 2021-02-11 2073 rproc_unprepare_device(rproc); eab58da78fe46f Mathieu Poirier 2021-02-11 2074 eab58da78fe46f Mathieu Poirier 2021-02-11 2075 rproc_disable_iommu(rproc); eab58da78fe46f Mathieu Poirier 2021-02-11 2076 66e2fed7a4bb20 Mathieu Poirier 2021-02-11 2077 /* Free the copy of the resource table */ 66e2fed7a4bb20 Mathieu Poirier 2021-02-11 2078 kfree(rproc->cached_table); ^^ eab58da78fe46f Mathieu Poirier 2021-02-11 2079 /* Follow the same sequence as in rproc_shutdown() */ eab58da78fe46f Mathieu Poirier 2021-02-11 @2080 kfree(rproc->cached_table); ^^ Double free. eab58da78fe46f Mathieu Poirier 2021-02-11 2081 rproc->cached_table = NULL; 66e2fed7a4bb20 Mathieu Poirier 2021-02-11 2082 rproc->clean_table = NULL; eab58da78fe46f Mathieu Poirier 2021-02-11 2083 rproc->table_ptr = NULL; 66e2fed7a4bb20 Mathieu Poirier 2021-02-11 2084 eab58da78fe46f Mathieu Poirier 2021-02-11 2085 out: eab58da78fe46f Mathieu Poirier 2021-02-11 2086 mutex_unlock(&rproc->lock); eab58da78fe46f Mathieu Poirier 2021-02-11 2087 return ret; eab58da78fe46f Mathieu Poirier 2021-02-11 2088 } --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org .config.gz Description: application/gzip
Re: [PATCH v5 13/19] remoteproc: Properly deal with the resource table (fwd)
There are identical kfrees on lines 2078 and 2080. julia -- Forwarded message -- Date: Fri, 12 Feb 2021 10:45:50 +0800 From: kernel test robot To: kbu...@lists.01.org Cc: l...@intel.com, Julia Lawall Subject: Re: [PATCH v5 13/19] remoteproc: Properly deal with the resource table CC: kbuild-...@lists.01.org In-Reply-To: <20210211234627.2669674-14-mathieu.poir...@linaro.org> References: <20210211234627.2669674-14-mathieu.poir...@linaro.org> TO: Mathieu Poirier TO: o...@wizery.com TO: bjorn.anders...@linaro.org TO: arnaud.pouliq...@st.com CC: robh...@kernel.org CC: mcoquelin.st...@gmail.com CC: alexandre.tor...@st.com CC: linux-remotep...@vger.kernel.org CC: devicet...@vger.kernel.org CC: linux-kernel@vger.kernel.org CC: linux-arm-ker...@lists.infradead.org Hi Mathieu, I love your patch! Perhaps something to improve: [auto build test WARNING on robh/for-next] [also build test WARNING on linus/master v5.11-rc7 next-20210211] [cannot apply to remoteproc/for-next rpmsg/for-next] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch] url: https://github.com/0day-ci/linux/commits/Mathieu-Poirier/remoteproc-Add-support-for-detaching-a-remote-processor/20210212-075607 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next :: branch date: 3 hours ago :: commit date: 3 hours ago config: openrisc-randconfig-c003-20210209 (attached as .config) compiler: or1k-linux-gcc (GCC) 9.3.0 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot Reported-by: Julia Lawall "coccinelle warnings: (new ones prefixed by >>)" >> drivers/remoteproc/remoteproc_core.c:2080:7-26: ERROR: reference preceded by >> free on line 2078 vim +2080 drivers/remoteproc/remoteproc_core.c 400e64df6b237e Ohad Ben-Cohen 2011-10-20 2012 eab58da78fe46f Mathieu Poirier 2021-02-11 2013 /** eab58da78fe46f Mathieu Poirier 2021-02-11 2014 * rproc_detach() - Detach the remote processor from the eab58da78fe46f Mathieu Poirier 2021-02-11 2015 * remoteproc core eab58da78fe46f Mathieu Poirier 2021-02-11 2016 * eab58da78fe46f Mathieu Poirier 2021-02-11 2017 * @rproc: the remote processor eab58da78fe46f Mathieu Poirier 2021-02-11 2018 * eab58da78fe46f Mathieu Poirier 2021-02-11 2019 * Detach a remote processor (previously attached to with rproc_attach()). eab58da78fe46f Mathieu Poirier 2021-02-11 2020 * eab58da78fe46f Mathieu Poirier 2021-02-11 2021 * In case @rproc is still being used by an additional user(s), then eab58da78fe46f Mathieu Poirier 2021-02-11 2022 * this function will just decrement the power refcount and exit, eab58da78fe46f Mathieu Poirier 2021-02-11 2023 * without disconnecting the device. eab58da78fe46f Mathieu Poirier 2021-02-11 2024 * eab58da78fe46f Mathieu Poirier 2021-02-11 2025 * Function rproc_detach() calls __rproc_detach() in order to let a remote eab58da78fe46f Mathieu Poirier 2021-02-11 2026 * processor know that services provided by the application processor are eab58da78fe46f Mathieu Poirier 2021-02-11 2027 * no longer available. From there it should be possible to remove the eab58da78fe46f Mathieu Poirier 2021-02-11 2028 * platform driver and even power cycle the application processor (if the HW eab58da78fe46f Mathieu Poirier 2021-02-11 2029 * supports it) without needing to switch off the remote processor. eab58da78fe46f Mathieu Poirier 2021-02-11 2030 */ eab58da78fe46f Mathieu Poirier 2021-02-11 2031 int rproc_detach(struct rproc *rproc) eab58da78fe46f Mathieu Poirier 2021-02-11 2032 { eab58da78fe46f Mathieu Poirier 2021-02-11 2033 struct device *dev = &rproc->dev; eab58da78fe46f Mathieu Poirier 2021-02-11 2034 int ret; eab58da78fe46f Mathieu Poirier 2021-02-11 2035 eab58da78fe46f Mathieu Poirier 2021-02-11 2036 ret = mutex_lock_interruptible(&rproc->lock); eab58da78fe46f Mathieu Poirier 2021-02-11 2037 if (ret) { eab58da78fe46f Mathieu Poirier 2021-02-11 2038 dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); eab58da78fe46f Mathieu Poirier 2021-02-11 2039 return ret; eab58da78fe46f Mathieu Poirier 2021-02-11 2040 } eab58da78fe46f Mathieu Poirier 2021-02-11 2041 eab58da78fe46f Mathieu Poirier 2021-02-11 2042 if (rproc->state != RPROC_RUNNING && rproc->state != RPROC_ATTACHED) { eab58da78fe46f Mathieu Poirier 2021-02-11 2043 ret = -EPERM; eab58da78fe46f Mathieu Poirier 2021-02-11 2044 goto out; eab58da78fe46f Mathieu Poirier 2021-02-11 2045 } eab58da78fe46f Mathieu Poirier 2021-02-11 2046 eab58da78fe46f Mathieu Poirier 2021-02-11 2047 /* if the remote proc is still needed, bail out */
[tip: core/rcu] torture: Make torture.sh rcuscale and refscale deal with allmodconfig
The following commit has been merged into the core/rcu branch of tip: Commit-ID: 7a99487c76aad613b7533e3ea1b8d3eaf30ca37e Gitweb: https://git.kernel.org/tip/7a99487c76aad613b7533e3ea1b8d3eaf30ca37e Author:Paul E. McKenney AuthorDate:Tue, 24 Nov 2020 18:57:47 -08:00 Committer: Paul E. McKenney CommitterDate: Wed, 06 Jan 2021 17:03:42 -08:00 torture: Make torture.sh rcuscale and refscale deal with allmodconfig The .mod.c files created by allmodconfig builds interfers with the approach torture.sh uses to enumerate types of rcuscale and refscale runs. This commit therefore tightens the pattern matching to avoid this interference. Signed-off-by: Paul E. McKenney --- tools/testing/selftests/rcutorture/bin/torture.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/rcutorture/bin/torture.sh b/tools/testing/selftests/rcutorture/bin/torture.sh index 8e66797..a89b521 100755 --- a/tools/testing/selftests/rcutorture/bin/torture.sh +++ b/tools/testing/selftests/rcutorture/bin/torture.sh @@ -302,7 +302,7 @@ fi if test "$do_refscale" = yes then - primlist="`grep '\.name[]*=' kernel/rcu/refscale*.c | sed -e 's/^[^"]*"//' -e 's/".*$//'`" + primlist="`grep '\.name[]*=' kernel/rcu/refscale.c | sed -e 's/^[^"]*"//' -e 's/".*$//'`" else primlist= fi @@ -314,7 +314,7 @@ done if test "$do_rcuscale" = yes then - primlist="`grep '\.name[]*=' kernel/rcu/rcuscale*.c | sed -e 's/^[^"]*"//' -e 's/".*$//'`" + primlist="`grep '\.name[]*=' kernel/rcu/rcuscale.c | sed -e 's/^[^"]*"//' -e 's/".*$//'`" else primlist= fi
[PATCH v5 18/19] remoteproc: Properly deal with detach request
This patch introduces the capability to detach a remote processor that has been attached to or booted by the remoteproc core. For that to happen a rproc::ops::detach() operation need to be available. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_cdev.c | 6 ++ drivers/remoteproc/remoteproc_sysfs.c | 6 ++ 2 files changed, 12 insertions(+) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index 61541bc7d26c..f7645f289563 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -43,6 +43,12 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ return -EINVAL; ret = rproc_shutdown(rproc); + } else if (!strncmp(cmd, "detach", len)) { + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) + return -EINVAL; + + ret = rproc_detach(rproc); } else { dev_err(&rproc->dev, "Unrecognized option\n"); ret = -EINVAL; diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 7d281cfe3e03..5a239df5877e 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -207,6 +207,12 @@ static ssize_t state_store(struct device *dev, return -EINVAL; ret = rproc_shutdown(rproc); + } else if (sysfs_streq(buf, "detach")) { + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) + return -EINVAL; + + ret = rproc_detach(rproc); } else { dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); ret = -EINVAL; -- 2.25.1
[PATCH v5 17/19] remoteproc: Properly deal with a start request when attached
This patch takes into account scenarios where a remote processor has been attached to when receiving a "start" command from sysfs. As with the "running" case, the command can't be carried out if the remote processor is already in operation. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_cdev.c | 3 ++- drivers/remoteproc/remoteproc_sysfs.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index d06f8d4919c7..61541bc7d26c 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -32,7 +32,8 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ return -EFAULT; if (!strncmp(cmd, "start", len)) { - if (rproc->state == RPROC_RUNNING) + if (rproc->state == RPROC_RUNNING || + rproc->state == RPROC_ATTACHED) return -EBUSY; ret = rproc_boot(rproc); diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 3696f2ccc785..7d281cfe3e03 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -194,7 +194,8 @@ static ssize_t state_store(struct device *dev, int ret = 0; if (sysfs_streq(buf, "start")) { - if (rproc->state == RPROC_RUNNING) + if (rproc->state == RPROC_RUNNING || + rproc->state == RPROC_ATTACHED) return -EBUSY; ret = rproc_boot(rproc); -- 2.25.1
[PATCH v5 16/19] remoteproc: Properly deal with a stop request when attached
This patch introduces the capability to stop a remote processor that has been attached to by the remoteproc core. For that to happen a rproc::ops::stop() operation need to be available. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_cdev.c | 5 +++-- drivers/remoteproc/remoteproc_core.c | 6 +- drivers/remoteproc/remoteproc_sysfs.c | 5 +++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index b19ea3057bde..d06f8d4919c7 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -37,10 +37,11 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ ret = rproc_boot(rproc); } else if (!strncmp(cmd, "stop", len)) { - if (rproc->state != RPROC_RUNNING) + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) return -EINVAL; - rproc_shutdown(rproc); + ret = rproc_shutdown(rproc); } else { dev_err(&rproc->dev, "Unrecognized option\n"); ret = -EINVAL; diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 0dd9f02f52b6..12bd177aa8cd 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1740,6 +1740,10 @@ static int rproc_stop(struct rproc *rproc, bool crashed) struct device *dev = &rproc->dev; int ret; + /* No need to continue if a stop() operation has not been provided */ + if (!rproc->ops->stop) + return -EINVAL; + /* Stop any subdevices for the remote processor */ rproc_stop_subdevices(rproc, crashed); @@ -1977,7 +1981,7 @@ int rproc_shutdown(struct rproc *rproc) return ret; } - if (rproc->state != RPROC_RUNNING) { + if (rproc->state != RPROC_RUNNING && rproc->state != RPROC_ATTACHED) { ret = -EPERM; goto out; } diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index f9694def9b54..3696f2ccc785 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -201,10 +201,11 @@ static ssize_t state_store(struct device *dev, if (ret) dev_err(&rproc->dev, "Boot failed: %d\n", ret); } else if (sysfs_streq(buf, "stop")) { - if (rproc->state != RPROC_RUNNING) + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) return -EINVAL; - rproc_shutdown(rproc); + ret = rproc_shutdown(rproc); } else { dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); ret = -EINVAL; -- 2.25.1
[PATCH v5 15/19] remoteproc: Properly deal with a kernel panic when attached
The panic handler operation of registered remote processors should also be called when remote processors have been attached to. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 62f708662052..0dd9f02f52b6 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2693,7 +2693,11 @@ static int rproc_panic_handler(struct notifier_block *nb, unsigned long event, rcu_read_lock(); list_for_each_entry_rcu(rproc, &rproc_list, node) { - if (!rproc->ops->panic || rproc->state != RPROC_RUNNING) + if (!rproc->ops->panic) + continue; + + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) continue; d = rproc->ops->panic(rproc); -- 2.25.1
[PATCH v5 13/19] remoteproc: Properly deal with the resource table
If it is possible to detach the remote processor, keep an untouched copy of the resource table. That way we can start from the same resource table without having to worry about original values or what elements the startup code has changed when re-attaching to the remote processor. Reported-by: Arnaud POULIQUEN Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_core.c | 70 ++ drivers/remoteproc/remoteproc_elf_loader.c | 24 +++- include/linux/remoteproc.h | 3 + 3 files changed, 95 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 660dcc002ff6..9a77cb6d6470 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1527,7 +1527,9 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) clean_up_resources: rproc_resource_cleanup(rproc); kfree(rproc->cached_table); + kfree(rproc->clean_table); rproc->cached_table = NULL; + rproc->clean_table = NULL; rproc->table_ptr = NULL; unprepare_rproc: /* release HW resources if needed */ @@ -1555,6 +1557,23 @@ static int rproc_set_loaded_rsc_table(struct rproc *rproc) return ret; } + /* +* If it is possible to detach the remote processor, keep an untouched +* copy of the resource table. That way we can start fresh again when +* the remote processor is re-attached, that is: +* +* DETACHED -> ATTACHED -> DETACHED -> ATTACHED +* +* A clean copy of the table is also taken in rproc_elf_load_rsc_table() +* for cases where the remote processor is booted by the remoteproc +* core and later detached from. +*/ + if (rproc->ops->detach) { + rproc->clean_table = kmemdup(table_ptr, table_sz, GFP_KERNEL); + if (!rproc->clean_table) + return -ENOMEM; + } + /* * The resource table is already loaded in device memory, no need * to work with a cached table. @@ -1566,6 +1585,40 @@ static int rproc_set_loaded_rsc_table(struct rproc *rproc) return 0; } +static int rproc_reset_loaded_rsc_table(struct rproc *rproc) +{ + /* +* In order to detach() from a remote processor a clean resource table +* _must_ have been allocated at boot time, either from rproc_fw_boot() +* or from rproc_attach(). If one isn't present something went really +* wrong and we must complain. +*/ + if (WARN_ON(!rproc->clean_table)) + return -EINVAL; + + /* +* Install the clean resource table where the firmware, i.e +* rproc_get_loaded_rsc_table(), expects it. +*/ + memcpy(rproc->table_ptr, rproc->clean_table, rproc->table_sz); + + /* +* If the remote processors was started by the core then a cached_table +* is present and we must follow the same cleanup sequence as we would +* for a shutdown(). As it is in rproc_stop(), use the cached resource +* table for the rest of the detach process since ->table_ptr will +* become invalid as soon as carveouts are released in +* rproc_resource_cleanup(). +* +* If the remote processor was started by an external entity the +* cached_table is NULL and the rest of the cleanup code in +* rproc_free_vring() can deal with that. +*/ + rproc->table_ptr = rproc->cached_table; + + return 0; +} + /* * Attach to remote processor - similar to rproc_fw_boot() but without * the steps that deal with the firmware image. @@ -1947,7 +2000,10 @@ void rproc_shutdown(struct rproc *rproc) /* Free the copy of the resource table */ kfree(rproc->cached_table); + /* Free the clean resource table */ + kfree(rproc->clean_table); rproc->cached_table = NULL; + rproc->clean_table = NULL; rproc->table_ptr = NULL; out: mutex_unlock(&rproc->lock); @@ -2000,6 +2056,16 @@ int rproc_detach(struct rproc *rproc) goto out; } + /* +* Install a clean resource table for re-attach while +* rproc->table_ptr is still valid. +*/ + ret = rproc_reset_loaded_rsc_table(rproc); + if (ret) { + atomic_inc(&rproc->power); + goto out; + } + /* clean up all acquired resources */ rproc_resource_cleanup(rproc); @@ -2008,10 +2074,14 @@ int rproc_detach(struct rproc *rproc) rproc_disable_iommu(rproc); + /* Free the copy of the resource table */ + kfree(rproc->cached_table); /* Follow the same sequence as in rproc_shutdown() */ kfree(rproc->cached_tab
[PATCH 2/3] rcu: dont special case "all" handling; let bitmask deal with it
Now that the core bitmap parse code respects the "all" parameter, there is no need for RCU to have its own special check for it. Cc: Yury Norov Cc: Peter Zijlstra Cc: "Paul E. McKenney" Signed-off-by: Paul Gortmaker --- Documentation/admin-guide/kernel-parameters.txt | 4 +--- kernel/rcu/tree_plugin.h| 13 - 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index a10b545c2070..a116c0ff0a91 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -4037,9 +4037,7 @@ see CONFIG_RAS_CEC help text. rcu_nocbs= [KNL] - The argument is a cpu list, as described above, - except that the string "all" can be used to - specify every CPU on the system. + The argument is a cpu list, as described above. In kernels built with CONFIG_RCU_NOCB_CPU=y, set the specified list of CPUs to be no-callback CPUs. diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h index 7e291ce0a1d6..642ebd6569c7 100644 --- a/kernel/rcu/tree_plugin.h +++ b/kernel/rcu/tree_plugin.h @@ -1463,20 +1463,15 @@ static void rcu_cleanup_after_idle(void) /* * Parse the boot-time rcu_nocb_mask CPU list from the kernel parameters. - * The string after the "rcu_nocbs=" is either "all" for all CPUs, or a - * comma-separated list of CPUs and/or CPU ranges. If an invalid list is - * given, a warning is emitted and all CPUs are offloaded. + * If the list is invalid, a warning is emitted and all CPUs are offloaded. */ static int __init rcu_nocb_setup(char *str) { alloc_bootmem_cpumask_var(&rcu_nocb_mask); - if (!strcasecmp(str, "all")) + if (cpulist_parse(str, rcu_nocb_mask)) { + pr_warn("rcu_nocbs= bad CPU range, all CPUs set\n"); cpumask_setall(rcu_nocb_mask); - else - if (cpulist_parse(str, rcu_nocb_mask)) { - pr_warn("rcu_nocbs= bad CPU range, all CPUs set\n"); - cpumask_setall(rcu_nocb_mask); - } + } return 1; } __setup("rcu_nocbs=", rcu_nocb_setup); -- 2.17.1
Grsecurity GPL Violations: Linus/FSF/SFConservancy won't defend. Claw back your copyrights. BSD-in-Practice was not the deal.
Silence is consent. Are there FOSS developers making decent money via Patreon, GoFundMe, whatever? Yes, Grsecurity is making good money. They simply added a no-redistribution agreement to their patch of the Linux Kernel. ( https://perens.com/2017/06/28/warning-grsecurity-potential-contributory-infringement-risk-for-customers/ ) The FSF, Software Freedom Conservancy, and the Corporate Linux Kernel Developers all agree that this is fine (silence is consent). https://twitter.com/spendergrsec/status/1293155787859206146 Importantly, neither the FSF nor the SFC, nor in fact any actual lawyer agrees with this bizarre claim from an anonymous troll. More info about the source of the claim can be found here: https://grsecurity.net/setting_the_record_straight_on_oss_v_perens_part1 Thanks for doing your part, "Dr" to continue the troll's harrassment LOL. " #GRSecurity violates both the Linux kernel's copyright and the #GCC #copyright by forbidding redistribution of the patches (in their Access Agreement): which are non-seperable derivative works... Contributors should blanket-revoke their contributions from all free-takers since they didn't agree to BSD-in-Practice. They should also claw-back any transferred copyrights from the FSF using the 30 year clawback provision in the US Copyright Act. Design of how a program works is a copyrightable aspect (Ex: How RMS designed GCC 30 years ago or so etc) Had to repost this because the linux admins deleted the email: https://lkml.org/lkml/2020/12/28/2518 The message you requested cannot be found. The message you requested cannot be found. The message with the url http://feisty.lkml.org/lkml/2020/12/28/2518 does not exist in the database. Grsecurity GPL Violations: Bring a CASE act claim every time GrSecurity releases a new infringing work? (GRSecurity blatantly violates the clause in the Linux kernel and GCC copyright licenses regarding adding addtional terms between the licensee of the kernel / gcc and furthur down-the-line licensees, regarding derivative works) (The linux kernel has 1000s of copyright holders) (All who shake at the knees at the thought of initiating a federal Copyright lawsuit)
[PATCH tip/core/rcu 08/18] torture: Make torture.sh rcuscale and refscale deal with allmodconfig
From: "Paul E. McKenney" The .mod.c files created by allmodconfig builds interfers with the approach torture.sh uses to enumerate types of rcuscale and refscale runs. This commit therefore tightens the pattern matching to avoid this interference. Signed-off-by: Paul E. McKenney --- tools/testing/selftests/rcutorture/bin/torture.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/rcutorture/bin/torture.sh b/tools/testing/selftests/rcutorture/bin/torture.sh index 8e66797..a89b521 100755 --- a/tools/testing/selftests/rcutorture/bin/torture.sh +++ b/tools/testing/selftests/rcutorture/bin/torture.sh @@ -302,7 +302,7 @@ fi if test "$do_refscale" = yes then - primlist="`grep '\.name[]*=' kernel/rcu/refscale*.c | sed -e 's/^[^"]*"//' -e 's/".*$//'`" + primlist="`grep '\.name[]*=' kernel/rcu/refscale.c | sed -e 's/^[^"]*"//' -e 's/".*$//'`" else primlist= fi @@ -314,7 +314,7 @@ done if test "$do_rcuscale" = yes then - primlist="`grep '\.name[]*=' kernel/rcu/rcuscale*.c | sed -e 's/^[^"]*"//' -e 's/".*$//'`" + primlist="`grep '\.name[]*=' kernel/rcu/rcuscale.c | sed -e 's/^[^"]*"//' -e 's/".*$//'`" else primlist= fi -- 2.9.5
Grsecurity GPL Violations: Linus/FSF/SFConservancy won't defend. Claw back your copyrights. BSD-in-Practice was not the deal.
Silence is consent. Are there FOSS developers making decent money via Patreon, GoFundMe, whatever? Yes, Grsecurity is making good money. They simply added a no-redistribution agreement to their patch of the Linux Kernel. ( https://perens.com/2017/06/28/warning-grsecurity-potential-contributory-infringement-risk-for-customers/ ) The FSF, Software Freedom Conservancy, and the Corporate Linux Kernel Developers all agree that this is fine (silence is consent). https://twitter.com/spendergrsec/status/1293155787859206146 Importantly, neither the FSF nor the SFC, nor in fact any actual lawyer agrees with this bizarre claim from an anonymous troll. More info about the source of the claim can be found here: https://grsecurity.net/setting_the_record_straight_on_oss_v_perens_part1 Thanks for doing your part, "Dr" to continue the troll's harrassment LOL. " #GRSecurity violates both the Linux kernel's copyright and the #GCC #copyright by forbidding redistribution of the patches (in their Access Agreement): which are non-seperable derivative works... Contributors should blanket-revoke their contributions from all free-takers since they didn't agree to BSD-in-Practice. They should also claw-back any transferred copyrights from the FSF using the 30 year clawback provision in the US Copyright Act. Design of how a program works is a copyrightable aspect (Ex: How RMS designed GCC 30 years ago or so etc) Had to repost this because the linux admins deleted the email: https://lkml.org/lkml/2020/12/28/2518 The message you requested cannot be found. The message you requested cannot be found. The message with the url http://feisty.lkml.org/lkml/2020/12/28/2518 does not exist in the database. Grsecurity GPL Violations: Bring a CASE act claim every time GrSecurity releases a new infringing work? (GRSecurity blatantly violates the clause in the Linux kernel and GCC copyright licenses regarding adding addtional terms between the licensee of the kernel / gcc and furthur down-the-line licensees, regarding derivative works) (The linux kernel has 1000s of copyright holders) (All who shake at the knees at the thought of initiating a federal Copyright lawsuit)
[PATCH 5.4 010/453] PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter
From: Zhang Qilong [ Upstream commit dd8088d5a8969dc2b42f71d7bc01c25c61a78066 ] In many case, we need to check return value of pm_runtime_get_sync, but it brings a trouble to the usage counter processing. Many callers forget to decrease the usage counter when it failed, which could resulted in reference leak. It has been discussed a lot[0][1]. So we add a function to deal with the usage counter for better coding. [0]https://lkml.org/lkml/2020/6/14/88 [1]https://patchwork.ozlabs.org/project/linux-tegra/list/?series=178139 Signed-off-by: Zhang Qilong Acked-by: Rafael J. Wysocki Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- include/linux/pm_runtime.h | 21 + 1 file changed, 21 insertions(+) diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h index fe61e3b9a9ca2..7145795b4b9da 100644 --- a/include/linux/pm_runtime.h +++ b/include/linux/pm_runtime.h @@ -224,6 +224,27 @@ static inline int pm_runtime_get_sync(struct device *dev) return __pm_runtime_resume(dev, RPM_GET_PUT); } +/** + * pm_runtime_resume_and_get - Bump up usage counter of a device and resume it. + * @dev: Target device. + * + * Resume @dev synchronously and if that is successful, increment its runtime + * PM usage counter. Return 0 if the runtime PM usage counter of @dev has been + * incremented or a negative error code otherwise. + */ +static inline int pm_runtime_resume_and_get(struct device *dev) +{ + int ret; + + ret = __pm_runtime_resume(dev, RPM_GET_PUT); + if (ret < 0) { + pm_runtime_put_noidle(dev); + return ret; + } + + return 0; +} + static inline int pm_runtime_put(struct device *dev) { return __pm_runtime_idle(dev, RPM_GET_PUT | RPM_ASYNC); -- 2.27.0
[PATCH v4 16/17] remoteproc: Properly deal with detach request
This patch introduces the capability to detach a remote processor that has been attached to or booted by the remoteproc core. For that to happen a rproc::ops::detach() operation need to be available. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_cdev.c | 6 ++ drivers/remoteproc/remoteproc_sysfs.c | 6 ++ 2 files changed, 12 insertions(+) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index 61541bc7d26c..f7645f289563 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -43,6 +43,12 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ return -EINVAL; ret = rproc_shutdown(rproc); + } else if (!strncmp(cmd, "detach", len)) { + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) + return -EINVAL; + + ret = rproc_detach(rproc); } else { dev_err(&rproc->dev, "Unrecognized option\n"); ret = -EINVAL; diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 298052c9d068..ea7b067fe89a 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -236,6 +236,12 @@ static ssize_t state_store(struct device *dev, return -EINVAL; ret = rproc_shutdown(rproc); + } else if (sysfs_streq(buf, "detach")) { + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) + return -EINVAL; + + ret = rproc_detach(rproc); } else { dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); ret = -EINVAL; -- 2.25.1
[PATCH v4 09/17] remoteproc: Properly deal with a kernel panic when attached
The panic handler operation of registered remote processors should also be called when remote processors have been attached to. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 19545b7925e2..fc28053c7f89 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2414,7 +2414,11 @@ static int rproc_panic_handler(struct notifier_block *nb, unsigned long event, rcu_read_lock(); list_for_each_entry_rcu(rproc, &rproc_list, node) { - if (!rproc->ops->panic || rproc->state != RPROC_RUNNING) + if (!rproc->ops->panic) + continue; + + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) continue; d = rproc->ops->panic(rproc); -- 2.25.1
[PATCH v4 14/17] remoteproc: Properly deal with a stop request when attached
This patch introduces the capability to stop a remote processor that has been attached to by the remoteproc core. For that to happen a rproc::ops::stop() operation need to be available. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_cdev.c | 5 +++-- drivers/remoteproc/remoteproc_core.c | 6 +- drivers/remoteproc/remoteproc_sysfs.c | 5 +++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index b19ea3057bde..d06f8d4919c7 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -37,10 +37,11 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ ret = rproc_boot(rproc); } else if (!strncmp(cmd, "stop", len)) { - if (rproc->state != RPROC_RUNNING) + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) return -EINVAL; - rproc_shutdown(rproc); + ret = rproc_shutdown(rproc); } else { dev_err(&rproc->dev, "Unrecognized option\n"); ret = -EINVAL; diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 90057ad1bb6c..2fe42ac7ca89 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1648,6 +1648,10 @@ static int rproc_stop(struct rproc *rproc, bool crashed) struct device *dev = &rproc->dev; int ret; + /* No need to continue if a stop() operation has not been provided */ + if (!rproc->ops->stop) + return -EINVAL; + /* Stop any subdevices for the remote processor */ rproc_stop_subdevices(rproc, crashed); @@ -1897,7 +1901,7 @@ int rproc_shutdown(struct rproc *rproc) return ret; } - if (rproc->state != RPROC_RUNNING) { + if (rproc->state != RPROC_RUNNING && rproc->state != RPROC_ATTACHED) { ret = -EPERM; goto out; } diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 99ff51fd9707..96751c087585 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -230,10 +230,11 @@ static ssize_t state_store(struct device *dev, if (ret) dev_err(&rproc->dev, "Boot failed: %d\n", ret); } else if (sysfs_streq(buf, "stop")) { - if (rproc->state != RPROC_RUNNING) + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) return -EINVAL; - rproc_shutdown(rproc); + ret = rproc_shutdown(rproc); } else { dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); ret = -EINVAL; -- 2.25.1
[PATCH v4 15/17] remoteproc: Properly deal with a start request when attached
This patch takes into account scenarios where a remote processor has been attached to when receiving a "start" command from sysfs. As with the "running" case, the command can't be carried out if the remote processor is already in operation. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_cdev.c | 3 ++- drivers/remoteproc/remoteproc_sysfs.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index d06f8d4919c7..61541bc7d26c 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -32,7 +32,8 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ return -EFAULT; if (!strncmp(cmd, "start", len)) { - if (rproc->state == RPROC_RUNNING) + if (rproc->state == RPROC_RUNNING || + rproc->state == RPROC_ATTACHED) return -EBUSY; ret = rproc_boot(rproc); diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 96751c087585..298052c9d068 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -223,7 +223,8 @@ static ssize_t state_store(struct device *dev, int ret = 0; if (sysfs_streq(buf, "start")) { - if (rproc->state == RPROC_RUNNING) + if (rproc->state == RPROC_RUNNING || + rproc->state == RPROC_ATTACHED) return -EBUSY; ret = rproc_boot(rproc); -- 2.25.1
Re: [PATCH v3 14/15] remoteproc: Properly deal with detach request
On 11/26/20 10:06 PM, Mathieu Poirier wrote: > This patch introduces the capability to detach a remote processor > that has been attached to or booted by the remoteproc core. For > that to happen a rproc::ops::detach() operation need to be > available. > > Signed-off-by: Mathieu Poirier > Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen Thanks, Arnaud > --- > drivers/remoteproc/remoteproc_cdev.c | 6 ++ > drivers/remoteproc/remoteproc_sysfs.c | 6 ++ > 2 files changed, 12 insertions(+) > > diff --git a/drivers/remoteproc/remoteproc_cdev.c > b/drivers/remoteproc/remoteproc_cdev.c > index 61541bc7d26c..f7645f289563 100644 > --- a/drivers/remoteproc/remoteproc_cdev.c > +++ b/drivers/remoteproc/remoteproc_cdev.c > @@ -43,6 +43,12 @@ static ssize_t rproc_cdev_write(struct file *filp, const > char __user *buf, size_ > return -EINVAL; > > ret = rproc_shutdown(rproc); > + } else if (!strncmp(cmd, "detach", len)) { > + if (rproc->state != RPROC_RUNNING && > + rproc->state != RPROC_ATTACHED) > + return -EINVAL; > + > + ret = rproc_detach(rproc); > } else { > dev_err(&rproc->dev, "Unrecognized option\n"); > ret = -EINVAL; > diff --git a/drivers/remoteproc/remoteproc_sysfs.c > b/drivers/remoteproc/remoteproc_sysfs.c > index 7d281cfe3e03..5a239df5877e 100644 > --- a/drivers/remoteproc/remoteproc_sysfs.c > +++ b/drivers/remoteproc/remoteproc_sysfs.c > @@ -207,6 +207,12 @@ static ssize_t state_store(struct device *dev, > return -EINVAL; > > ret = rproc_shutdown(rproc); > + } else if (sysfs_streq(buf, "detach")) { > + if (rproc->state != RPROC_RUNNING && > + rproc->state != RPROC_ATTACHED) > + return -EINVAL; > + > + ret = rproc_detach(rproc); > } else { > dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); > ret = -EINVAL; >
Re: [PATCH v3 13/15] remoteproc: Properly deal with a start request when attached
On 11/26/20 10:06 PM, Mathieu Poirier wrote: > This patch takes into account scenarios where a remote processor > has been attached to when receiving a "start" command from sysfs. > > As with the "running" case, the command can't be carried out if the > remote processor is already in operation. > > Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen Thanks, Arnaud > --- > drivers/remoteproc/remoteproc_cdev.c | 3 ++- > drivers/remoteproc/remoteproc_sysfs.c | 3 ++- > 2 files changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/remoteproc/remoteproc_cdev.c > b/drivers/remoteproc/remoteproc_cdev.c > index d06f8d4919c7..61541bc7d26c 100644 > --- a/drivers/remoteproc/remoteproc_cdev.c > +++ b/drivers/remoteproc/remoteproc_cdev.c > @@ -32,7 +32,8 @@ static ssize_t rproc_cdev_write(struct file *filp, const > char __user *buf, size_ > return -EFAULT; > > if (!strncmp(cmd, "start", len)) { > - if (rproc->state == RPROC_RUNNING) > + if (rproc->state == RPROC_RUNNING || > + rproc->state == RPROC_ATTACHED) > return -EBUSY; > > ret = rproc_boot(rproc); > diff --git a/drivers/remoteproc/remoteproc_sysfs.c > b/drivers/remoteproc/remoteproc_sysfs.c > index 3696f2ccc785..7d281cfe3e03 100644 > --- a/drivers/remoteproc/remoteproc_sysfs.c > +++ b/drivers/remoteproc/remoteproc_sysfs.c > @@ -194,7 +194,8 @@ static ssize_t state_store(struct device *dev, > int ret = 0; > > if (sysfs_streq(buf, "start")) { > - if (rproc->state == RPROC_RUNNING) > + if (rproc->state == RPROC_RUNNING || > + rproc->state == RPROC_ATTACHED) > return -EBUSY; > > ret = rproc_boot(rproc); >
[PATCH v3 06/15] remoteproc: Properly deal with a kernel panic when attached
The panic handler operation of registered remote processors should also be called when remote processors have been attached to. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_core.c | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 300785a18f03..539667948bc8 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2471,7 +2471,11 @@ static int rproc_panic_handler(struct notifier_block *nb, unsigned long event, rcu_read_lock(); list_for_each_entry_rcu(rproc, &rproc_list, node) { - if (!rproc->ops->panic || rproc->state != RPROC_RUNNING) + if (!rproc->ops->panic) + continue; + + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) continue; d = rproc->ops->panic(rproc); -- 2.25.1
[PATCH v3 14/15] remoteproc: Properly deal with detach request
This patch introduces the capability to detach a remote processor that has been attached to or booted by the remoteproc core. For that to happen a rproc::ops::detach() operation need to be available. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan --- drivers/remoteproc/remoteproc_cdev.c | 6 ++ drivers/remoteproc/remoteproc_sysfs.c | 6 ++ 2 files changed, 12 insertions(+) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index 61541bc7d26c..f7645f289563 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -43,6 +43,12 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ return -EINVAL; ret = rproc_shutdown(rproc); + } else if (!strncmp(cmd, "detach", len)) { + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) + return -EINVAL; + + ret = rproc_detach(rproc); } else { dev_err(&rproc->dev, "Unrecognized option\n"); ret = -EINVAL; diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 7d281cfe3e03..5a239df5877e 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -207,6 +207,12 @@ static ssize_t state_store(struct device *dev, return -EINVAL; ret = rproc_shutdown(rproc); + } else if (sysfs_streq(buf, "detach")) { + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) + return -EINVAL; + + ret = rproc_detach(rproc); } else { dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); ret = -EINVAL; -- 2.25.1
[PATCH v3 13/15] remoteproc: Properly deal with a start request when attached
This patch takes into account scenarios where a remote processor has been attached to when receiving a "start" command from sysfs. As with the "running" case, the command can't be carried out if the remote processor is already in operation. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_cdev.c | 3 ++- drivers/remoteproc/remoteproc_sysfs.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index d06f8d4919c7..61541bc7d26c 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -32,7 +32,8 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ return -EFAULT; if (!strncmp(cmd, "start", len)) { - if (rproc->state == RPROC_RUNNING) + if (rproc->state == RPROC_RUNNING || + rproc->state == RPROC_ATTACHED) return -EBUSY; ret = rproc_boot(rproc); diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 3696f2ccc785..7d281cfe3e03 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -194,7 +194,8 @@ static ssize_t state_store(struct device *dev, int ret = 0; if (sysfs_streq(buf, "start")) { - if (rproc->state == RPROC_RUNNING) + if (rproc->state == RPROC_RUNNING || + rproc->state == RPROC_ATTACHED) return -EBUSY; ret = rproc_boot(rproc); -- 2.25.1
[PATCH v3 12/15] remoteproc: Properly deal with a stop request when attached
This patch introduces the capability to stop a remote processor that has been attached to by the remoteproc core. For that to happen a rproc::ops::stop() operation need to be available. Signed-off-by: Mathieu Poirier Reviewed-by: Peng Fan Reviewed-by: Arnaud Pouliquen --- drivers/remoteproc/remoteproc_cdev.c | 5 +++-- drivers/remoteproc/remoteproc_core.c | 6 +- drivers/remoteproc/remoteproc_sysfs.c | 5 +++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index b19ea3057bde..d06f8d4919c7 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -37,10 +37,11 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ ret = rproc_boot(rproc); } else if (!strncmp(cmd, "stop", len)) { - if (rproc->state != RPROC_RUNNING) + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) return -EINVAL; - rproc_shutdown(rproc); + ret = rproc_shutdown(rproc); } else { dev_err(&rproc->dev, "Unrecognized option\n"); ret = -EINVAL; diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 51275107eb1f..3d7d245edc4e 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1642,6 +1642,10 @@ static int rproc_stop(struct rproc *rproc, bool crashed) struct device *dev = &rproc->dev; int ret; + /* No need to continue if a stop() operation has not been provided */ + if (!rproc->ops->stop) + return -EINVAL; + /* Stop any subdevices for the remote processor */ rproc_stop_subdevices(rproc, crashed); @@ -1880,7 +1884,7 @@ int rproc_shutdown(struct rproc *rproc) return ret; } - if (rproc->state != RPROC_RUNNING) { + if (rproc->state != RPROC_RUNNING && rproc->state != RPROC_ATTACHED) { ret = -EPERM; goto out; } diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index f9694def9b54..3696f2ccc785 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -201,10 +201,11 @@ static ssize_t state_store(struct device *dev, if (ret) dev_err(&rproc->dev, "Boot failed: %d\n", ret); } else if (sysfs_streq(buf, "stop")) { - if (rproc->state != RPROC_RUNNING) + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) return -EINVAL; - rproc_shutdown(rproc); + ret = rproc_shutdown(rproc); } else { dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); ret = -EINVAL; -- 2.25.1
[PATCH 5.9 047/252] PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter
From: Zhang Qilong [ Upstream commit dd8088d5a8969dc2b42f71d7bc01c25c61a78066 ] In many case, we need to check return value of pm_runtime_get_sync, but it brings a trouble to the usage counter processing. Many callers forget to decrease the usage counter when it failed, which could resulted in reference leak. It has been discussed a lot[0][1]. So we add a function to deal with the usage counter for better coding. [0]https://lkml.org/lkml/2020/6/14/88 [1]https://patchwork.ozlabs.org/project/linux-tegra/list/?series=178139 Signed-off-by: Zhang Qilong Acked-by: Rafael J. Wysocki Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- include/linux/pm_runtime.h | 21 + 1 file changed, 21 insertions(+) --- a/include/linux/pm_runtime.h +++ b/include/linux/pm_runtime.h @@ -387,6 +387,27 @@ static inline int pm_runtime_get_sync(st } /** + * pm_runtime_resume_and_get - Bump up usage counter of a device and resume it. + * @dev: Target device. + * + * Resume @dev synchronously and if that is successful, increment its runtime + * PM usage counter. Return 0 if the runtime PM usage counter of @dev has been + * incremented or a negative error code otherwise. + */ +static inline int pm_runtime_resume_and_get(struct device *dev) +{ + int ret; + + ret = __pm_runtime_resume(dev, RPM_GET_PUT); + if (ret < 0) { + pm_runtime_put_noidle(dev); + return ret; + } + + return 0; +} + +/** * pm_runtime_put - Drop device usage counter and queue up "idle check" if 0. * @dev: Target device. *
[Question] How to deal D state on request_wait_answer?
Hi We recently detected a bug in virtiofs. Here, we created a virtual machine as guest with Qemu and virtiofsd. We mounted virtiofs on guest, for example /home/virtiofs. Then we killed the virtiofsd in host and accessed /home/virtiofs in guest later. This casued a process with D state which could not be killed. The stack of the process as following: wait_event_interruptible [<0>] request_wait_answer+0x9d/0x210 [fuse] [<0>] __fuse_request_send+0x75/0x80 [fuse] [<0>] fuse_simple_request+0x164/0x270 [fuse] [<0>] fuse_do_getattr+0xd5/0x2a0 [fuse] [<0>] vfs_statx+0x89/0xe0 [<0>] __do_sys_newstat+0x39/0x70 [<0>] do_syscall_64+0x55/0x1c0 [<0>] entry_SYSCALL_64_after_hwframe+0x44/0xa9 We have no idea to deal with the bug. Here, we have some question about that: 1. Why not use timeout mechanism? 2. If timeout mechanism is used, the process will enter wait_event after wait_event_interruptible_timeout?
Re: Bank Deal.
Good Day, I am Mr. Eric Axford a director with Financial Conduct Authority (FCA) UK. I'm soliciting your assistance for transfer of $65.9M into your bank account. Please respond back for more details about this transaction. Yours Truly, Mr. Eric Axford
[PATCH 2/7] soc: sunxi: Deal with the MBUS DMA offsets in a central place
So far most of the drivers with the MBUS quirks had to duplicate the code to deal with DT compatibility and enforcing the DMA offsets. Let's move for a more maintainable solution by putting everything in a notifier that would take care of setting up the DMA offsets for all the MBUS devices. Suggested-by: Robin Murphy Signed-off-by: Maxime Ripard --- drivers/soc/sunxi/Kconfig | 8 ++ drivers/soc/sunxi/Makefile | 1 + drivers/soc/sunxi/sunxi_mbus.c | 132 + 3 files changed, 141 insertions(+) create mode 100644 drivers/soc/sunxi/sunxi_mbus.c diff --git a/drivers/soc/sunxi/Kconfig b/drivers/soc/sunxi/Kconfig index f10fd6cae13e..1fef0e711056 100644 --- a/drivers/soc/sunxi/Kconfig +++ b/drivers/soc/sunxi/Kconfig @@ -2,6 +2,14 @@ # # Allwinner sunXi SoC drivers # + +config SUNXI_MBUS + bool + default ARCH_SUNXI + help + Say y to enable the fixups needed to support the Allwinner + MBUS DMA quirks. + config SUNXI_SRAM bool default ARCH_SUNXI diff --git a/drivers/soc/sunxi/Makefile b/drivers/soc/sunxi/Makefile index 7816fbbec387..549159571d4f 100644 --- a/drivers/soc/sunxi/Makefile +++ b/drivers/soc/sunxi/Makefile @@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_SUNXI_MBUS) +=sunxi_mbus.o obj-$(CONFIG_SUNXI_SRAM) +=sunxi_sram.o diff --git a/drivers/soc/sunxi/sunxi_mbus.c b/drivers/soc/sunxi/sunxi_mbus.c new file mode 100644 index ..a9d077f73c3a --- /dev/null +++ b/drivers/soc/sunxi/sunxi_mbus.c @@ -0,0 +1,132 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2020 Maxime Ripard */ + +#include +#include +#include +#include +#include +#include + +static const char * const sunxi_mbus_devices[] = { + /* +* The display engine virtual devices are not strictly speaking +* connected to the MBUS, but since DRM will perform all the +* memory allocations and DMA operations through that device, we +* need to have the quirk on those devices too. +*/ + "allwinner,sun4i-a10-display-engine", + "allwinner,sun5i-a10s-display-engine", + "allwinner,sun5i-a13-display-engine", + "allwinner,sun6i-a31-display-engine", + "allwinner,sun6i-a31s-display-engine", + "allwinner,sun7i-a20-display-engine", + "allwinner,sun8i-a23-display-engine", + "allwinner,sun8i-a33-display-engine", + "allwinner,sun8i-a83t-display-engine", + "allwinner,sun8i-h3-display-engine", + "allwinner,sun8i-r40-display-engine", + "allwinner,sun8i-v3s-display-engine", + "allwinner,sun9i-a80-display-engine", + "allwinner,sun50i-a64-display-engine", + + /* +* And now we have the regular devices connected to the MBUS +* (that we know of). +*/ + "allwinner,sun4i-a10-csi1", + "allwinner,sun4i-a10-display-backend", + "allwinner,sun4i-a10-display-frontend", + "allwinner,sun4i-a10-video-engine", + "allwinner,sun5i-a13-display-backend", + "allwinner,sun5i-a13-video-engine", + "allwinner,sun6i-a31-csi", + "allwinner,sun6i-a31-display-backend", + "allwinner,sun7i-a20-csi0", + "allwinner,sun7i-a20-display-backend", + "allwinner,sun7i-a20-display-frontend", + "allwinner,sun7i-a20-video-engine", + "allwinner,sun8i-a23-display-backend", + "allwinner,sun8i-a23-display-frontend", + "allwinner,sun8i-a33-display-backend", + "allwinner,sun8i-a33-display-frontend", + "allwinner,sun8i-a33-video-engine", + "allwinner,sun8i-a83t-csi", + "allwinner,sun8i-h3-csi", + "allwinner,sun8i-h3-video-engine", + "allwinner,sun8i-v3s-csi", + "allwinner,sun9i-a80-display-backend", + "allwinner,sun50i-a64-csi", + "allwinner,sun50i-a64-video-engine", + "allwinner,sun50i-h5-video-engine", + NULL, +}; + +static int sunxi_mbus_notifier(struct notifier_block *nb, + unsigned long event, void *__dev) +{ + struct device *dev = __dev; + int ret; + + if (event != BUS_NOTIFY_ADD_DEVICE) + return NOTIFY_DONE; + + /* +* Only the devices that need a large memory bandwidth do DMA +* directly over the memory bus (called MBUS), instead of going +* through the regular system bus. +*/ + if (!of_device_compatible_match(dev->of_node, sunxi_mbus_devices)) + return NOTIFY_DONE; + + /* +* Devices with an interconnects property have the
[PATCH 5.9 18/74] efi/arm64: libstub: Deal gracefully with EFI_RNG_PROTOCOL failure
From: Ard Biesheuvel commit d32de9130f6c79533508e2c7879f18997bfbe2a0 upstream. Currently, on arm64, we abort on any failure from efi_get_random_bytes() other than EFI_NOT_FOUND when it comes to setting the physical seed for KASLR, but ignore such failures when obtaining the seed for virtual KASLR or for early seeding of the kernel's entropy pool via the config table. This is inconsistent, and may lead to unexpected boot failures. So let's permit any failure for the physical seed, and simply report the error code if it does not equal EFI_NOT_FOUND. Cc: # v5.8+ Reported-by: Heinrich Schuchardt Signed-off-by: Ard Biesheuvel Signed-off-by: Greg Kroah-Hartman --- drivers/firmware/efi/libstub/arm64-stub.c |8 +--- drivers/firmware/efi/libstub/fdt.c|4 +--- 2 files changed, 6 insertions(+), 6 deletions(-) --- a/drivers/firmware/efi/libstub/arm64-stub.c +++ b/drivers/firmware/efi/libstub/arm64-stub.c @@ -62,10 +62,12 @@ efi_status_t handle_kernel_image(unsigne status = efi_get_random_bytes(sizeof(phys_seed), (u8 *)&phys_seed); if (status == EFI_NOT_FOUND) { - efi_info("EFI_RNG_PROTOCOL unavailable, no randomness supplied\n"); + efi_info("EFI_RNG_PROTOCOL unavailable, KASLR will be disabled\n"); + efi_nokaslr = true; } else if (status != EFI_SUCCESS) { - efi_err("efi_get_random_bytes() failed\n"); - return status; + efi_err("efi_get_random_bytes() failed (0x%lx), KASLR will be disabled\n", + status); + efi_nokaslr = true; } } else { efi_info("KASLR disabled on kernel command line\n"); --- a/drivers/firmware/efi/libstub/fdt.c +++ b/drivers/firmware/efi/libstub/fdt.c @@ -136,7 +136,7 @@ static efi_status_t update_fdt(void *ori if (status) goto fdt_set_fail; - if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) { + if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && !efi_nokaslr) { efi_status_t efi_status; efi_status = efi_get_random_bytes(sizeof(fdt_val64), @@ -145,8 +145,6 @@ static efi_status_t update_fdt(void *ori status = fdt_setprop_var(fdt, node, "kaslr-seed", fdt_val64); if (status) goto fdt_set_fail; - } else if (efi_status != EFI_NOT_FOUND) { - return efi_status; } }
[PATCH 5.8 18/70] efi/arm64: libstub: Deal gracefully with EFI_RNG_PROTOCOL failure
From: Ard Biesheuvel commit d32de9130f6c79533508e2c7879f18997bfbe2a0 upstream. Currently, on arm64, we abort on any failure from efi_get_random_bytes() other than EFI_NOT_FOUND when it comes to setting the physical seed for KASLR, but ignore such failures when obtaining the seed for virtual KASLR or for early seeding of the kernel's entropy pool via the config table. This is inconsistent, and may lead to unexpected boot failures. So let's permit any failure for the physical seed, and simply report the error code if it does not equal EFI_NOT_FOUND. Cc: # v5.8+ Reported-by: Heinrich Schuchardt Signed-off-by: Ard Biesheuvel Signed-off-by: Greg Kroah-Hartman --- drivers/firmware/efi/libstub/arm64-stub.c |8 +--- drivers/firmware/efi/libstub/fdt.c|4 +--- 2 files changed, 6 insertions(+), 6 deletions(-) --- a/drivers/firmware/efi/libstub/arm64-stub.c +++ b/drivers/firmware/efi/libstub/arm64-stub.c @@ -62,10 +62,12 @@ efi_status_t handle_kernel_image(unsigne status = efi_get_random_bytes(sizeof(phys_seed), (u8 *)&phys_seed); if (status == EFI_NOT_FOUND) { - efi_info("EFI_RNG_PROTOCOL unavailable, no randomness supplied\n"); + efi_info("EFI_RNG_PROTOCOL unavailable, KASLR will be disabled\n"); + efi_nokaslr = true; } else if (status != EFI_SUCCESS) { - efi_err("efi_get_random_bytes() failed\n"); - return status; + efi_err("efi_get_random_bytes() failed (0x%lx), KASLR will be disabled\n", + status); + efi_nokaslr = true; } } else { efi_info("KASLR disabled on kernel command line\n"); --- a/drivers/firmware/efi/libstub/fdt.c +++ b/drivers/firmware/efi/libstub/fdt.c @@ -136,7 +136,7 @@ static efi_status_t update_fdt(void *ori if (status) goto fdt_set_fail; - if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) { + if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && !efi_nokaslr) { efi_status_t efi_status; efi_status = efi_get_random_bytes(sizeof(fdt_val64), @@ -145,8 +145,6 @@ static efi_status_t update_fdt(void *ori status = fdt_setprop_var(fdt, node, "kaslr-seed", fdt_val64); if (status) goto fdt_set_fail; - } else if (efi_status != EFI_NOT_FOUND) { - return efi_status; } }
RE: [PATCH 11/13] remoteproc: Properly deal with detach request
> Subject: [PATCH 11/13] remoteproc: Properly deal with detach request > > This patch introduces the capability to detach a remote processor that has > been attached to or booted by the remoteproc core. For that to happen a > rproc::ops::detach() operation need to be available. > > Signed-off-by: Mathieu Poirier > --- > drivers/remoteproc/remoteproc_cdev.c | 6 ++ > drivers/remoteproc/remoteproc_sysfs.c | 6 ++ > 2 files changed, 12 insertions(+) > > diff --git a/drivers/remoteproc/remoteproc_cdev.c > b/drivers/remoteproc/remoteproc_cdev.c > index d06f8d4919c7..3a3830e27050 100644 > --- a/drivers/remoteproc/remoteproc_cdev.c > +++ b/drivers/remoteproc/remoteproc_cdev.c > @@ -42,6 +42,12 @@ static ssize_t rproc_cdev_write(struct file *filp, const > char __user *buf, size_ > return -EINVAL; > > ret = rproc_shutdown(rproc); > + } else if (!strncmp(cmd, "detach", len)) { > + if (rproc->state != RPROC_RUNNING && > + rproc->state != RPROC_ATTACHED) > + return -EINVAL; > + > + ret = rproc_detach(rproc); > } else { > dev_err(&rproc->dev, "Unrecognized option\n"); > ret = -EINVAL; > diff --git a/drivers/remoteproc/remoteproc_sysfs.c > b/drivers/remoteproc/remoteproc_sysfs.c > index 6134d2f083ce..013231f69837 100644 > --- a/drivers/remoteproc/remoteproc_sysfs.c > +++ b/drivers/remoteproc/remoteproc_sysfs.c > @@ -118,6 +118,12 @@ static ssize_t state_store(struct device *dev, > return -EINVAL; > > ret = rproc_shutdown(rproc); > + } else if (sysfs_streq(buf, "detach")) { > + if (rproc->state != RPROC_RUNNING && > + rproc->state != RPROC_ATTACHED) > + return -EINVAL; > + > + ret = rproc_detach(rproc); > } else { > dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); > ret = -EINVAL; > -- Reviewed-by: Peng Fan
RE: [PATCH 10/13] remoteproc: Properly deal with a stop request when attached
> Subject: [PATCH 10/13] remoteproc: Properly deal with a stop request when > attached > > This patch introduces the capability to stop a remote processor that has been > attached to by the remoteproc core. For that to happen a rproc::ops::stop() > operation need to be available. > > Signed-off-by: Mathieu Poirier > --- > drivers/remoteproc/remoteproc_cdev.c | 5 +++-- > drivers/remoteproc/remoteproc_core.c | 6 +- > drivers/remoteproc/remoteproc_sysfs.c | 5 +++-- > 3 files changed, 11 insertions(+), 5 deletions(-) > > diff --git a/drivers/remoteproc/remoteproc_cdev.c > b/drivers/remoteproc/remoteproc_cdev.c > index b19ea3057bde..d06f8d4919c7 100644 > --- a/drivers/remoteproc/remoteproc_cdev.c > +++ b/drivers/remoteproc/remoteproc_cdev.c > @@ -37,10 +37,11 @@ static ssize_t rproc_cdev_write(struct file *filp, const > char __user *buf, size_ > > ret = rproc_boot(rproc); > } else if (!strncmp(cmd, "stop", len)) { > - if (rproc->state != RPROC_RUNNING) > + if (rproc->state != RPROC_RUNNING && > + rproc->state != RPROC_ATTACHED) > return -EINVAL; > > - rproc_shutdown(rproc); > + ret = rproc_shutdown(rproc); > } else { > dev_err(&rproc->dev, "Unrecognized option\n"); > ret = -EINVAL; > diff --git a/drivers/remoteproc/remoteproc_core.c > b/drivers/remoteproc/remoteproc_core.c > index c6c6aba66098..95bb40b4ebb3 100644 > --- a/drivers/remoteproc/remoteproc_core.c > +++ b/drivers/remoteproc/remoteproc_core.c > @@ -1619,6 +1619,10 @@ static int rproc_stop(struct rproc *rproc, bool > crashed) > struct device *dev = &rproc->dev; > int ret; > > + /* No need to continue if a stop() operation has not been provided */ > + if (!rproc->ops->stop) > + return -EINVAL; > + > /* Stop any subdevices for the remote processor */ > rproc_stop_subdevices(rproc, crashed); > > @@ -1857,7 +1861,7 @@ int rproc_shutdown(struct rproc *rproc) > return ret; > } > > - if (rproc->state != RPROC_RUNNING) { > + if (rproc->state != RPROC_RUNNING && rproc->state != > RPROC_ATTACHED) { > ret = -EPERM; > goto out; > } > diff --git a/drivers/remoteproc/remoteproc_sysfs.c > b/drivers/remoteproc/remoteproc_sysfs.c > index c152d11a4d3c..6134d2f083ce 100644 > --- a/drivers/remoteproc/remoteproc_sysfs.c > +++ b/drivers/remoteproc/remoteproc_sysfs.c > @@ -113,10 +113,11 @@ static ssize_t state_store(struct device *dev, > if (ret) > dev_err(&rproc->dev, "Boot failed: %d\n", ret); > } else if (sysfs_streq(buf, "stop")) { > - if (rproc->state != RPROC_RUNNING) > + if (rproc->state != RPROC_RUNNING && > + rproc->state != RPROC_ATTACHED) > return -EINVAL; > > - rproc_shutdown(rproc); > + ret = rproc_shutdown(rproc); > } else { > dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); > ret = -EINVAL; > -- Reviewed-by: Peng Fan
RE: [PATCH 13/13] remoteproc: Properly deal with a kernel panic when attached
> Subject: [PATCH 13/13] remoteproc: Properly deal with a kernel panic when > attached > > The panic handler operation of registered remote processors should also be > called when remote processors have been attached to. > > Signed-off-by: Mathieu Poirier > --- > drivers/remoteproc/remoteproc_core.c | 6 +- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/drivers/remoteproc/remoteproc_core.c > b/drivers/remoteproc/remoteproc_core.c > index 5586582f54c5..54b5e3437ab5 100644 > --- a/drivers/remoteproc/remoteproc_core.c > +++ b/drivers/remoteproc/remoteproc_core.c > @@ -2491,7 +2491,11 @@ static int rproc_panic_handler(struct > notifier_block *nb, unsigned long event, > > rcu_read_lock(); > list_for_each_entry_rcu(rproc, &rproc_list, node) { > - if (!rproc->ops->panic || rproc->state != RPROC_RUNNING) > + if (!rproc->ops->panic) > + continue; > + > + if (rproc->state != RPROC_RUNNING && > + rproc->state != RPROC_ATTACHED) > continue; > > d = rproc->ops->panic(rproc); > -- Reviewed-by: Peng Fan
[tip: efi/urgent] efi/arm64: libstub: Deal gracefully with EFI_RNG_PROTOCOL failure
The following commit has been merged into the efi/urgent branch of tip: Commit-ID: d32de9130f6c79533508e2c7879f18997bfbe2a0 Gitweb: https://git.kernel.org/tip/d32de9130f6c79533508e2c7879f18997bfbe2a0 Author:Ard Biesheuvel AuthorDate:Sat, 26 Sep 2020 10:52:42 +02:00 Committer: Ard Biesheuvel CommitterDate: Tue, 29 Sep 2020 15:41:52 +02:00 efi/arm64: libstub: Deal gracefully with EFI_RNG_PROTOCOL failure Currently, on arm64, we abort on any failure from efi_get_random_bytes() other than EFI_NOT_FOUND when it comes to setting the physical seed for KASLR, but ignore such failures when obtaining the seed for virtual KASLR or for early seeding of the kernel's entropy pool via the config table. This is inconsistent, and may lead to unexpected boot failures. So let's permit any failure for the physical seed, and simply report the error code if it does not equal EFI_NOT_FOUND. Cc: # v5.8+ Reported-by: Heinrich Schuchardt Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/arm64-stub.c | 8 +--- drivers/firmware/efi/libstub/fdt.c| 4 +--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c index e5bfac7..04f5d79 100644 --- a/drivers/firmware/efi/libstub/arm64-stub.c +++ b/drivers/firmware/efi/libstub/arm64-stub.c @@ -62,10 +62,12 @@ efi_status_t handle_kernel_image(unsigned long *image_addr, status = efi_get_random_bytes(sizeof(phys_seed), (u8 *)&phys_seed); if (status == EFI_NOT_FOUND) { - efi_info("EFI_RNG_PROTOCOL unavailable, no randomness supplied\n"); + efi_info("EFI_RNG_PROTOCOL unavailable, KASLR will be disabled\n"); + efi_nokaslr = true; } else if (status != EFI_SUCCESS) { - efi_err("efi_get_random_bytes() failed\n"); - return status; + efi_err("efi_get_random_bytes() failed (0x%lx), KASLR will be disabled\n", + status); + efi_nokaslr = true; } } else { efi_info("KASLR disabled on kernel command line\n"); diff --git a/drivers/firmware/efi/libstub/fdt.c b/drivers/firmware/efi/libstub/fdt.c index 11ecf3c..368cd60 100644 --- a/drivers/firmware/efi/libstub/fdt.c +++ b/drivers/firmware/efi/libstub/fdt.c @@ -136,7 +136,7 @@ static efi_status_t update_fdt(void *orig_fdt, unsigned long orig_fdt_size, if (status) goto fdt_set_fail; - if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) { + if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && !efi_nokaslr) { efi_status_t efi_status; efi_status = efi_get_random_bytes(sizeof(fdt_val64), @@ -145,8 +145,6 @@ static efi_status_t update_fdt(void *orig_fdt, unsigned long orig_fdt_size, status = fdt_setprop_var(fdt, node, "kaslr-seed", fdt_val64); if (status) goto fdt_set_fail; - } else if (efi_status != EFI_NOT_FOUND) { - return efi_status; } }
Re: let import_iovec deal with compat_iovecs as well v4
On Fri, Sep 25, 2020 at 06:51:37AM +0200, Christoph Hellwig wrote: > Hi Al, > > this series changes import_iovec to transparently deal with compat iovec > structures, and then cleanups up a lot of code dupliation. OK, I can live with that. Applied, let's see if it passes smoke tests into -next it goes.
let import_iovec deal with compat_iovecs as well v4
Hi Al, this series changes import_iovec to transparently deal with compat iovec structures, and then cleanups up a lot of code dupliation. Changes since v3: - fix up changed prototypes in compat.h as well Changes since v2: - revert the switch of the access process vm sysclls to iov_iter - refactor the import_iovec internals differently - switch aio to use __import_iovec Changes since v1: - improve a commit message - drop a pointless unlikely - drop the PF_FORCE_COMPAT flag - add a few more cleanups (including two from David Laight) Diffstat: arch/arm64/include/asm/unistd32.h | 10 arch/mips/kernel/syscalls/syscall_n32.tbl | 10 arch/mips/kernel/syscalls/syscall_o32.tbl | 10 arch/parisc/kernel/syscalls/syscall.tbl| 10 arch/powerpc/kernel/syscalls/syscall.tbl | 10 arch/s390/kernel/syscalls/syscall.tbl | 10 arch/sparc/kernel/syscalls/syscall.tbl | 10 arch/x86/entry/syscall_x32.c |5 arch/x86/entry/syscalls/syscall_32.tbl | 10 arch/x86/entry/syscalls/syscall_64.tbl | 10 block/scsi_ioctl.c | 12 drivers/scsi/sg.c |9 fs/aio.c | 38 -- fs/io_uring.c | 20 - fs/read_write.c| 362 + fs/splice.c| 57 --- include/linux/compat.h | 24 - include/linux/fs.h | 11 include/linux/uio.h| 10 include/uapi/asm-generic/unistd.h | 12 lib/iov_iter.c | 161 +++-- mm/process_vm_access.c | 85 net/compat.c |4 security/keys/compat.c | 37 -- security/keys/internal.h |5 security/keys/keyctl.c |2 tools/include/uapi/asm-generic/unistd.h| 12 tools/perf/arch/powerpc/entry/syscalls/syscall.tbl | 10 tools/perf/arch/s390/entry/syscalls/syscall.tbl| 10 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl | 10 30 files changed, 280 insertions(+), 706 deletions(-)
let import_iovec deal with compat_iovecs as well v3
Hi Al, this series changes import_iovec to transparently deal with comat iovec structures, and then cleanups up a lot of code dupliation. Changes since v2: - revert the switch of the access process vm sysclls to iov_iter - refactor the import_iovec internals differently - switch aio to use __import_iovec Changes since v1: - improve a commit message - drop a pointless unlikely - drop the PF_FORCE_COMPAT flag - add a few more cleanups (including two from David Laight) Diffstat: arch/arm64/include/asm/unistd32.h | 10 arch/mips/kernel/syscalls/syscall_n32.tbl | 10 arch/mips/kernel/syscalls/syscall_o32.tbl | 10 arch/parisc/kernel/syscalls/syscall.tbl| 10 arch/powerpc/kernel/syscalls/syscall.tbl | 10 arch/s390/kernel/syscalls/syscall.tbl | 10 arch/sparc/kernel/syscalls/syscall.tbl | 10 arch/x86/entry/syscall_x32.c |5 arch/x86/entry/syscalls/syscall_32.tbl | 10 arch/x86/entry/syscalls/syscall_64.tbl | 10 block/scsi_ioctl.c | 12 drivers/scsi/sg.c |9 fs/aio.c | 38 -- fs/io_uring.c | 20 - fs/read_write.c| 362 + fs/splice.c| 57 --- include/linux/compat.h | 24 - include/linux/fs.h | 11 include/linux/uio.h| 10 include/uapi/asm-generic/unistd.h | 12 lib/iov_iter.c | 161 +++-- mm/process_vm_access.c | 85 net/compat.c |4 security/keys/compat.c | 37 -- security/keys/internal.h |5 security/keys/keyctl.c |2 tools/include/uapi/asm-generic/unistd.h| 12 tools/perf/arch/powerpc/entry/syscalls/syscall.tbl | 10 tools/perf/arch/s390/entry/syscalls/syscall.tbl| 10 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl | 10 30 files changed, 280 insertions(+), 706 deletions(-)
let import_iovec deal with compat_iovecs as well v2
Hi Al, this series changes import_iovec to transparently deal with comat iovec structures, and then cleanups up a lot of code dupliation. Changes since v1: - improve a commit message - drop a pointless unlikely - drop the PF_FORCE_COMPAT flag - add a few more cleanups (including two from David Laight) Diffstat: arch/arm64/include/asm/unistd32.h | 10 arch/mips/kernel/syscalls/syscall_n32.tbl | 10 arch/mips/kernel/syscalls/syscall_o32.tbl | 10 arch/parisc/kernel/syscalls/syscall.tbl| 10 arch/powerpc/kernel/syscalls/syscall.tbl | 10 arch/s390/kernel/syscalls/syscall.tbl | 10 arch/sparc/kernel/syscalls/syscall.tbl | 10 arch/x86/entry/syscall_x32.c |5 arch/x86/entry/syscalls/syscall_32.tbl | 10 arch/x86/entry/syscalls/syscall_64.tbl | 10 block/scsi_ioctl.c | 12 drivers/scsi/sg.c |9 fs/aio.c | 38 -- fs/io_uring.c | 20 - fs/read_write.c| 362 + fs/splice.c| 57 --- include/linux/compat.h | 24 - include/linux/fs.h | 11 include/linux/uio.h| 10 include/uapi/asm-generic/unistd.h | 12 lib/iov_iter.c | 161 +++-- mm/process_vm_access.c | 85 net/compat.c |4 security/keys/compat.c | 37 -- security/keys/internal.h |5 security/keys/keyctl.c |2 tools/include/uapi/asm-generic/unistd.h| 12 tools/perf/arch/powerpc/entry/syscalls/syscall.tbl | 10 tools/perf/arch/s390/entry/syscalls/syscall.tbl| 10 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl | 10 30 files changed, 280 insertions(+), 706 deletions(-)
RE: let import_iovec deal with compat_iovecs as well
> On Sat, Sep 19, 2020 at 02:24:10PM +, David Laight wrote: > > I thought about that change while writing my import_iovec() => > > iovec_import() > > patch - and thought that the io_uring code would (as usual) cause grief. > > > > Christoph - did you see those patches? Link to cover email. https://lkml.org/lkml/2020/9/15/661 - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Re: let import_iovec deal with compat_iovecs as well
On Sat, Sep 19, 2020 at 02:24:10PM +, David Laight wrote: > I thought about that change while writing my import_iovec() => iovec_import() > patch - and thought that the io_uring code would (as usual) cause grief. > > Christoph - did you see those patches? No.
RE: let import_iovec deal with compat_iovecs as well
From: Christoph Hellwig > Sent: 18 September 2020 13:45 > > this series changes import_iovec to transparently deal with comat iovec > structures, and then cleanups up a lot of code dupliation. But to get > there it first has to fix the pre-existing bug that io_uring compat > contexts don't trigger the in_compat_syscall() check. This has so far > been relatively harmless as very little code callable from io_uring used > the check, and even that code that could be called usually wasn't. I thought about that change while writing my import_iovec() => iovec_import() patch - and thought that the io_uring code would (as usual) cause grief. Christoph - did you see those patches? David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
let import_iovec deal with compat_iovecs as well
Hi Al, this series changes import_iovec to transparently deal with comat iovec structures, and then cleanups up a lot of code dupliation. But to get there it first has to fix the pre-existing bug that io_uring compat contexts don't trigger the in_compat_syscall() check. This has so far been relatively harmless as very little code callable from io_uring used the check, and even that code that could be called usually wasn't. Diffstat arch/arm64/include/asm/unistd32.h | 10 arch/mips/kernel/syscalls/syscall_n32.tbl | 10 arch/mips/kernel/syscalls/syscall_o32.tbl | 10 arch/parisc/kernel/syscalls/syscall.tbl| 10 arch/powerpc/kernel/syscalls/syscall.tbl | 10 arch/s390/kernel/syscalls/syscall.tbl | 10 arch/sparc/include/asm/compat.h|3 arch/sparc/kernel/syscalls/syscall.tbl | 10 arch/x86/entry/syscall_x32.c |5 arch/x86/entry/syscalls/syscall_32.tbl | 10 arch/x86/entry/syscalls/syscall_64.tbl | 10 arch/x86/include/asm/compat.h |2 block/scsi_ioctl.c | 12 drivers/scsi/sg.c |9 fs/aio.c | 38 -- fs/io_uring.c | 21 - fs/read_write.c| 307 - fs/splice.c| 57 --- include/linux/compat.h | 29 - include/linux/fs.h |7 include/linux/sched.h |1 include/linux/uio.h|7 include/uapi/asm-generic/unistd.h | 12 lib/iov_iter.c | 30 -- mm/process_vm_access.c | 69 net/compat.c |4 security/keys/compat.c | 37 -- security/keys/internal.h |5 security/keys/keyctl.c |2 tools/include/uapi/asm-generic/unistd.h| 12 tools/perf/arch/powerpc/entry/syscalls/syscall.tbl | 10 tools/perf/arch/s390/entry/syscalls/syscall.tbl| 10 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl | 10 33 files changed, 207 insertions(+), 582 deletions(-)
[PATCH v5 07/80] drm/vc4: crtc: Deal with different number of pixel per clock
Some of the HDMI pixelvalves in vc5 output two pixels per clock cycle. Let's put the number of pixel output per clock cycle in the CRTC data and update the various calculations to reflect that. Reviewed-by: Eric Anholt Tested-by: Chanwoo Choi Tested-by: Hoegeun Kwon Tested-by: Stefan Wahren Signed-off-by: Maxime Ripard --- drivers/gpu/drm/vc4/vc4_crtc.c | 18 +++--- drivers/gpu/drm/vc4/vc4_drv.h | 3 +++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_crtc.c b/drivers/gpu/drm/vc4/vc4_crtc.c index 6d8fa6118fc1..e55b2208b4b7 100644 --- a/drivers/gpu/drm/vc4/vc4_crtc.c +++ b/drivers/gpu/drm/vc4/vc4_crtc.c @@ -235,6 +235,7 @@ static void vc4_crtc_config_pv(struct drm_crtc *crtc) struct drm_encoder *encoder = vc4_get_crtc_encoder(crtc); struct vc4_encoder *vc4_encoder = to_vc4_encoder(encoder); struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc); + const struct vc4_pv_data *pv_data = vc4_crtc_to_vc4_pv_data(vc4_crtc); struct drm_crtc_state *state = crtc->state; struct drm_display_mode *mode = &state->adjusted_mode; bool interlace = mode->flags & DRM_MODE_FLAG_INTERLACE; @@ -242,6 +243,7 @@ static void vc4_crtc_config_pv(struct drm_crtc *crtc) bool is_dsi = (vc4_encoder->type == VC4_ENCODER_TYPE_DSI0 || vc4_encoder->type == VC4_ENCODER_TYPE_DSI1); u32 format = is_dsi ? PV_CONTROL_FORMAT_DSIV_24 : PV_CONTROL_FORMAT_24; + u8 ppc = pv_data->pixels_per_clock; /* Reset the PV fifo. */ CRTC_WRITE(PV_CONTROL, 0); @@ -249,17 +251,16 @@ static void vc4_crtc_config_pv(struct drm_crtc *crtc) CRTC_WRITE(PV_CONTROL, 0); CRTC_WRITE(PV_HORZA, - VC4_SET_FIELD((mode->htotal - - mode->hsync_end) * pixel_rep, + VC4_SET_FIELD((mode->htotal - mode->hsync_end) * pixel_rep / ppc, PV_HORZA_HBP) | - VC4_SET_FIELD((mode->hsync_end - - mode->hsync_start) * pixel_rep, + VC4_SET_FIELD((mode->hsync_end - mode->hsync_start) * pixel_rep / ppc, PV_HORZA_HSYNC)); + CRTC_WRITE(PV_HORZB, - VC4_SET_FIELD((mode->hsync_start - - mode->hdisplay) * pixel_rep, + VC4_SET_FIELD((mode->hsync_start - mode->hdisplay) * pixel_rep / ppc, PV_HORZB_HFP) | - VC4_SET_FIELD(mode->hdisplay * pixel_rep, PV_HORZB_HACTIVE)); + VC4_SET_FIELD(mode->hdisplay * pixel_rep / ppc, +PV_HORZB_HACTIVE)); CRTC_WRITE(PV_VERTA, VC4_SET_FIELD(mode->crtc_vtotal - mode->crtc_vsync_end, @@ -761,6 +762,7 @@ static const struct vc4_pv_data bcm2835_pv0_data = { .hvs_channel = 0, }, .debugfs_name = "crtc0_regs", + .pixels_per_clock = 1, .encoder_types = { [PV_CONTROL_CLK_SELECT_DSI] = VC4_ENCODER_TYPE_DSI0, [PV_CONTROL_CLK_SELECT_DPI_SMI_HDMI] = VC4_ENCODER_TYPE_DPI, @@ -772,6 +774,7 @@ static const struct vc4_pv_data bcm2835_pv1_data = { .hvs_channel = 2, }, .debugfs_name = "crtc1_regs", + .pixels_per_clock = 1, .encoder_types = { [PV_CONTROL_CLK_SELECT_DSI] = VC4_ENCODER_TYPE_DSI1, [PV_CONTROL_CLK_SELECT_DPI_SMI_HDMI] = VC4_ENCODER_TYPE_SMI, @@ -783,6 +786,7 @@ static const struct vc4_pv_data bcm2835_pv2_data = { .hvs_channel = 1, }, .debugfs_name = "crtc2_regs", + .pixels_per_clock = 1, .encoder_types = { [PV_CONTROL_CLK_SELECT_DPI_SMI_HDMI] = VC4_ENCODER_TYPE_HDMI, [PV_CONTROL_CLK_SELECT_VEC] = VC4_ENCODER_TYPE_VEC, diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h index 6358f6ca8d56..0bc150daafb2 100644 --- a/drivers/gpu/drm/vc4/vc4_drv.h +++ b/drivers/gpu/drm/vc4/vc4_drv.h @@ -454,6 +454,9 @@ struct vc4_crtc_data { struct vc4_pv_data { struct vc4_crtc_database; + /* Number of pixels output per clock period */ + u8 pixels_per_clock; + enum vc4_encoder_type encoder_types[4]; const char *debugfs_name; -- git-series 0.9.1
[PATCH v5 58/80] drm/vc4: hdmi: Deal with multiple debugfs files
The HDMI driver was registering a single debugfs file so far with the name hdmi_regs. Obviously, this is not going to work anymore when will have multiple HDMI controllers since we will end up trying to register two files with the same name. Let's use the variant to avoid that name conflict. Reviewed-by: Dave Stevenson Tested-by: Chanwoo Choi Tested-by: Hoegeun Kwon Tested-by: Stefan Wahren Signed-off-by: Maxime Ripard --- drivers/gpu/drm/vc4/vc4_hdmi.c | 5 - drivers/gpu/drm/vc4/vc4_hdmi.h | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index f6d18bdbd1bb..4d0b44a2ac61 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -1369,7 +1369,9 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data) if (ret) goto err_destroy_encoder; - vc4_debugfs_add_file(drm, "hdmi_regs", vc4_hdmi_debugfs_regs, vc4_hdmi); + vc4_debugfs_add_file(drm, variant->debugfs_name, +vc4_hdmi_debugfs_regs, +vc4_hdmi); return 0; @@ -1447,6 +1449,7 @@ static int vc4_hdmi_dev_remove(struct platform_device *pdev) static const struct vc4_hdmi_variant bcm2835_variant = { .encoder_type = VC4_ENCODER_TYPE_HDMI0, + .debugfs_name = "hdmi_regs", .registers = vc4_hdmi_fields, .num_registers = ARRAY_SIZE(vc4_hdmi_fields), diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.h b/drivers/gpu/drm/vc4/vc4_hdmi.h index 0d529db4b3ab..794216f3228d 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.h +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h @@ -30,6 +30,9 @@ struct vc4_hdmi_variant { /* Encoder Type for that controller */ enum vc4_encoder_type encoder_type; + /* Filename to expose the registers in debugfs */ + const char *debugfs_name; + /* List of the registers available on that variant */ const struct vc4_hdmi_register *registers; -- git-series 0.9.1
[PATCH v5 69/80] drm/vc4: hdmi: Deal with multiple ALSA cards
The HDMI driver was registering a single ALSA card so far with the name vc4-hdmi. Obviously, this is not going to work anymore when we will have multiple HDMI controllers since we will end up trying to register two files with the same name. Let's use the variant to avoid that name conflict. Reviewed-by: Dave Stevenson Tested-by: Chanwoo Choi Tested-by: Hoegeun Kwon Tested-by: Stefan Wahren Signed-off-by: Maxime Ripard --- drivers/gpu/drm/vc4/vc4_hdmi.c | 3 ++- drivers/gpu/drm/vc4/vc4_hdmi.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index 20cfc85449ca..5e479647559f 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -1043,7 +1043,7 @@ static int vc4_hdmi_audio_init(struct vc4_hdmi *vc4_hdmi) card->dai_link = dai_link; card->num_links = 1; - card->name = "vc4-hdmi"; + card->name = vc4_hdmi->variant->card_name; card->dev = dev; /* @@ -1502,6 +1502,7 @@ static int vc4_hdmi_dev_remove(struct platform_device *pdev) static const struct vc4_hdmi_variant bcm2835_variant = { .encoder_type = VC4_ENCODER_TYPE_HDMI0, .debugfs_name = "hdmi_regs", + .card_name = "vc4-hdmi", .max_pixel_clock= 16200, .cec_available = true, .registers = vc4_hdmi_fields, diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.h b/drivers/gpu/drm/vc4/vc4_hdmi.h index 4aea5ee8a91d..34138e0dd4a6 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.h +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h @@ -30,6 +30,9 @@ struct vc4_hdmi_variant { /* Encoder Type for that controller */ enum vc4_encoder_type encoder_type; + /* ALSA card name */ + const char *card_name; + /* Filename to expose the registers in debugfs */ const char *debugfs_name; -- git-series 0.9.1
[PATCH 5.4 179/214] genirq/matrix: Deal with the sillyness of for_each_cpu() on UP
From: Thomas Gleixner commit 784a0830377d0761834e385975bc46861fea9fa0 upstream. Most of the CPU mask operations behave the same way, but for_each_cpu() and it's variants ignore the cpumask argument and claim that CPU0 is always in the mask. This is historical, inconsistent and annoying behaviour. The matrix allocator uses for_each_cpu() and can be called on UP with an empty cpumask. The calling code does not expect that this succeeds but until commit e027f799 ("x86/irq: Unbreak interrupt affinity setting") this went unnoticed. That commit added a WARN_ON() to catch cases which move an interrupt from one vector to another on the same CPU. The warning triggers on UP. Add a check for the cpumask being empty to prevent this. Fixes: 2f75d9e1c905 ("genirq: Implement bitmap matrix allocator") Reported-by: kernel test robot Signed-off-by: Thomas Gleixner Cc: sta...@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- kernel/irq/matrix.c |7 +++ 1 file changed, 7 insertions(+) --- a/kernel/irq/matrix.c +++ b/kernel/irq/matrix.c @@ -380,6 +380,13 @@ int irq_matrix_alloc(struct irq_matrix * unsigned int cpu, bit; struct cpumap *cm; + /* +* Not required in theory, but matrix_find_best_cpu() uses +* for_each_cpu() which ignores the cpumask on UP . +*/ + if (cpumask_empty(msk)) + return -EINVAL; + cpu = matrix_find_best_cpu(m, msk); if (cpu == UINT_MAX) return -ENOSPC;
[PATCH 5.8 206/255] genirq/matrix: Deal with the sillyness of for_each_cpu() on UP
From: Thomas Gleixner commit 784a0830377d0761834e385975bc46861fea9fa0 upstream. Most of the CPU mask operations behave the same way, but for_each_cpu() and it's variants ignore the cpumask argument and claim that CPU0 is always in the mask. This is historical, inconsistent and annoying behaviour. The matrix allocator uses for_each_cpu() and can be called on UP with an empty cpumask. The calling code does not expect that this succeeds but until commit e027f799 ("x86/irq: Unbreak interrupt affinity setting") this went unnoticed. That commit added a WARN_ON() to catch cases which move an interrupt from one vector to another on the same CPU. The warning triggers on UP. Add a check for the cpumask being empty to prevent this. Fixes: 2f75d9e1c905 ("genirq: Implement bitmap matrix allocator") Reported-by: kernel test robot Signed-off-by: Thomas Gleixner Cc: sta...@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- kernel/irq/matrix.c |7 +++ 1 file changed, 7 insertions(+) --- a/kernel/irq/matrix.c +++ b/kernel/irq/matrix.c @@ -380,6 +380,13 @@ int irq_matrix_alloc(struct irq_matrix * unsigned int cpu, bit; struct cpumap *cm; + /* +* Not required in theory, but matrix_find_best_cpu() uses +* for_each_cpu() which ignores the cpumask on UP . +*/ + if (cpumask_empty(msk)) + return -EINVAL; + cpu = matrix_find_best_cpu(m, msk); if (cpu == UINT_MAX) return -ENOSPC;
[PATCH 4.19 103/125] genirq/matrix: Deal with the sillyness of for_each_cpu() on UP
From: Thomas Gleixner commit 784a0830377d0761834e385975bc46861fea9fa0 upstream. Most of the CPU mask operations behave the same way, but for_each_cpu() and it's variants ignore the cpumask argument and claim that CPU0 is always in the mask. This is historical, inconsistent and annoying behaviour. The matrix allocator uses for_each_cpu() and can be called on UP with an empty cpumask. The calling code does not expect that this succeeds but until commit e027f799 ("x86/irq: Unbreak interrupt affinity setting") this went unnoticed. That commit added a WARN_ON() to catch cases which move an interrupt from one vector to another on the same CPU. The warning triggers on UP. Add a check for the cpumask being empty to prevent this. Fixes: 2f75d9e1c905 ("genirq: Implement bitmap matrix allocator") Reported-by: kernel test robot Signed-off-by: Thomas Gleixner Cc: sta...@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- kernel/irq/matrix.c |7 +++ 1 file changed, 7 insertions(+) --- a/kernel/irq/matrix.c +++ b/kernel/irq/matrix.c @@ -380,6 +380,13 @@ int irq_matrix_alloc(struct irq_matrix * unsigned int cpu, bit; struct cpumap *cm; + /* +* Not required in theory, but matrix_find_best_cpu() uses +* for_each_cpu() which ignores the cpumask on UP . +*/ + if (cpumask_empty(msk)) + return -EINVAL; + cpu = matrix_find_best_cpu(m, msk); if (cpu == UINT_MAX) return -ENOSPC;
[tip: x86/urgent] genirq/matrix: Deal with the sillyness of for_each_cpu() on UP
The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 784a0830377d0761834e385975bc46861fea9fa0 Gitweb: https://git.kernel.org/tip/784a0830377d0761834e385975bc46861fea9fa0 Author:Thomas Gleixner AuthorDate:Sun, 30 Aug 2020 19:07:53 +02:00 Committer: Thomas Gleixner CommitterDate: Sun, 30 Aug 2020 19:17:28 +02:00 genirq/matrix: Deal with the sillyness of for_each_cpu() on UP Most of the CPU mask operations behave the same way, but for_each_cpu() and it's variants ignore the cpumask argument and claim that CPU0 is always in the mask. This is historical, inconsistent and annoying behaviour. The matrix allocator uses for_each_cpu() and can be called on UP with an empty cpumask. The calling code does not expect that this succeeds but until commit e027f799 ("x86/irq: Unbreak interrupt affinity setting") this went unnoticed. That commit added a WARN_ON() to catch cases which move an interrupt from one vector to another on the same CPU. The warning triggers on UP. Add a check for the cpumask being empty to prevent this. Fixes: 2f75d9e1c905 ("genirq: Implement bitmap matrix allocator") Reported-by: kernel test robot Signed-off-by: Thomas Gleixner Cc: sta...@vger.kernel.org --- kernel/irq/matrix.c | 7 +++ 1 file changed, 7 insertions(+) diff --git a/kernel/irq/matrix.c b/kernel/irq/matrix.c index 30cc217..651a4ad 100644 --- a/kernel/irq/matrix.c +++ b/kernel/irq/matrix.c @@ -380,6 +380,13 @@ int irq_matrix_alloc(struct irq_matrix *m, const struct cpumask *msk, unsigned int cpu, bit; struct cpumap *cm; + /* +* Not required in theory, but matrix_find_best_cpu() uses +* for_each_cpu() which ignores the cpumask on UP . +*/ + if (cpumask_empty(msk)) + return -EINVAL; + cpu = matrix_find_best_cpu(m, msk); if (cpu == UINT_MAX) return -ENOSPC;
Re: [PATCH] ASoC: meson: cards: deal dpcm flag change
Hi On 27.08.2020 15:32, Jerome Brunet wrote: > On Thu 27 Aug 2020 at 14:43, Marek Szyprowski > wrote: >> On 31.07.2020 14:06, Jerome Brunet wrote: >>> Commit b73287f0b074 ("ASoC: soc-pcm: dpcm: fix playback/capture checks") >>> changed the meaning of dpcm_playback/dpcm_capture and now requires the >>> CPU DAI BE to aligned with those flags. >>> >>> This broke all Amlogic cards with uni-directional backends (All gx and >>> most axg cards). >>> >>> While I'm still confused as to how this change is an improvement, those >>> cards can't remain broken forever. Hopefully, next time an API change is >>> done like that, all the users will be updated as part of the change, and >>> not left to fend for themselves. >>> >>> Fixes: b73287f0b074 ("ASoC: soc-pcm: dpcm: fix playback/capture checks") >>> Signed-off-by: Jerome Brunet >> This patch landed finally in v5.9-rc1. I've noticed it causes a >> following warning on Hardkernel's Odroid N2 board >> (arch/arm64/boot/dts/amlogic/meson-g12b-odroid-n2.dtb): > Looks like the after match of the flag change again ... > >> meson-drm ff90.vpu: [drm] fb0: mesondrmfb frame buffer device >> [ cut here ] >> WARNING: CPU: 3 PID: 66 at sound/soc/soc-core.c:817 > Marek, is it possible that you have CONFIG_LOCKDEP enabled in your > configuration ? Right, I have CONFIG_PROVE_LOCKING and CONFIG_LOCKDEP enabled. > snd_soc_find_dai() is called by snd_soc_dai_link_set_capabilities(). > Indeed, the client_mutex will not be help by any of the user of > snd_soc_dai_link_set_capabilities() when called. > > So I believe simple card and qcom will be impacted as well. > >> snd_soc_find_dai+0xe4/0xf0 >> Modules linked in: dw_hdmi_i2s_audio dw_hdmi_cec meson_gxl realtek >> dwmac_generic crct10dif_ce snd_soc_meson_axg_sound_card >> snd_soc_meson_card_utils rc_odroid pwm_meson meson_ir >> snd_soc_meson_g12a_toacodec snd_soc_meson_axg_tdmout rtc_meson_vrtc >> snd_soc_meson_g12a_tohdmitx snd_soc_meson_codec_glue mdio_mux_meson_g12a >> snd_soc_meson_axg_tdmin dwmac_meson8b stmmac_platform >> reset_meson_audio_arb snd_soc_meson_axg_frddr axg_audio >> snd_soc_meson_axg_toddr sclk_div clk_phase meson_rng stmmac rng_core >> meson_dw_hdmi snd_soc_meson_axg_fifo meson_drm meson_canvas mdio_xpcs >> dw_hdmi snd_soc_meson_t9015 display_connector nvmem_meson_efuse >> snd_soc_meson_axg_tdm_interface snd_soc_meson_axg_tdm_formatter >> snd_soc_simple_amplifier >> CPU: 3 PID: 66 Comm: kworker/3:1 Not tainted 5.9.0-rc1 #1527 >> Hardware name: Hardkernel ODROID-N2 (DT) >> Workqueue: events deferred_probe_work_func >> pstate: 6005 (nZCv daif -PAN -UAO BTYPE=--) >> pc : snd_soc_find_dai+0xe4/0xf0 >> lr : snd_soc_find_dai+0xe0/0xf0 >> ... >> Call trace: >>snd_soc_find_dai+0xe4/0xf0 >>snd_soc_dai_link_set_capabilities+0x68/0x160 >>axg_card_add_link+0x188/0x5c4 [snd_soc_meson_axg_sound_card] >>meson_card_probe+0x1e0/0x960 [snd_soc_meson_card_utils] >>platform_drv_probe+0x50/0xa8 >>really_probe+0x110/0x400 >>driver_probe_device+0x54/0xb8 >>__device_attach_driver+0x90/0xc0 >>bus_for_each_drv+0x70/0xc8 >>__device_attach+0xec/0x150 >>device_initial_probe+0x10/0x18 >>bus_probe_device+0x94/0xa0 >>deferred_probe_work_func+0x70/0xa8 >>process_one_work+0x2a8/0x718 >>worker_thread+0x48/0x460 >>kthread+0x134/0x160 >>ret_from_fork+0x10/0x1c >> irq event stamp: 269690 >> hardirqs last enabled at (269689): [] >> _raw_spin_unlock_irqrestore+0x7c/0x98 >> hardirqs last disabled at (269690): [] >> do_debug_exception+0x140/0x26c >> softirqs last enabled at (269318): [] >> efi_header_end+0x654/0x6d4 >> softirqs last disabled at (269313): [] >> irq_exit+0x16c/0x178 >> ---[ end trace 56a3ea4fa00c37c8 ]--- >> ... >> axg-sound-card sound: ASoC: no DMI vendor name! >> >> The warning is repeated 10 times. > That's the probe defferal mechanism causing the repeat > >> The bisect between v5.8-rc1 and v5.9-rc1 points to the commit >> c8f7dbdbaa15 ("Merge remote-tracking branch 'asoc/for-5.8' into >> asoc-linus"), which introduced a branch with this patch. >> >> The commit with this patch is applied on the earlier kernel release >> (da3f23fde9d7 "ASoC: meson: cards: deal dpcm flag change" on top of >> v5.7-rc1) worked fine, so it looks that there is an interference with >> something merged later. >> >> If I revert this patch on top of v5.9-rc1 or current linux-next, the >> warning is gone. > ... but any aml platform with uni-directional backend (not the N2, lucky > you) would be broken. > >> Let me know how I can help debugging this issue. > If you have CONFIG_LOCKDEP enabled, try disabling see how it goes and > report. It is not a fix but at least you'll be unblocked. Right, disabling LOCKDEP hides it. The issue is not a problem for me. I've just added OdroidN2 to my test machines and wanted to report what I found and help fixing it. Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland
Re: [PATCH] ASoC: meson: cards: deal dpcm flag change
On Thu 27 Aug 2020 at 14:43, Marek Szyprowski wrote: > Hi Jerome, > > On 31.07.2020 14:06, Jerome Brunet wrote: >> Commit b73287f0b074 ("ASoC: soc-pcm: dpcm: fix playback/capture checks") >> changed the meaning of dpcm_playback/dpcm_capture and now requires the >> CPU DAI BE to aligned with those flags. >> >> This broke all Amlogic cards with uni-directional backends (All gx and >> most axg cards). >> >> While I'm still confused as to how this change is an improvement, those >> cards can't remain broken forever. Hopefully, next time an API change is >> done like that, all the users will be updated as part of the change, and >> not left to fend for themselves. >> >> Fixes: b73287f0b074 ("ASoC: soc-pcm: dpcm: fix playback/capture checks") >> Signed-off-by: Jerome Brunet > > This patch landed finally in v5.9-rc1. I've noticed it causes a > following warning on Hardkernel's Odroid N2 board > (arch/arm64/boot/dts/amlogic/meson-g12b-odroid-n2.dtb): Looks like the after match of the flag change again ... > > meson-drm ff90.vpu: [drm] fb0: mesondrmfb frame buffer device > [ cut here ] > WARNING: CPU: 3 PID: 66 at sound/soc/soc-core.c:817 Marek, is it possible that you have CONFIG_LOCKDEP enabled in your configuration ? snd_soc_find_dai() is called by snd_soc_dai_link_set_capabilities(). Indeed, the client_mutex will not be help by any of the user of snd_soc_dai_link_set_capabilities() when called. So I believe simple card and qcom will be impacted as well. > snd_soc_find_dai+0xe4/0xf0 > Modules linked in: dw_hdmi_i2s_audio dw_hdmi_cec meson_gxl realtek > dwmac_generic crct10dif_ce snd_soc_meson_axg_sound_card > snd_soc_meson_card_utils rc_odroid pwm_meson meson_ir > snd_soc_meson_g12a_toacodec snd_soc_meson_axg_tdmout rtc_meson_vrtc > snd_soc_meson_g12a_tohdmitx snd_soc_meson_codec_glue mdio_mux_meson_g12a > snd_soc_meson_axg_tdmin dwmac_meson8b stmmac_platform > reset_meson_audio_arb snd_soc_meson_axg_frddr axg_audio > snd_soc_meson_axg_toddr sclk_div clk_phase meson_rng stmmac rng_core > meson_dw_hdmi snd_soc_meson_axg_fifo meson_drm meson_canvas mdio_xpcs > dw_hdmi snd_soc_meson_t9015 display_connector nvmem_meson_efuse > snd_soc_meson_axg_tdm_interface snd_soc_meson_axg_tdm_formatter > snd_soc_simple_amplifier > CPU: 3 PID: 66 Comm: kworker/3:1 Not tainted 5.9.0-rc1 #1527 > Hardware name: Hardkernel ODROID-N2 (DT) > Workqueue: events deferred_probe_work_func > pstate: 6005 (nZCv daif -PAN -UAO BTYPE=--) > pc : snd_soc_find_dai+0xe4/0xf0 > lr : snd_soc_find_dai+0xe0/0xf0 > ... > Call trace: > snd_soc_find_dai+0xe4/0xf0 > snd_soc_dai_link_set_capabilities+0x68/0x160 > axg_card_add_link+0x188/0x5c4 [snd_soc_meson_axg_sound_card] > meson_card_probe+0x1e0/0x960 [snd_soc_meson_card_utils] > platform_drv_probe+0x50/0xa8 > really_probe+0x110/0x400 > driver_probe_device+0x54/0xb8 > __device_attach_driver+0x90/0xc0 > bus_for_each_drv+0x70/0xc8 > __device_attach+0xec/0x150 > device_initial_probe+0x10/0x18 > bus_probe_device+0x94/0xa0 > deferred_probe_work_func+0x70/0xa8 > process_one_work+0x2a8/0x718 > worker_thread+0x48/0x460 > kthread+0x134/0x160 > ret_from_fork+0x10/0x1c > irq event stamp: 269690 > hardirqs last enabled at (269689): [] > _raw_spin_unlock_irqrestore+0x7c/0x98 > hardirqs last disabled at (269690): [] > do_debug_exception+0x140/0x26c > softirqs last enabled at (269318): [] > efi_header_end+0x654/0x6d4 > softirqs last disabled at (269313): [] > irq_exit+0x16c/0x178 > ---[ end trace 56a3ea4fa00c37c8 ]--- > ... > axg-sound-card sound: ASoC: no DMI vendor name! > > The warning is repeated 10 times. That's the probe defferal mechanism causing the repeat > > The bisect between v5.8-rc1 and v5.9-rc1 points to the commit > c8f7dbdbaa15 ("Merge remote-tracking branch 'asoc/for-5.8' into > asoc-linus"), which introduced a branch with this patch. > > The commit with this patch is applied on the earlier kernel release > (da3f23fde9d7 "ASoC: meson: cards: deal dpcm flag change" on top of > v5.7-rc1) worked fine, so it looks that there is an interference with > something merged later. > > If I revert this patch on top of v5.9-rc1 or current linux-next, the > warning is gone. ... but any aml platform with uni-directional backend (not the N2, lucky you) would be broken. > Let me know how I can help debugging this issue. If you have CONFIG_LOCKDEP enabled, try disabling see how it goes and report. It is not a fix but at least you'll be unblocked. > > Best regards
Re: [PATCH] ASoC: meson: cards: deal dpcm flag change
Hi Jerome, On 31.07.2020 14:06, Jerome Brunet wrote: > Commit b73287f0b074 ("ASoC: soc-pcm: dpcm: fix playback/capture checks") > changed the meaning of dpcm_playback/dpcm_capture and now requires the > CPU DAI BE to aligned with those flags. > > This broke all Amlogic cards with uni-directional backends (All gx and > most axg cards). > > While I'm still confused as to how this change is an improvement, those > cards can't remain broken forever. Hopefully, next time an API change is > done like that, all the users will be updated as part of the change, and > not left to fend for themselves. > > Fixes: b73287f0b074 ("ASoC: soc-pcm: dpcm: fix playback/capture checks") > Signed-off-by: Jerome Brunet This patch landed finally in v5.9-rc1. I've noticed it causes a following warning on Hardkernel's Odroid N2 board (arch/arm64/boot/dts/amlogic/meson-g12b-odroid-n2.dtb): meson-drm ff90.vpu: [drm] fb0: mesondrmfb frame buffer device [ cut here ] WARNING: CPU: 3 PID: 66 at sound/soc/soc-core.c:817 snd_soc_find_dai+0xe4/0xf0 Modules linked in: dw_hdmi_i2s_audio dw_hdmi_cec meson_gxl realtek dwmac_generic crct10dif_ce snd_soc_meson_axg_sound_card snd_soc_meson_card_utils rc_odroid pwm_meson meson_ir snd_soc_meson_g12a_toacodec snd_soc_meson_axg_tdmout rtc_meson_vrtc snd_soc_meson_g12a_tohdmitx snd_soc_meson_codec_glue mdio_mux_meson_g12a snd_soc_meson_axg_tdmin dwmac_meson8b stmmac_platform reset_meson_audio_arb snd_soc_meson_axg_frddr axg_audio snd_soc_meson_axg_toddr sclk_div clk_phase meson_rng stmmac rng_core meson_dw_hdmi snd_soc_meson_axg_fifo meson_drm meson_canvas mdio_xpcs dw_hdmi snd_soc_meson_t9015 display_connector nvmem_meson_efuse snd_soc_meson_axg_tdm_interface snd_soc_meson_axg_tdm_formatter snd_soc_simple_amplifier CPU: 3 PID: 66 Comm: kworker/3:1 Not tainted 5.9.0-rc1 #1527 Hardware name: Hardkernel ODROID-N2 (DT) Workqueue: events deferred_probe_work_func pstate: 6005 (nZCv daif -PAN -UAO BTYPE=--) pc : snd_soc_find_dai+0xe4/0xf0 lr : snd_soc_find_dai+0xe0/0xf0 ... Call trace: snd_soc_find_dai+0xe4/0xf0 snd_soc_dai_link_set_capabilities+0x68/0x160 axg_card_add_link+0x188/0x5c4 [snd_soc_meson_axg_sound_card] meson_card_probe+0x1e0/0x960 [snd_soc_meson_card_utils] platform_drv_probe+0x50/0xa8 really_probe+0x110/0x400 driver_probe_device+0x54/0xb8 __device_attach_driver+0x90/0xc0 bus_for_each_drv+0x70/0xc8 __device_attach+0xec/0x150 device_initial_probe+0x10/0x18 bus_probe_device+0x94/0xa0 deferred_probe_work_func+0x70/0xa8 process_one_work+0x2a8/0x718 worker_thread+0x48/0x460 kthread+0x134/0x160 ret_from_fork+0x10/0x1c irq event stamp: 269690 hardirqs last enabled at (269689): [] _raw_spin_unlock_irqrestore+0x7c/0x98 hardirqs last disabled at (269690): [] do_debug_exception+0x140/0x26c softirqs last enabled at (269318): [] efi_header_end+0x654/0x6d4 softirqs last disabled at (269313): [] irq_exit+0x16c/0x178 ---[ end trace 56a3ea4fa00c37c8 ]--- ... axg-sound-card sound: ASoC: no DMI vendor name! The warning is repeated 10 times. The bisect between v5.8-rc1 and v5.9-rc1 points to the commit c8f7dbdbaa15 ("Merge remote-tracking branch 'asoc/for-5.8' into asoc-linus"), which introduced a branch with this patch. The commit with this patch is applied on the earlier kernel release (da3f23fde9d7 "ASoC: meson: cards: deal dpcm flag change" on top of v5.7-rc1) worked fine, so it looks that there is an interference with something merged later. If I revert this patch on top of v5.9-rc1 or current linux-next, the warning is gone. Let me know how I can help debugging this issue. Best regards -- Marek Szyprowski, PhD Samsung R&D Institute Poland
[PATCH 10/13] remoteproc: Properly deal with a stop request when attached
This patch introduces the capability to stop a remote processor that has been attached to by the remoteproc core. For that to happen a rproc::ops::stop() operation need to be available. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_cdev.c | 5 +++-- drivers/remoteproc/remoteproc_core.c | 6 +- drivers/remoteproc/remoteproc_sysfs.c | 5 +++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index b19ea3057bde..d06f8d4919c7 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -37,10 +37,11 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ ret = rproc_boot(rproc); } else if (!strncmp(cmd, "stop", len)) { - if (rproc->state != RPROC_RUNNING) + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) return -EINVAL; - rproc_shutdown(rproc); + ret = rproc_shutdown(rproc); } else { dev_err(&rproc->dev, "Unrecognized option\n"); ret = -EINVAL; diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index c6c6aba66098..95bb40b4ebb3 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1619,6 +1619,10 @@ static int rproc_stop(struct rproc *rproc, bool crashed) struct device *dev = &rproc->dev; int ret; + /* No need to continue if a stop() operation has not been provided */ + if (!rproc->ops->stop) + return -EINVAL; + /* Stop any subdevices for the remote processor */ rproc_stop_subdevices(rproc, crashed); @@ -1857,7 +1861,7 @@ int rproc_shutdown(struct rproc *rproc) return ret; } - if (rproc->state != RPROC_RUNNING) { + if (rproc->state != RPROC_RUNNING && rproc->state != RPROC_ATTACHED) { ret = -EPERM; goto out; } diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index c152d11a4d3c..6134d2f083ce 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -113,10 +113,11 @@ static ssize_t state_store(struct device *dev, if (ret) dev_err(&rproc->dev, "Boot failed: %d\n", ret); } else if (sysfs_streq(buf, "stop")) { - if (rproc->state != RPROC_RUNNING) + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) return -EINVAL; - rproc_shutdown(rproc); + ret = rproc_shutdown(rproc); } else { dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); ret = -EINVAL; -- 2.25.1
[PATCH 13/13] remoteproc: Properly deal with a kernel panic when attached
The panic handler operation of registered remote processors should also be called when remote processors have been attached to. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_core.c | 6 +- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 5586582f54c5..54b5e3437ab5 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -2491,7 +2491,11 @@ static int rproc_panic_handler(struct notifier_block *nb, unsigned long event, rcu_read_lock(); list_for_each_entry_rcu(rproc, &rproc_list, node) { - if (!rproc->ops->panic || rproc->state != RPROC_RUNNING) + if (!rproc->ops->panic) + continue; + + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) continue; d = rproc->ops->panic(rproc); -- 2.25.1
[PATCH 11/13] remoteproc: Properly deal with detach request
This patch introduces the capability to detach a remote processor that has been attached to or booted by the remoteproc core. For that to happen a rproc::ops::detach() operation need to be available. Signed-off-by: Mathieu Poirier --- drivers/remoteproc/remoteproc_cdev.c | 6 ++ drivers/remoteproc/remoteproc_sysfs.c | 6 ++ 2 files changed, 12 insertions(+) diff --git a/drivers/remoteproc/remoteproc_cdev.c b/drivers/remoteproc/remoteproc_cdev.c index d06f8d4919c7..3a3830e27050 100644 --- a/drivers/remoteproc/remoteproc_cdev.c +++ b/drivers/remoteproc/remoteproc_cdev.c @@ -42,6 +42,12 @@ static ssize_t rproc_cdev_write(struct file *filp, const char __user *buf, size_ return -EINVAL; ret = rproc_shutdown(rproc); + } else if (!strncmp(cmd, "detach", len)) { + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) + return -EINVAL; + + ret = rproc_detach(rproc); } else { dev_err(&rproc->dev, "Unrecognized option\n"); ret = -EINVAL; diff --git a/drivers/remoteproc/remoteproc_sysfs.c b/drivers/remoteproc/remoteproc_sysfs.c index 6134d2f083ce..013231f69837 100644 --- a/drivers/remoteproc/remoteproc_sysfs.c +++ b/drivers/remoteproc/remoteproc_sysfs.c @@ -118,6 +118,12 @@ static ssize_t state_store(struct device *dev, return -EINVAL; ret = rproc_shutdown(rproc); + } else if (sysfs_streq(buf, "detach")) { + if (rproc->state != RPROC_RUNNING && + rproc->state != RPROC_ATTACHED) + return -EINVAL; + + ret = rproc_detach(rproc); } else { dev_err(&rproc->dev, "Unrecognised option: %s\n", buf); ret = -EINVAL; -- 2.25.1
[PATCH 25/28] wireless: broadcom: brcmfmac: p2p: Deal with set but unused variables
'vif' is a function parameter which is oddly overwritten within the function, but never read back. 'timeout' is set, but never checked. Fixes the following W=1 kernel build warning(s): drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c: In function ‘brcmf_p2p_scan_prep’: drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c:894:31: warning: parameter ‘vif’ set but not used [-Wunused-but-set-parameter] drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c: In function ‘brcmf_p2p_tx_action_frame’: drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c:1549:6: warning: variable ‘timeout’ set but not used [-Wunused-but-set-variable] Cc: Arend van Spriel Cc: Franky Lin Cc: Hante Meuleman Cc: Chi-Hsien Lin Cc: Wright Feng Cc: Kalle Valo Cc: "David S. Miller" Cc: Jakub Kicinski Cc: linux-wirel...@vger.kernel.org Cc: brcm80211-dev-list@broadcom.com Cc: brcm80211-dev-l...@cypress.com Cc: net...@vger.kernel.org Signed-off-by: Lee Jones --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c | 6 +- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c index debd887e159e1..7f681a25ab525 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/p2p.c @@ -913,8 +913,6 @@ int brcmf_p2p_scan_prep(struct wiphy *wiphy, if (err) return err; - vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif; - /* override .run_escan() callback. */ cfg->escan_info.run = brcmf_p2p_run_escan; } @@ -1546,7 +1544,6 @@ static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p, struct brcmf_cfg80211_vif *vif; struct brcmf_p2p_action_frame *p2p_af; s32 err = 0; - s32 timeout = 0; brcmf_dbg(TRACE, "Enter\n"); @@ -1582,8 +1579,7 @@ static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p, (p2p->wait_for_offchan_complete) ? "off-channel" : "on-channel"); - timeout = wait_for_completion_timeout(&p2p->send_af_done, - P2P_AF_MAX_WAIT_TIME); + wait_for_completion_timeout(&p2p->send_af_done, P2P_AF_MAX_WAIT_TIME); if (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status)) { brcmf_dbg(TRACE, "TX action frame operation is success\n"); -- 2.25.1
[PATCH 5.8 338/464] ASoC: meson: cards: deal dpcm flag change
From: Jerome Brunet [ Upstream commit da3f23fde9d7b4a7e0ca9a9a096cec3104df1b82 ] Commit b73287f0b074 ("ASoC: soc-pcm: dpcm: fix playback/capture checks") changed the meaning of dpcm_playback/dpcm_capture and now requires the CPU DAI BE to aligned with those flags. This broke all Amlogic cards with uni-directional backends (All gx and most axg cards). While I'm still confused as to how this change is an improvement, those cards can't remain broken forever. Hopefully, next time an API change is done like that, all the users will be updated as part of the change, and not left to fend for themselves. Fixes: b73287f0b074 ("ASoC: soc-pcm: dpcm: fix playback/capture checks") Signed-off-by: Jerome Brunet Link: https://lore.kernel.org/r/20200731120603.2243261-1-jbru...@baylibre.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/meson/axg-card.c | 18 ++ sound/soc/meson/gx-card.c | 18 +- sound/soc/meson/meson-card-utils.c | 4 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/sound/soc/meson/axg-card.c b/sound/soc/meson/axg-card.c index 47f2d93224fea..33058518c3da4 100644 --- a/sound/soc/meson/axg-card.c +++ b/sound/soc/meson/axg-card.c @@ -327,20 +327,22 @@ static int axg_card_add_link(struct snd_soc_card *card, struct device_node *np, return ret; if (axg_card_cpu_is_playback_fe(dai_link->cpus->of_node)) - ret = meson_card_set_fe_link(card, dai_link, np, true); + return meson_card_set_fe_link(card, dai_link, np, true); else if (axg_card_cpu_is_capture_fe(dai_link->cpus->of_node)) - ret = meson_card_set_fe_link(card, dai_link, np, false); - else - ret = meson_card_set_be_link(card, dai_link, np); + return meson_card_set_fe_link(card, dai_link, np, false); + + ret = meson_card_set_be_link(card, dai_link, np); if (ret) return ret; - if (axg_card_cpu_is_tdm_iface(dai_link->cpus->of_node)) - ret = axg_card_parse_tdm(card, np, index); - else if (axg_card_cpu_is_codec(dai_link->cpus->of_node)) { + if (axg_card_cpu_is_codec(dai_link->cpus->of_node)) { dai_link->params = &codec_params; - dai_link->no_pcm = 0; /* link is not a DPCM BE */ + } else { + dai_link->no_pcm = 1; + snd_soc_dai_link_set_capabilities(dai_link); + if (axg_card_cpu_is_tdm_iface(dai_link->cpus->of_node)) + ret = axg_card_parse_tdm(card, np, index); } return ret; diff --git a/sound/soc/meson/gx-card.c b/sound/soc/meson/gx-card.c index 4abf7efb7eacc..fdd2d5303b2a7 100644 --- a/sound/soc/meson/gx-card.c +++ b/sound/soc/meson/gx-card.c @@ -96,21 +96,21 @@ static int gx_card_add_link(struct snd_soc_card *card, struct device_node *np, return ret; if (gx_card_cpu_identify(dai_link->cpus, "FIFO")) - ret = meson_card_set_fe_link(card, dai_link, np, true); - else - ret = meson_card_set_be_link(card, dai_link, np); + return meson_card_set_fe_link(card, dai_link, np, true); + ret = meson_card_set_be_link(card, dai_link, np); if (ret) return ret; - /* Check if the cpu is the i2s encoder and parse i2s data */ - if (gx_card_cpu_identify(dai_link->cpus, "I2S Encoder")) - ret = gx_card_parse_i2s(card, np, index); - /* Or apply codec to codec params if necessary */ - else if (gx_card_cpu_identify(dai_link->cpus, "CODEC CTRL")) { + if (gx_card_cpu_identify(dai_link->cpus, "CODEC CTRL")) { dai_link->params = &codec_params; - dai_link->no_pcm = 0; /* link is not a DPCM BE */ + } else { + dai_link->no_pcm = 1; + snd_soc_dai_link_set_capabilities(dai_link); + /* Check if the cpu is the i2s encoder and parse i2s data */ + if (gx_card_cpu_identify(dai_link->cpus, "I2S Encoder")) + ret = gx_card_parse_i2s(card, np, index); } return ret; diff --git a/sound/soc/meson/meson-card-utils.c b/sound/soc/meson/meson-card-utils.c index 5a4a91c887347..c734131ff0d62 100644 --- a/sound/soc/meson/meson-card-utils.c +++ b/sound/soc/meson/meson-card-utils.c @@ -147,10 +147,6 @@ int meson_card_set_be_link(struct snd_soc_card *card, struct device_node *np; int ret, num_codecs; - link->no_pcm = 1; - link->dpcm_playback = 1; - link->dpcm_capture = 1; - num_codecs = of_get_child_count(node); if (!num_codecs) { dev_err(card->dev, "be link %s has no codec\n", -- 2.25.1
Re: [RFC PATCH v1] dma-fence-array: Deal with sub-fences that are signaled late
On Thu, Aug 13, 2020 at 07:49:24AM +0100, Chris Wilson wrote: > Quoting Jordan Crouse (2020-08-13 00:55:44) > > This is an RFC because I'm still trying to grok the correct behavior. > > > > Consider a dma_fence_array created two two fence and signal_on_any is true. > > A reference to dma_fence_array is taken for each waiting fence. > > > > When the client calls dma_fence_wait() only one of the fences is signaled. > > The client returns successfully from the wait and puts it's reference to > > the array fence but the array fence still remains because of the remaining > > un-signaled fence. > > > > Now consider that the unsignaled fence is signaled while the timeline is > > being > > destroyed much later. The timeline destroy calls dma_fence_signal_locked(). > > The > > following sequence occurs: > > > > 1) dma_fence_array_cb_func is called > > > > 2) array->num_pending is 0 (because it was set to 1 due to signal_on_any) > > so the > > callback function calls dma_fence_put() instead of triggering the irq work > > > > 3) The array fence is released which in turn puts the lingering fence which > > is > > then released > > > > 4) deadlock with the timeline > > It's the same recursive lock as we previously resolved in sw_sync.c by > removing the locking from timeline_fence_release(). Ah, yep. I'm working on a not-quite-ready-for-primetime version of a vulkan timeline implementation for drm/msm and I was doing something similar to how sw_sync used to work in the release function. Getting rid of the recursive lock in the timeline seems a better solution than this. Thanks for taking the time to respond. Jordan > -Chris -- The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
[PATCH v3 13/44] staging: mfd: hi6421-spmi-pmic: deal with non-static functions
Several functions aren't used outside the mfd driver. So, either remove or make them static. Signed-off-by: Mauro Carvalho Chehab --- drivers/staging/hikey9xx/hi6421-spmi-pmic.c | 147 1 file changed, 24 insertions(+), 123 deletions(-) diff --git a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c index 809381eb6043..8b87d48b88b5 100644 --- a/drivers/staging/hikey9xx/hi6421-spmi-pmic.c +++ b/drivers/staging/hikey9xx/hi6421-spmi-pmic.c @@ -73,21 +73,21 @@ u32 hisi_pmic_read(struct hisi_pmic *pmic, int reg) u8 read_value = 0; struct spmi_device *pdev; - if (NULL == g_pmic) { - pr_err(" g_pmic is NULL\n"); + if (!g_pmic) { + pr_err("%s: g_pmic is NULL\n", __func__); return 0; } pdev = to_spmi_device(g_pmic->dev); - if (NULL == pdev) { - pr_err("%s:pdev get failed!\n", __func__); + if (!pdev) { + pr_err("%s: pdev get failed!\n", __func__); return 0; } ret = spmi_ext_register_readl(pdev, reg, (unsigned char*)&read_value, 1);/*lint !e734 !e732 */ if (ret) { - pr_err("%s:spmi_ext_register_readl failed!\n", __func__); - return ret; + pr_err("%s: spmi_ext_register_readl failed!\n", __func__); + return 0; } return (u32)read_value; } @@ -98,34 +98,32 @@ void hisi_pmic_write(struct hisi_pmic *pmic, int reg, u32 val) u32 ret; struct spmi_device *pdev; - if (NULL == g_pmic) { - pr_err(" g_pmic is NULL\n"); + if (!g_pmic) { + pr_err("%s: g_pmic is NULL\n", __func__); return; } pdev = to_spmi_device(g_pmic->dev); - if (NULL == pdev) { - pr_err("%s:pdev get failed!\n", __func__); + if (!pdev) { + pr_err("%s: pdev get failed!\n", __func__); return; } ret = spmi_ext_register_writel(pdev, reg, (unsigned char*)&val, 1);/*lint !e734 !e732 */ if (ret) { - pr_err("%s:spmi_ext_register_writel failed!\n", __func__); - return ; + pr_err("%s: spmi_ext_register_writel failed!\n", __func__); + return; } } EXPORT_SYMBOL(hisi_pmic_write); - -void hisi_pmic_rmw(struct hisi_pmic *pmic, int reg, -u32 mask, u32 bits) +void hisi_pmic_rmw(struct hisi_pmic *pmic, int reg, u32 mask, u32 bits) { u32 data; unsigned long flags; - if (NULL == g_pmic) { - pr_err(" g_pmic is NULL\n"); + if (!g_pmic) { + pr_err("%s: g_pmic is NULL\n", __func__); return; } @@ -137,75 +135,6 @@ void hisi_pmic_rmw(struct hisi_pmic *pmic, int reg, } EXPORT_SYMBOL(hisi_pmic_rmw); -unsigned int hisi_pmic_reg_read(int addr) -{ - return (unsigned int)hisi_pmic_read(g_pmic, addr); -} -EXPORT_SYMBOL(hisi_pmic_reg_read); - -void hisi_pmic_reg_write(int addr, int val) -{ - hisi_pmic_write(g_pmic, addr, val); -} -EXPORT_SYMBOL(hisi_pmic_reg_write); - -void hisi_pmic_reg_write_lock(int addr, int val) -{ - unsigned long flags; - - if (NULL == g_pmic) { - pr_err(" g_pmic is NULL\n"); - return; - } - - spin_lock_irqsave(&g_pmic->lock, flags); - hisi_pmic_write(g_pmic, g_pmic->normal_lock.addr, g_pmic->normal_lock.val); - hisi_pmic_write(g_pmic, g_pmic->debug_lock.addr, g_pmic->debug_lock.val); - hisi_pmic_write(g_pmic, addr, val); - hisi_pmic_write(g_pmic, g_pmic->normal_lock.addr, 0); - hisi_pmic_write(g_pmic, g_pmic->debug_lock.addr, 0); - spin_unlock_irqrestore(&g_pmic->lock, flags); -} - -int hisi_pmic_array_read(int addr, char *buff, unsigned int len) -{ - unsigned int i; - - if ((len > 32) || (NULL == buff)) { - return -EINVAL; - } - - /* -* Here is a bug in the pmu die. -* the coul driver will read 4 bytes, -* but the ssi bus only read 1 byte, and the pmu die -* will make sampling 1/10669us about vol cur,so the driver -* read the data is not the same sampling -*/ - for (i = 0; i < len; i++) - { - *(buff + i) = hisi_pmic_reg_read(addr+i); - } - - return 0; -} - -int hisi_pmic_array_write(int addr, char *buff, unsigned int len) -{ -unsigned int i; - - if ((len > 32) || (NULL == buff)) { - return -EINVAL; - } - - for (i = 0; i < len; i++) - { - hisi_pmic_reg_write(addr+i, *(buff + i)); - } - - return 0; -} - static irqreturn_t hisi_irq_handler(int irq, void *data) { struct hisi_pmic *pmic = (struct hisi_pmic *)data; @@ -213,13 +142,13 @@ static irqreturn_t hisi_irq_handler(int irq, void *data) int i, offset;
Re: [RFC PATCH v1] dma-fence-array: Deal with sub-fences that are signaled late
Am 13.08.20 um 01:55 schrieb Jordan Crouse: This is an RFC because I'm still trying to grok the correct behavior. Consider a dma_fence_array created two two fence and signal_on_any is true. A reference to dma_fence_array is taken for each waiting fence. Ok, that sounds like you seem to mix a couple of things up here. A dma_fence_array takes the reference to the fences it contains on creation. There is only one reference to the dma_fence_array even if it contains N unsignaled fences. What we do is to grab a reference to the array in dma_fence_array_enable_signaling(), but this is because we are registering the callback here. When the client calls dma_fence_wait() only one of the fences is signaled. The client returns successfully from the wait and puts it's reference to the array fence but the array fence still remains because of the remaining un-signaled fence. If signaling was enabled then this is correct, because otherwise we would crash when the other callbacks are called. Now consider that the unsignaled fence is signaled while the timeline is being destroyed much later. The timeline destroy calls dma_fence_signal_locked(). The following sequence occurs: 1) dma_fence_array_cb_func is called 2) array->num_pending is 0 (because it was set to 1 due to signal_on_any) so the callback function calls dma_fence_put() instead of triggering the irq work 3) The array fence is released which in turn puts the lingering fence which is then released 4) deadlock with the timeline Why do we have a deadlock here? That doesn't seems to add up. Christian. I think that we can fix this with the attached patch. Once the fence is signaled signaling it again in the irq worker shouldn't hurt anything. The only gotcha might be how the error is propagated - I wasn't quite sure the intent of clearing it only after getting to the irq worker. Signed-off-by: Jordan Crouse --- drivers/dma-buf/dma-fence-array.c | 10 -- 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/dma-buf/dma-fence-array.c b/drivers/dma-buf/dma-fence-array.c index d3fbd950be94..b8829b024255 100644 --- a/drivers/dma-buf/dma-fence-array.c +++ b/drivers/dma-buf/dma-fence-array.c @@ -46,8 +46,6 @@ static void irq_dma_fence_array_work(struct irq_work *wrk) { struct dma_fence_array *array = container_of(wrk, typeof(*array), work); - dma_fence_array_clear_pending_error(array); - dma_fence_signal(&array->base); dma_fence_put(&array->base); } @@ -61,10 +59,10 @@ static void dma_fence_array_cb_func(struct dma_fence *f, dma_fence_array_set_pending_error(array, f->error); - if (atomic_dec_and_test(&array->num_pending)) - irq_work_queue(&array->work); - else - dma_fence_put(&array->base); + if (!atomic_dec_and_test(&array->num_pending)) + dma_fence_array_set_pending_error(array, f->error); + + irq_work_queue(&array->work); } static bool dma_fence_array_enable_signaling(struct dma_fence *fence)
[RFC PATCH v1] dma-fence-array: Deal with sub-fences that are signaled late
This is an RFC because I'm still trying to grok the correct behavior. Consider a dma_fence_array created two two fence and signal_on_any is true. A reference to dma_fence_array is taken for each waiting fence. When the client calls dma_fence_wait() only one of the fences is signaled. The client returns successfully from the wait and puts it's reference to the array fence but the array fence still remains because of the remaining un-signaled fence. Now consider that the unsignaled fence is signaled while the timeline is being destroyed much later. The timeline destroy calls dma_fence_signal_locked(). The following sequence occurs: 1) dma_fence_array_cb_func is called 2) array->num_pending is 0 (because it was set to 1 due to signal_on_any) so the callback function calls dma_fence_put() instead of triggering the irq work 3) The array fence is released which in turn puts the lingering fence which is then released 4) deadlock with the timeline I think that we can fix this with the attached patch. Once the fence is signaled signaling it again in the irq worker shouldn't hurt anything. The only gotcha might be how the error is propagated - I wasn't quite sure the intent of clearing it only after getting to the irq worker. Signed-off-by: Jordan Crouse --- drivers/dma-buf/dma-fence-array.c | 10 -- 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/dma-buf/dma-fence-array.c b/drivers/dma-buf/dma-fence-array.c index d3fbd950be94..b8829b024255 100644 --- a/drivers/dma-buf/dma-fence-array.c +++ b/drivers/dma-buf/dma-fence-array.c @@ -46,8 +46,6 @@ static void irq_dma_fence_array_work(struct irq_work *wrk) { struct dma_fence_array *array = container_of(wrk, typeof(*array), work); - dma_fence_array_clear_pending_error(array); - dma_fence_signal(&array->base); dma_fence_put(&array->base); } @@ -61,10 +59,10 @@ static void dma_fence_array_cb_func(struct dma_fence *f, dma_fence_array_set_pending_error(array, f->error); - if (atomic_dec_and_test(&array->num_pending)) - irq_work_queue(&array->work); - else - dma_fence_put(&array->base); + if (!atomic_dec_and_test(&array->num_pending)) + dma_fence_array_set_pending_error(array, f->error); + + irq_work_queue(&array->work); } static bool dma_fence_array_enable_signaling(struct dma_fence *fence) -- 2.25.1