5.4.229-rc1 review
Subsystems (8)
Greg Kroah-Hartman
maintainerPATCH 606/658 s390/percpu: add READ_ONCE() to arch_this_cpu_to_op_simple()
In reply to Greg Kroah-HartmanFrom: Heiko Carstens <[email protected]>
commit e3f360db08d55a14112bd27454e616a24296a8b0 upstream.
Make sure that *ptr__ within arch_this_cpu_to_op_simple() is only dereferenced once by using READ_ONCE(). Otherwise the compiler could generate incorrect code.
--- arch/s390/include/asm/percpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/include/asm/percpu.h +1 -1
@@ -31,7 +31,7 @@pcp_op_T__ *ptr__; \preempt_disable_notrace (); \ ptr__ =raw_cpu_ptr (&(pcp)); \ - prev__ = *ptr__; \ + prev__ =READ_ONCE (*ptr__); \ do { \ old__ = prev__; \ new__ = old__ op (val); \
Greg Kroah-Hartman
maintainerPATCH 607/658 net/ulp: prevent ULP without clone op from entering the LISTEN status
In reply to Greg Kroah-HartmanFrom: Paolo Abeni <[email protected]>
commit 2c02d41d71f90a5168391b6a5f2954112ba2307c upstream.
When an ULP-enabled socket enters the LISTEN status, the listener ULP data pointer is copied inside the child/accepted sockets by sk_clone_lock().
The relevant ULP can take care of de-duplicating the context pointer via the clone() operation, but only MPTCP and SMC implement such op.
Other ULPs may end-up with a double-free at socket disposal time.
We can't simply clear the ULP data at clone time, as TLS replaces the socket ops with custom ones assuming a valid TLS ULP context is available.
Instead completely prevent clone-less ULP sockets from entering the LISTEN status.
--- net/ipv4/inet_connection_sock.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
net/ipv4/inet_connection_sock.c +15 -1
@@ -902,11 +902,25 @@ void inet_csk_prepare_forced_close(struc }EXPORT_SYMBOL (inet_csk_prepare_forced_close); +static int inet_ulp_can_listen (const struct sock *sk) +{ +const struct inet_connection_sock *icsk =inet_csk (sk); + +if (icsk->icsk_ulp_ops) +return -EINVAL ; + +return 0 ; +} +int inet_csk_listen_start (struct sock *sk,int backlog) {struct inet_connection_sock *icsk =inet_csk (sk);struct inet_sock *inet =inet_sk (sk); -int err = -EADDRINUSE ; +int err; + + err =inet_ulp_can_listen (sk); +if (unlikely (err)) +return err;reqsk_queue_alloc (&icsk->icsk_accept_queue);
Greg Kroah-Hartman
maintainerPATCH 608/658 ALSA: pcm: Move rwsem lock inside snd_ctl_elem_read to prevent UAF
In reply to Greg Kroah-HartmanFrom: Clement Lecigne <[email protected]>
[ Note: this is a fix that works around the bug equivalently as the
two upstream commits:
1fa4445f9adf ("ALSA: control - introduce snd_ctl_notify_one() helper") 56b88b50565c ("ALSA: pcm: Move rwsem lock inside snd_ctl_elem_read to prevent UAF")
but in a simpler way to fit with older stable trees -- tiwai ]
Add missing locking in ctl_elem_read_user/ctl_elem_write_user which can be easily triggered and turned into an use-after-free.
Example code paths with SNDRV_CTL_IOCTL_ELEM_READ:
64-bits:snd_ctl_ioctl
snd_ctl_elem_read_user
[takes controls_rwsem]
snd_ctl_elem_read [lock properly held, all good] [drops controls_rwsem]
32-bits (compat):snd_ctl_ioctl_compat
snd_ctl_elem_write_read_compat
ctl_elem_write_read
snd_ctl_elem_read [missing lock, not good]
CVE-2023-0266 was assigned for this issue.
--- sound/core/control_compat.c | 4 ++++ 1 file changed, 4 insertions(+)
sound/core/control_compat.c +4 -0
@@ -306,7 +306,9 @@ static int ctl_elem_read_user(struct snd err =snd_power_wait (card,SNDRV_CTL_POWER_D0 );if (err <0 ) goto error; +down_read (&card->controls_rwsem); err =snd_ctl_elem_read (card, data); +up_read (&card->controls_rwsem);if (err <0 ) goto error; err =copy_ctl_value_to_user (userdata, valuep, data, type, count);
@@ -334,7 +336,9 @@ static int ctl_elem_write_user(struct sn err =snd_power_wait (card,SNDRV_CTL_POWER_D0 );if (err <0 ) goto error; +down_write (&card->controls_rwsem); err =snd_ctl_elem_write (card, file, data); +up_write (&card->controls_rwsem);if (err <0 ) goto error; err =copy_ctl_value_to_user (userdata, valuep, data, type, count);
Greg Kroah-Hartman
maintainerPATCH 609/658 ALSA: hda/hdmi: Add a HP device 0x8715 to force connect list
In reply to Greg Kroah-HartmanFrom: Adrian Chan <[email protected]>
commit de1ccb9e61728dd941fe0e955a7a129418657267 upstream.
Add the 'HP Engage Flex Mini' device to the force connect list to enable audio through HDMI.
--- sound/pci/hda/patch_hdmi.c | 1 + 1 file changed, 1 insertion(+)
sound/pci/hda/patch_hdmi.c +1 -0
@@ -1821,6 +1821,7 @@ static const struct snd_pci_quirk force_SND_PCI_QUIRK (0x103c ,0x870f ,"HP" ,1 ),SND_PCI_QUIRK (0x103c ,0x871a ,"HP" ,1 ),SND_PCI_QUIRK (0x103c ,0x8711 ,"HP" ,1 ), +SND_PCI_QUIRK (0x103c ,0x8715 ,"HP" ,1 ), SND_PCI_QUIRK(0x1462, 0xec94, "MS-7C94", 1), {} };
Greg Kroah-Hartman
maintainerPATCH 610/658 cifs: Fix uninitialized memory read for smb311 posix symlink create
In reply to Greg Kroah-HartmanFrom: Volker Lendecke <[email protected]>
commit a152d05ae4a71d802d50cf9177dba34e8bb09f68 upstream.
If smb311 posix is enabled, we send the intended mode for file creation in the posix create context. Instead of using what's there on the stack, create the mfsymlink file with 0644.
--- fs/cifs/link.c | 1 + 1 file changed, 1 insertion(+)
fs/cifs/link.c +1 -0
@@ -481,6 +481,7 @@ smb3_create_mf_symlink(unsigned int xid, oparms.disposition =FILE_CREATE ; oparms.fid = &fid; oparms.reconnect = false; + oparms.mode =0644 ; rc =SMB2_open (xid, &oparms, utf16_path, &oplock,NULL ,NULL ,NULL );
Greg Kroah-Hartman
maintainerPATCH 611/658 drm/msm/adreno: Make adreno quirks not overwrite each other
In reply to Greg Kroah-HartmanFrom: Konrad Dybcio <[email protected]>
commit 13ef096e342b00e30b95a90c6c13eee1f0bec4c5 upstream.
So far the adreno quirks have all been assigned with an OR operator, which is problematic, because they were assigned consecutive integer values, which makes checking them with an AND operator kind of no bueno..
Switch to using BIT(n) so that only the quirks that the programmer chose are taken into account when evaluating info->quirks & ADRENO_QUIRK_...
Patchwork: https://patchwork.freedesktop.org/patch/516456/
--- drivers/gpu/drm/msm/adreno/adreno_gpu.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpu/drm/msm/adreno/adreno_gpu.h +4 -6
@@ -47,11 +47,9 @@ enum { ADRENO_FW_MAX, }; -enum adreno_quirks { -ADRENO_QUIRK_TWO_PASS_USE_WFI =1 , -ADRENO_QUIRK_FAULT_DETECT_MASK =2 , -ADRENO_QUIRK_LMLOADKILL_DISABLE =3 , -}; +#define ADRENO_QUIRK_TWO_PASS_USE_WFI BIT(0) +#define ADRENO_QUIRK_FAULT_DETECT_MASK BIT(1) +#define ADRENO_QUIRK_LMLOADKILL_DISABLE BIT(2)struct adreno_rev {uint8_t core;
@@ -74,7 +72,7 @@ struct adreno_info {const char *name;const char *fw[ADRENO_FW_MAX ];uint32_t gmem; -enum adreno_quirks quirks; +u64 quirks;struct msm_gpu *(*init)(struct drm_device *dev);const char *zapfw;u32 inactive_period;
Greg Kroah-Hartman
maintainerPATCH 612/658 platform/x86: sony-laptop: Dont turn off 0x153 keyboard backlight during probe
In reply to Greg Kroah-HartmanFrom: Hans de Goede <[email protected]>
commit ad75bd85b1db69c97eefea07b375567821f6ef58 upstream.
The 0x153 version of the kbd backlight control SNC handle has no separate address to probe if the backlight is there.
This turns the probe call into a set keyboard backlight call with a value of 0 turning off the keyboard backlight.
Skip probing when there is no separate probe address to avoid this.
--- drivers/platform/x86/sony-laptop.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
drivers/platform/x86/sony-laptop.c +14 -7
@@ -1899,14 +1899,21 @@ static int sony_nc_kbd_backlight_setup(sbreak ; } - ret =sony_call_snc_handle (handle, probe_base, &result); -if (ret) -return ret; +/* +* Only probe if there is a separate probe_base, otherwise the probe call +* is equivalent to __sony_nc_kbd_backlight_mode_set(0), resulting in +* the keyboard backlight being turned off. +*/ +if (probe_base) { + ret =sony_call_snc_handle (handle, probe_base, &result); +if (ret) +return ret; -if ((handle ==0x0137 && !(result &0x02 )) || - !(result &0x01 )) { -dprintk ("no backlight keyboard found\n" ); -return 0 ; +if ((handle ==0x0137 && !(result &0x02 )) || + !(result &0x01 )) { +dprintk ("no backlight keyboard found\n" ); +return 0 ; + } } kbdbl_ctl =kzalloc (sizeof (*kbdbl_ctl),GFP_KERNEL );
Greg Kroah-Hartman
maintainerPATCH 613/658 ixgbe: fix pci device refcount leak
In reply to Greg Kroah-HartmanFrom: Yang Yingliang <[email protected]>
commit b93fb4405fcb5112c5739c5349afb52ec7f15c07 upstream.
As the comment of pci_get_domain_bus_and_slot() says, it returns a PCI device with refcount incremented, when finish using it, the caller must decrement the reference count by calling pci_dev_put().
In ixgbe_get_first_secondary_devfn() and ixgbe_x550em_a_has_mii(), pci_dev_put() is called to avoid leak.
--- drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c +9 -5
@@ -851,9 +851,11 @@ static struct pci_dev *ixgbe_get_first_s rp_pdev =pci_get_domain_bus_and_slot (0 ,0 , devfn);if (rp_pdev && rp_pdev->subordinate) { bus = rp_pdev->subordinate->number; +pci_dev_put (rp_pdev);return pci_get_domain_bus_and_slot (0 , bus,0 ); } +pci_dev_put (rp_pdev);return NULL ; }
@@ -870,6 +872,7 @@ static bool ixgbe_x550em_a_has_mii(strucstruct ixgbe_adapter *adapter = hw->back;struct pci_dev *pdev = adapter->pdev;struct pci_dev *func0_pdev; +bool has_mii = false;/* For the C3000 family of SoCs (x550em_a) the internal ixgbe devices * are always downstream of root ports @ 0000:00:16.0 & 0000:00:17.0
@@ -880,15 +883,16 @@ static bool ixgbe_x550em_a_has_mii(struc func0_pdev =ixgbe_get_first_secondary_devfn (PCI_DEVFN (0x16 ,0 ));if (func0_pdev) {if (func0_pdev == pdev) -return true; -else -return false; + has_mii = true; + goto out; } func0_pdev =ixgbe_get_first_secondary_devfn (PCI_DEVFN (0x17 ,0 ));if (func0_pdev == pdev) -return true; + has_mii = true; -return false; +out: +pci_dev_put (func0_pdev); +return has_mii; }/**
Greg Kroah-Hartman
maintainerPATCH 614/658 ipv6: raw: Deduct extension header length in rawv6_push_pending_frames
In reply to Greg Kroah-HartmanFrom: Herbert Xu <[email protected]>
commit cb3e9864cdbe35ff6378966660edbcbac955fe17 upstream.
The total cork length created by ip6_append_data includes extension headers, so we must exclude them when comparing them against the IPV6_CHECKSUM offset which does not include extension headers.
--- net/ipv6/raw.c | 4 ++++ 1 file changed, 4 insertions(+)
net/ipv6/raw.c +4 -0
@@ -539,6 +539,7 @@ csum_copy_err:static int rawv6_push_pending_frames (struct sock *sk,struct flowi6 *fl6,struct raw6_sock *rp) { +struct ipv6_txoptions *opt;struct sk_buff *skb;int err =0 ;int offset;
@@ -556,6 +557,9 @@ static int rawv6_push_pending_frames(str offset = rp->offset; total_len =inet_sk (sk)->cork.base.length; + opt =inet6_sk (sk)->cork.opt; + total_len -= opt ? opt->opt_flen :0 ; +if (offset >= total_len -1 ) { err = -EINVAL ;ip6_flush_pending_frames (sk);
Greg Kroah-Hartman
maintainerPATCH 615/658 wifi: wilc1000: sdio: fix module autoloading
In reply to Greg Kroah-HartmanFrom: Michael Walle <[email protected]>
[ Upstream commit 57d545b5a3d6ce3a8fb6b093f02bfcbb908973f3 ]
There are no SDIO module aliases included in the driver, therefore, module autoloading isn't working. Add the proper MODULE_DEVICE_TABLE().
--- drivers/staging/wilc1000/wilc_sdio.c | 1 + 1 file changed, 1 insertion(+)
drivers/staging/wilc1000/wilc_sdio.c +1 -0
@@ -20,6 +20,7 @@ static const struct sdio_device_id wilc_sdio_ids[] = { { SDIO_DEVICE(SDIO_VENDOR_ID_WILC, SDIO_DEVICE_ID_WILC) }, { }, }; +MODULE_DEVICE_TABLE (sdio, wilc_sdio_ids);#define WILC_SDIO_BLOCK_SIZE 512
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 616/658 usb: ulpi: defer ulpi_register on ulpi_read_id timeout
In reply to Greg Kroah-HartmanFrom: Ferry Toth <[email protected]>
[ Upstream commit 8a7b31d545d3a15f0e6f5984ae16f0ca4fd76aac ]
Since commit 0f0101719138 ("usb: dwc3: Don't switch OTG -> peripheral if extcon is present") Dual Role support on Intel Merrifield platform broke due to rearranging the call to dwc3_get_extcon().
It appears to be caused by ulpi_read_id() on the first test write failing with -ETIMEDOUT. Currently ulpi_read_id() expects to discover the phy via DT when the test write fails and returns 0 in that case, even if DT does not provide the phy. As a result usb probe completes without phy.
Make ulpi_read_id() return -ETIMEDOUT to its user if the first test write fails. The user should then handle it appropriately. A follow up patch will make dwc3_core_init() set -EPROBE_DEFER in this case and bail out.
--- drivers/usb/common/ulpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/common/ulpi.c +1 -1
@@ -207,7 +207,7 @@ static int ulpi_read_id(struct ulpi *ulpi)/* Test the interface */ ret =ulpi_write (ulpi,ULPI_SCRATCH ,0xaa );if (ret <0 ) - goto err; +return ret; ret =ulpi_read (ulpi,ULPI_SCRATCH );if (ret <0 )
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 617/658 ext4: Provide function to handle transaction restarts
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit a413036791d040e33badcc634453a4d0c0705499 ]
Provide ext4_journal_ensure_credits_fn() function to ensure transaction has given amount of credits and call helper function to prepare for restarting a transaction. This allows to remove some boilerplate code from various places, add proper error handling for the case where transaction extension or restart fails, and reduces following changes needed for proper revoke record reservation tracking.
Stable-dep-of: d87a7b4c77a9 ("jbd2: use the correct print format")
--- fs/ext4/ext4.h | 4 +- fs/ext4/ext4_jbd2.c | 11 ++++++ fs/ext4/ext4_jbd2.h | 48 +++++++++++++++++++++++ fs/ext4/extents.c | 68 +++++++++++++++++++------------- fs/ext4/indirect.c | 93 +++++++++++++++++++++++++------------------- fs/ext4/inode.c | 26 ------------- fs/ext4/migrate.c | 95 +++++++++++++++++---------------------------- fs/ext4/resize.c | 46 +++++----------------- fs/ext4/xattr.c | 90 ++++++++++++++++-------------------------- 9 files changed, 234 insertions(+), 247 deletions(-)
fs/ext4/ext4.h +3 -1
@@ -2634,7 +2634,6 @@ extern int ext4_can_truncate(struct inode *inode);extern int ext4_truncate (struct inode *);extern int ext4_break_layouts (struct inode *);extern int ext4_punch_hole (struct inode *inode,loff_t offset,loff_t length); -extern int ext4_truncate_restart_trans (handle_t *,struct inode *,int nblocks);extern void ext4_set_inode_flags (struct inode *);extern int ext4_alloc_da_blocks (struct inode *inode);extern void ext4_set_aops (struct inode *inode);
@@ -3327,6 +3326,9 @@ extern int ext4_swap_extents(handle_t *handle, struct inode *inode1, ext4_lblk_t lblk2, ext4_lblk_t count, int mark_unwritten,int *err);extern int ext4_clu_mapped (struct inode *inode,ext4_lblk_t lclu); +extern int ext4_datasem_ensure_credits (handle_t *handle,struct inode *inode, +int check_cred,int restart_cred); +/* move_extent.c */ extern void ext4_double_down_write_data_sem(struct inode *first,
fs/ext4/ext4_jbd2.c +11 -0
@@ -133,6 +133,17 @@ handle_t *__ext4_journal_start_reserved(handle_t *handle, unsigned int line,return handle; } +int __ext4_journal_ensure_credits (handle_t *handle,int check_cred, +int extend_cred) +{ +if (!ext4_handle_valid (handle)) +return 0 ; +if (handle->h_buffer_credits >= check_cred) +return 0 ; +return ext4_journal_extend (handle, + extend_cred - handle->h_buffer_credits); +} + static void ext4_journal_abort_handle(const char *caller, unsigned int line, const char *err_fn, struct buffer_head *bh,
fs/ext4/ext4_jbd2.h +48 -0
54 lines not on this page · raw message
fs/ext4/extents.c +40 -28
91 lines not on this page · raw message
fs/ext4/indirect.c +54 -39
119 lines not on this page · raw message
fs/ext4/inode.c +0 -26
@@ -163,32 +163,6 @@ int ext4_inode_is_fast_symlink(struct inode *inode) (inode->i_size <EXT4_N_BLOCKS *4 ); } -/* -* Restart the transaction associated with *handle. This does a commit, -* so before we call here everything must be consistently dirtied against -* this transaction. -*/ -int ext4_truncate_restart_trans (handle_t *handle,struct inode *inode, -int nblocks) -{ -int ret; - -/* -* Drop i_data_sem to avoid deadlock with ext4_map_blocks. At this -* moment, get_block can be called only for blocks inside i_size since -* page cache has been already dropped and writes are blocked by -* i_mutex. So we can safely drop the i_data_sem here. -*/ -BUG_ON (EXT4_JOURNAL (inode) ==NULL ); -jbd_debug (2 ,"restarting handle %p\n" , handle); -up_write (&EXT4_I (inode)->i_data_sem); - ret =ext4_journal_restart (handle, nblocks); -down_write (&EXT4_I (inode)->i_data_sem); -ext4_discard_preallocations (inode); - -return ret; -} -/* * Called at the last iput() if i_nlink is zero. */
fs/ext4/migrate.c +35 -60
166 lines not on this page · raw message
fs/ext4/resize.c +10 -36
82 lines not on this page · raw message
fs/ext4/xattr.c +33 -57
118 lines not on this page · raw message
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 618/658 ext4, jbd2: Provide accessor function for handle credits
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit a9a8344ee1714f835ba394077e8c13d751e2f148 ]
Provide accessor function to get number of credits available in a handle and use it from ext4. Later, computation of available credits won't be so straightforward.
Stable-dep-of: d87a7b4c77a9 ("jbd2: use the correct print format")
--- fs/ext4/ext4_jbd2.c | 13 +++++++------ fs/ext4/ext4_jbd2.h | 7 ------- fs/ext4/xattr.c | 2 +- include/linux/jbd2.h | 6 ++++++ 4 files changed, 14 insertions(+), 14 deletions(-)
fs/ext4/ext4_jbd2.c +7 -6
@@ -119,8 +119,8 @@ handle_t *__ext4_journal_start_reserved(handle_t *handle, unsigned int line,return ext4_get_nojournal (); sb = handle->h_journal->j_private; -trace_ext4_journal_start_reserved (sb, handle->h_buffer_credits, - _RET_IP_); +trace_ext4_journal_start_reserved (sb, +jbd2_handle_buffer_credits (handle), _RET_IP_); err =ext4_journal_check_start (sb);if (err <0 ) {jbd2_journal_free_reserved (handle);
@@ -138,10 +138,10 @@ int __ext4_journal_ensure_credits(handle_t *handle, int check_cred, {if (!ext4_handle_valid (handle))return 0 ; -if (handle->h_buffer_credits >= check_cred) +if (jbd2_handle_buffer_credits (handle) >= check_cred)return 0 ;return ext4_journal_extend (handle, - extend_cred - handle->h_buffer_credits); + extend_cred -jbd2_handle_buffer_credits (handle)); } static void ext4_journal_abort_handle(const char *caller, unsigned int line,
@@ -289,7 +289,7 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line, handle->h_type, handle->h_line_no, handle->h_requested_credits, - handle->h_buffer_credits, err); + jbd2_handle_buffer_credits(handle), err);return err; } ext4_error_inode(inode, where, line,
@@ -300,7 +300,8 @@ int __ext4_handle_dirty_metadata(const char *where, unsigned int line, handle->h_type, handle->h_line_no, handle->h_requested_credits, - handle->h_buffer_credits, err); +jbd2_handle_buffer_credits (handle), + err); } }else {if (inode)
fs/ext4/ext4_jbd2.h +0 -7
@@ -288,13 +288,6 @@ static inline int ext4_handle_is_aborted(handle_t *handle)return 0 ; } -static inline int ext4_handle_has_enough_credits (handle_t *handle,int needed) -{ -if (ext4_handle_valid (handle) && handle->h_buffer_credits < needed) -return 0 ; -return 1 ; -} -#define ext4_journal_start_sb (sb, type, nblocks) \ __ext4_journal_start_sb((sb), __LINE__, (type), (nblocks), 0)
fs/ext4/xattr.c +1 -1
@@ -2330,7 +2330,7 @@ ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index, flags & XATTR_CREATE);brelse (bh); -if (!ext4_handle_has_enough_credits (handle, credits)) { +if (jbd2_handle_buffer_credits (handle) < credits) { error = -ENOSPC ; goto cleanup; }
include/linux/jbd2.h +6 -0
@@ -1644,6 +1644,12 @@ static inline tid_t jbd2_get_latest_transaction(journal_t *journal)return tid; } + +static inline int jbd2_handle_buffer_credits (handle_t *handle) +{ +return handle->h_buffer_credits; +} +#ifdef __KERNEL__#define buffer_trace_init (bh) do {} while (0)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 619/658 ocfs2: Use accessor function for h_buffer_credits
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit 9797a902480521dc8e7a478e38f0c896ffff8784 ]
Use the jbd2 accessor function for h_buffer_credits.
Stable-dep-of: d87a7b4c77a9 ("jbd2: use the correct print format")
--- fs/ocfs2/alloc.c | 32 ++++++++++++++++---------------- fs/ocfs2/journal.c | 4 ++-- 2 files changed, 18 insertions(+), 18 deletions(-)
fs/ocfs2/alloc.c +16 -16
@@ -2288,9 +2288,9 @@ static int ocfs2_extend_rotate_transaction(handle_t *handle, int subtree_depth,int ret =0 ;int credits = (path->p_tree_depth - subtree_depth) *2 +1 + op_credits; -if (handle->h_buffer_credits < credits) +if (jbd2_handle_buffer_credits (handle) < credits) ret =ocfs2_extend_trans (handle, - credits - handle->h_buffer_credits); + credits -jbd2_handle_buffer_credits (handle));return ret; }
@@ -2367,7 +2367,7 @@ static int ocfs2_rotate_tree_right(handle_t *handle,struct ocfs2_path *right_path, struct ocfs2_path **ret_left_path) { - int ret, start, orig_credits = handle->h_buffer_credits; + int ret, start, orig_credits = jbd2_handle_buffer_credits(handle);u32 cpos;struct ocfs2_path *left_path =NULL ;struct super_block *sb =ocfs2_metadata_cache_get_super (et->et_ci);
@@ -3148,7 +3148,7 @@ static int ocfs2_rotate_tree_left(handle_t *handle,struct ocfs2_path *path, struct ocfs2_cached_dealloc_ctxt *dealloc) { - int ret, orig_credits = handle->h_buffer_credits; + int ret, orig_credits = jbd2_handle_buffer_credits(handle);struct ocfs2_path *tmp_path =NULL , *restart_path =NULL ;struct ocfs2_extent_block *eb;struct ocfs2_extent_list *el;
@@ -3386,8 +3386,8 @@ static int ocfs2_merge_rec_right(struct ocfs2_path *left_path, right_path); ret =ocfs2_extend_rotate_transaction (handle, subtree_index, - handle->h_buffer_credits, - right_path); +jbd2_handle_buffer_credits (handle), + right_path);if (ret) {mlog_errno (ret); goto out;
@@ -3548,8 +3548,8 @@ static int ocfs2_merge_rec_left(struct ocfs2_path *right_path, right_path); ret =ocfs2_extend_rotate_transaction (handle, subtree_index, - handle->h_buffer_credits, - left_path); +jbd2_handle_buffer_credits (handle), + left_path);if (ret) {mlog_errno (ret); goto out;
@@ -3623,7 +3623,7 @@ static int ocfs2_merge_rec_left(struct ocfs2_path *right_path, le16_to_cpu(el->l_next_free_rec) == 1) {/* extend credit for ocfs2_remove_rightmost_path */ ret =ocfs2_extend_rotate_transaction (handle,0 , - handle->h_buffer_credits, +jbd2_handle_buffer_credits (handle), right_path);if (ret) {mlog_errno (ret);
@@ -3669,7 +3669,7 @@ static int ocfs2_try_to_merge_extent(handle_t *handle,if (ctxt->c_split_covers_rec && ctxt->c_has_empty_extent) {/* extend credit for ocfs2_remove_rightmost_path */ ret =ocfs2_extend_rotate_transaction (handle,0 , - handle->h_buffer_credits, +jbd2_handle_buffer_credits (handle), path);if (ret) {mlog_errno (ret);
@@ -3725,7 +3725,7 @@ static int ocfs2_try_to_merge_extent(handle_t *handle,/* extend credit for ocfs2_remove_rightmost_path */ ret =ocfs2_extend_rotate_transaction (handle,0 , - handle->h_buffer_credits, +jbd2_handle_buffer_credits (handle), path);if (ret) {mlog_errno (ret);
@@ -3755,7 +3755,7 @@ static int ocfs2_try_to_merge_extent(handle_t *handle,/* extend credit for ocfs2_remove_rightmost_path */ ret =ocfs2_extend_rotate_transaction (handle,0 , - handle->h_buffer_credits, +jbd2_handle_buffer_credits (handle), path);if (ret) {mlog_errno (ret);
@@ -3799,7 +3799,7 @@ static int ocfs2_try_to_merge_extent(handle_t *handle,if (ctxt->c_split_covers_rec) {/* extend credit for ocfs2_remove_rightmost_path */ ret =ocfs2_extend_rotate_transaction (handle,0 , - handle->h_buffer_credits, +jbd2_handle_buffer_credits (handle), path);if (ret) {mlog_errno (ret);
@@ -5358,7 +5358,7 @@ static int ocfs2_truncate_rec(handle_t *handle,if (ocfs2_is_empty_extent (&el->l_recs[0 ]) && index >0 ) {/* extend credit for ocfs2_remove_rightmost_path */ ret =ocfs2_extend_rotate_transaction (handle,0 , - handle->h_buffer_credits, +jbd2_handle_buffer_credits (handle), path);if (ret) {mlog_errno (ret);
@@ -5427,8 +5427,8 @@ static int ocfs2_truncate_rec(handle_t *handle, } ret =ocfs2_extend_rotate_transaction (handle,0 , - handle->h_buffer_credits, - path); +jbd2_handle_buffer_credits (handle), + path);if (ret) {mlog_errno (ret); goto out;
fs/ocfs2/journal.c +2 -2
@@ -420,7 +420,7 @@ int ocfs2_extend_trans(handle_t *handle, int nblocks)if (!nblocks)return 0 ; - old_nblocks = handle->h_buffer_credits; + old_nblocks =jbd2_handle_buffer_credits (handle);trace_ocfs2_extend_trans (old_nblocks, nblocks);
@@ -461,7 +461,7 @@ int ocfs2_allocate_extend_trans(handle_t *handle, int thresh)BUG_ON (!handle); - old_nblks = handle->h_buffer_credits; + old_nblks =jbd2_handle_buffer_credits (handle);trace_ocfs2_allocate_extend_trans (old_nblks, thresh);if (old_nblks < thresh)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 620/658 jbd2: Reorganize jbd2_journal_stop()
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit dfaf5ffda227be3e867fee7c0f6a66749392fbd0 ]
Move code in jbd2_journal_stop() around a bit. It removes some unnecessary code duplication and will make factoring out parts common with jbd2__journal_restart() easier.
Stable-dep-of: d87a7b4c77a9 ("jbd2: use the correct print format")
--- fs/jbd2/transaction.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-)
fs/jbd2/transaction.c +16 -24
@@ -1722,41 +1722,34 @@ int jbd2_journal_stop(handle_t *handle)tid_t tid;pid_t pid; +if (--handle->h_ref >0 ) { +jbd_debug (4 ,"h_ref %d -> %d\n" , handle->h_ref +1 , + handle->h_ref); +if (is_handle_aborted (handle)) +return -EIO ; +return 0 ; + }if (!transaction) {/* -* Handle is already detached from the transaction so -* there is nothing to do other than decrease a refcount, -* or free the handle if refcount drops to zero +* Handle is already detached from the transaction so there is +* nothing to do other than free the handle. */ -if (--handle->h_ref >0 ) { -jbd_debug (4 ,"h_ref %d -> %d\n" , handle->h_ref +1 , - handle->h_ref); -return err; - }else { -if (handle->h_rsv_handle) -jbd2_free_handle (handle->h_rsv_handle); - goto free_and_exit; - } +if (handle->h_rsv_handle) +jbd2_free_handle (handle->h_rsv_handle); + goto free_and_exit; } journal = transaction->t_journal; + tid = transaction->t_tid;J_ASSERT (journal_current_handle () == handle); +J_ASSERT (atomic_read (&transaction->t_updates) >0 );if (is_handle_aborted (handle)) err = -EIO ; -else -J_ASSERT (atomic_read (&transaction->t_updates) >0 ); - -if (--handle->h_ref >0 ) { -jbd_debug (4 ,"h_ref %d -> %d\n" , handle->h_ref +1 , - handle->h_ref); -return err; - }jbd_debug (4 ,"Handle %p going down\n" , handle); trace_jbd2_handle_stats(journal->j_fs_dev->bd_dev, - transaction->t_tid, - handle->h_type, handle->h_line_no, + tid, handle->h_type, handle->h_line_no, jiffies - handle->h_start_jiffies, handle->h_sync, handle->h_requested_credits, (handle->h_requested_credits -
@@ -1841,7 +1834,7 @@ int jbd2_journal_stop(handle_t *handle)jbd_debug (2 ,"transaction too old, requesting commit for " "handle %p\n" , handle);/* This is non-blocking */ -jbd2_log_start_commit (journal, transaction->t_tid); +jbd2_log_start_commit (journal, tid);/* * Special case: JBD2_SYNC synchronous updates require us
@@ -1857,7 +1850,6 @@ int jbd2_journal_stop(handle_t *handle)* once we do this, we must not dereference transaction * pointer again. */ - tid = transaction->t_tid;if (atomic_dec_and_test (&transaction->t_updates)) {wake_up (&journal->j_wait_updates);if (journal->j_barrier_count)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 621/658 jbd2: Drop pointless wakeup from jbd2_journal_stop()
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit 5559b2d81b51de75cb7864bb1fbb82982f7e8fff ]
When we drop last handle from a transaction and journal->j_barrier_count
Quoted 1 line
0,
jbd2_journal_stop()wakes upjournal->j_wait_transaction_locked
wait queue. This looks pointless - wait for outstanding handles always happens on journal->j_wait_updates waitqueue. journal->j_wait_transaction_locked is used to wait for transaction state changes and by start_this_handle() for waiting until journal->j_barrier_count drops to 0. The first case is clearly irrelevant here since only jbd2 thread changes transaction state. The second case looks related but jbd2_journal_unlock_updates() is responsible for the wakeup in this case. So just drop the wakeup.
Stable-dep-of: d87a7b4c77a9 ("jbd2: use the correct print format")
--- fs/jbd2/transaction.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
fs/jbd2/transaction.c +1 -4
@@ -1850,11 +1850,8 @@ int jbd2_journal_stop(handle_t *handle)* once we do this, we must not dereference transaction * pointer again. */ -if (atomic_dec_and_test (&transaction->t_updates)) { +if (atomic_dec_and_test (&transaction->t_updates))wake_up (&journal->j_wait_updates); -if (journal->j_barrier_count) -wake_up (&journal->j_wait_transaction_locked); - }rwsem_release (&journal->j_trans_commit_map,1 , _THIS_IP_);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 622/658 jbd2: Factor out common parts of stopping and restarting a handle
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit ec8b6f600e49dc87a8564807fec4193bf93ee2b5 ]
jbd2__journal_restart() has quite some code that is common with jbd2_journal_stop(). Factor this functionality into stop_this_handle() helper and use it from both functions. Note that this also drops t_handle_lock protection from jbd2__journal_restart() as jbd2_journal_stop() does the same thing without it.
Stable-dep-of: d87a7b4c77a9 ("jbd2: use the correct print format")
--- fs/jbd2/transaction.c | 98 ++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 52 deletions(-)
fs/jbd2/transaction.c +46 -52
@@ -514,12 +514,17 @@ handle_t *jbd2_journal_start(journal_t *journal, int nblocks) }EXPORT_SYMBOL (jbd2_journal_start); -void jbd2_journal_free_reserved (handle_t *handle) +static void __jbd2_journal_unreserve_handle (handle_t *handle) {journal_t *journal = handle->h_journal;WARN_ON (!handle->h_reserved);sub_reserved_credits (journal, handle->h_buffer_credits); +} + +void jbd2_journal_free_reserved (handle_t *handle) +{ +__jbd2_journal_unreserve_handle (handle);jbd2_free_handle (handle); }EXPORT_SYMBOL (jbd2_journal_free_reserved);
@@ -657,6 +662,28 @@ int jbd2_journal_extend(handle_t *handle, int nblocks)return result; } +static void stop_this_handle (handle_t *handle) +{ +transaction_t *transaction = handle->h_transaction; +journal_t *journal = transaction->t_journal; + +J_ASSERT (journal_current_handle () == handle); +J_ASSERT (atomic_read (&transaction->t_updates) >0 ); + current->journal_info =NULL ; +atomic_sub (handle->h_buffer_credits, + &transaction->t_outstanding_credits); +if (handle->h_rsv_handle) +__jbd2_journal_unreserve_handle (handle->h_rsv_handle); +if (atomic_dec_and_test (&transaction->t_updates)) +wake_up (&journal->j_wait_updates); + +rwsem_release (&journal->j_trans_commit_map,1 , _THIS_IP_); +/* +* Scope of the GFP_NOFS context is over here and so we can restore the +* original alloc context. +*/ +memalloc_nofs_restore (handle->saved_alloc_context); +}/** * int jbd2_journal_restart() - restart a handle .
@@ -679,52 +706,34 @@ int jbd2__journal_restart(handle_t *handle, int nblocks, gfp_t gfp_mask)transaction_t *transaction = handle->h_transaction;journal_t *journal;tid_t tid; -int need_to_start, ret; +int need_to_start;/* If we've had an abort of any type, don't even think about * actually doing the restart! */ if (is_handle_aborted (handle))return 0 ; journal = transaction->t_journal; + tid = transaction->t_tid;/* * First unlink the handle from its current transaction, and start the * commit on that. */ -J_ASSERT (atomic_read (&transaction->t_updates) >0 ); -J_ASSERT (journal_current_handle () == handle); - -read_lock (&journal->j_state_lock); -spin_lock (&transaction->t_handle_lock); -atomic_sub (handle->h_buffer_credits, - &transaction->t_outstanding_credits); -if (handle->h_rsv_handle) { -sub_reserved_credits (journal, - handle->h_rsv_handle->h_buffer_credits); - } -if (atomic_dec_and_test (&transaction->t_updates)) -wake_up (&journal->j_wait_updates); - tid = transaction->t_tid; -spin_unlock (&transaction->t_handle_lock); +jbd_debug (2 ,"restarting handle %p\n" , handle); +stop_this_handle (handle); handle->h_transaction =NULL ; - current->journal_info =NULL ; -jbd_debug (2 ,"restarting handle %p\n" , handle); +/* +* TODO: If we use READ_ONCE / WRITE_ONCE for j_commit_request we can +* get rid of pointless j_state_lock traffic like this. +*/ +read_lock (&journal->j_state_lock); need_to_start = !tid_geq (journal->j_commit_request, tid);read_unlock (&journal->j_state_lock);if (need_to_start)jbd2_log_start_commit (journal, tid); - -rwsem_release (&journal->j_trans_commit_map,1 , _THIS_IP_); handle->h_buffer_credits = nblocks; -/* -* Restore the original nofs context because the journal restart -* is basically the same thing as journal stop and start. -* start_this_handle will start a new nofs context. -*/ -memalloc_nofs_restore (handle->saved_alloc_context); - ret =start_this_handle (journal, handle, gfp_mask); -return ret; +return start_this_handle (journal, handle, gfp_mask); }EXPORT_SYMBOL (jbd2__journal_restart);
@@ -1734,16 +1743,12 @@ int jbd2_journal_stop(handle_t *handle)* Handle is already detached from the transaction so there is * nothing to do other than free the handle. */ -if (handle->h_rsv_handle) -jbd2_free_handle (handle->h_rsv_handle); +memalloc_nofs_restore (handle->saved_alloc_context); goto free_and_exit; } journal = transaction->t_journal; tid = transaction->t_tid; -J_ASSERT (journal_current_handle () == handle); -J_ASSERT (atomic_read (&transaction->t_updates) >0 ); -if (is_handle_aborted (handle)) err = -EIO ;
@@ -1813,9 +1818,6 @@ int jbd2_journal_stop(handle_t *handle)if (handle->h_sync) transaction->t_synchronous_commit =1 ; - current->journal_info =NULL ; -atomic_sub (handle->h_buffer_credits, - &transaction->t_outstanding_credits);/* * If the handle is marked SYNC, we need to set another commit
@@ -1845,27 +1847,19 @@ int jbd2_journal_stop(handle_t *handle) }/* -* Once we drop t_updates, if it goes to zero the transaction -* could start committing on us and eventually disappear. So -* once we do this, we must not dereference transaction -* pointer again. +* Once stop_this_handle() drops t_updates, the transaction could start +* committing on us and eventually disappear. So we must not +* dereference transaction pointer again after calling +* stop_this_handle(). */ -if (atomic_dec_and_test (&transaction->t_updates)) -wake_up (&journal->j_wait_updates); - -rwsem_release (&journal->j_trans_commit_map,1 , _THIS_IP_); +stop_this_handle (handle);if (wait_for_commit) err =jbd2_log_wait_commit (journal, tid); -if (handle->h_rsv_handle) -jbd2_journal_free_reserved (handle->h_rsv_handle); free_and_exit: -/* -* Scope of the GFP_NOFS context is over here and so we can restore the -* original alloc context. -*/ -memalloc_nofs_restore (handle->saved_alloc_context); +if (handle->h_rsv_handle) +jbd2_free_handle (handle->h_rsv_handle);jbd2_free_handle (handle);return err; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 623/658 jbd2: use the correct print format
In reply to Greg Kroah-HartmanFrom: Bixuan Cui <[email protected]>
[ Upstream commit d87a7b4c77a997d5388566dd511ca8e6b8e8a0a8 ]
The print format error was found when using ftrace event:
<...>-1406 [000] .... 23599442.895823: jbd2_end_commit: dev 252,8 transaction -1866216965 sync 0 head -1866217368
<...>-1406 [000] .... 23599442.896299: jbd2_start_commit: dev 252,8 transaction -1866216964 sync 0Use the correct print format for transaction, head and tid.
--- include/trace/events/jbd2.h | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-)
include/trace/events/jbd2.h +20 -20
@@ -40,7 +40,7 @@ DECLARE_EVENT_CLASS(jbd2_commit,TP_STRUCT__entry (__field (dev_t ,dev )__field ( char, sync_commit ) -__field ( int, transaction ) +__field ( tid_t, transaction ) ), TP_fast_assign(
@@ -49,7 +49,7 @@ DECLARE_EVENT_CLASS(jbd2_commit, __entry->transaction = commit_transaction->t_tid; ), -TP_printk ("dev %d,%d transaction %d sync %d" , +TP_printk ("dev %d,%d transaction %u sync %d" ,MAJOR (__entry->dev),MINOR (__entry->dev), __entry->transaction, __entry->sync_commit) );
@@ -97,8 +97,8 @@ TRACE_EVENT(jbd2_end_commit,TP_STRUCT__entry (__field (dev_t ,dev )__field ( char, sync_commit ) -__field ( int, transaction ) -__field ( int, head ) +__field ( tid_t, transaction ) +__field ( tid_t, head ) ), TP_fast_assign(
@@ -108,7 +108,7 @@ TRACE_EVENT(jbd2_end_commit, __entry->head = journal->j_tail_sequence; ), -TP_printk ("dev %d,%d transaction %d sync %d head %d" , +TP_printk ("dev %d,%d transaction %u sync %d head %u" ,MAJOR (__entry->dev),MINOR (__entry->dev), __entry->transaction, __entry->sync_commit, __entry->head) );
@@ -134,14 +134,14 @@ TRACE_EVENT(jbd2_submit_inode_data, ); TRACE_EVENT(jbd2_handle_start, - TP_PROTO(dev_t dev, unsigned long tid, unsigned int type, + TP_PROTO(dev_t dev, tid_t tid, unsigned int type, unsigned int line_no, int requested_blocks), TP_ARGS(dev, tid, type, line_no, requested_blocks), TP_STRUCT__entry( __field( dev_t, dev ) - __field( unsigned long, tid ) + __field( tid_t, tid ) __field( unsigned int, type ) __field( unsigned int, line_no ) __field( int, requested_blocks)
@@ -155,14 +155,14 @@ TRACE_EVENT(jbd2_handle_start, __entry->requested_blocks = requested_blocks; ), -TP_printk ("dev %d,%d tid %lu type %u line_no %u " +TP_printk ("dev %d,%d tid %u type %u line_no %u " "requested_blocks %d" ,MAJOR (__entry->dev),MINOR (__entry->dev), __entry->tid, __entry->type, __entry->line_no, __entry->requested_blocks) ); TRACE_EVENT(jbd2_handle_extend, - TP_PROTO(dev_t dev, unsigned long tid, unsigned int type, + TP_PROTO(dev_t dev, tid_t tid, unsigned int type, unsigned int line_no, int buffer_credits, int requested_blocks),
@@ -170,7 +170,7 @@ TRACE_EVENT(jbd2_handle_extend,TP_STRUCT__entry (__field (dev_t ,dev ) - __field( unsigned long, tid ) +__field ( tid_t, tid ) __field( unsigned int, type ) __field( unsigned int, line_no ) __field( int, buffer_credits )
@@ -186,7 +186,7 @@ TRACE_EVENT(jbd2_handle_extend, __entry->requested_blocks = requested_blocks; ), - TP_printk("dev %d,%d tid %lu type %u line_no %u " + TP_printk("dev %d,%d tid %u type %u line_no %u " "buffer_credits %d requested_blocks %d", MAJOR(__entry->dev), MINOR(__entry->dev), __entry->tid, __entry->type, __entry->line_no, __entry->buffer_credits,
@@ -194,7 +194,7 @@ TRACE_EVENT(jbd2_handle_extend, ); TRACE_EVENT(jbd2_handle_stats, - TP_PROTO(dev_t dev, unsigned long tid, unsigned int type, + TP_PROTO(dev_t dev, tid_t tid, unsigned int type, unsigned int line_no, int interval, int sync, int requested_blocks, int dirtied_blocks),
@@ -203,7 +203,7 @@ TRACE_EVENT(jbd2_handle_stats,TP_STRUCT__entry (__field (dev_t ,dev ) - __field( unsigned long, tid ) +__field ( tid_t, tid ) __field( unsigned int, type ) __field( unsigned int, line_no ) __field( int, interval )
@@ -223,7 +223,7 @@ TRACE_EVENT(jbd2_handle_stats, __entry->dirtied_blocks = dirtied_blocks; ), - TP_printk("dev %d,%d tid %lu type %u line_no %u interval %d " + TP_printk("dev %d,%d tid %u type %u line_no %u interval %d " "sync %d requested_blocks %d dirtied_blocks %d", MAJOR(__entry->dev), MINOR(__entry->dev), __entry->tid, __entry->type, __entry->line_no, __entry->interval,
@@ -232,14 +232,14 @@ TRACE_EVENT(jbd2_handle_stats, ); TRACE_EVENT(jbd2_run_stats, - TP_PROTO(dev_t dev, unsigned long tid, + TP_PROTO(dev_t dev, tid_t tid, struct transaction_run_stats_s *stats), TP_ARGS(dev, tid, stats), TP_STRUCT__entry( __field( dev_t, dev ) - __field( unsigned long, tid ) + __field( tid_t, tid ) __field( unsigned long, wait ) __field( unsigned long, request_delay ) __field( unsigned long, running )
@@ -265,7 +265,7 @@ TRACE_EVENT(jbd2_run_stats, __entry->blocks_logged = stats->rs_blocks_logged; ), - TP_printk("dev %d,%d tid %lu wait %u request_delay %u running %u " + TP_printk("dev %d,%d tid %u wait %u request_delay %u running %u " "locked %u flushing %u logging %u handle_count %u " "blocks %u blocks_logged %u", MAJOR(__entry->dev), MINOR(__entry->dev), __entry->tid,
@@ -280,14 +280,14 @@ TRACE_EVENT(jbd2_run_stats, ); TRACE_EVENT(jbd2_checkpoint_stats, - TP_PROTO(dev_t dev, unsigned long tid, + TP_PROTO(dev_t dev, tid_t tid, struct transaction_chp_stats_s *stats), TP_ARGS(dev, tid, stats), TP_STRUCT__entry( __field( dev_t, dev ) - __field( unsigned long, tid ) + __field( tid_t, tid ) __field( unsigned long, chp_time ) __field( __u32, forced_to_close ) __field( __u32, written )
@@ -303,7 +303,7 @@ TRACE_EVENT(jbd2_checkpoint_stats, __entry->dropped = stats->cs_dropped; ), - TP_printk("dev %d,%d tid %lu chp_time %u forced_to_close %u " + TP_printk("dev %d,%d tid %u chp_time %u forced_to_close %u " "written %u dropped %u", MAJOR(__entry->dev), MINOR(__entry->dev), __entry->tid, jiffies_to_msecs(__entry->chp_time),
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 624/658 quota: Factor out setup of quota inode
In reply to Greg Kroah-HartmanFrom: Jan Kara <[email protected]>
[ Upstream commit c7d3d28360fdb3ed3a5aa0bab19315e0fdc994a1 ]
Factor out setting up of quota inode and eventual error cleanup from vfs_load_quota_inode(). This will simplify situation for filesystems that don't have any quota inodes.
Stable-dep-of: d32387748476 ("ext4: fix bug_on in __es_tree_search caused by bad quota inode")
--- fs/quota/dquot.c | 108 ++++++++++++++++++++++++--------------- include/linux/quotaops.h | 2 + 2 files changed, 69 insertions(+), 41 deletions(-)
fs/quota/dquot.c +67 -41
@@ -2306,28 +2306,60 @@ EXPORT_SYMBOL(dquot_quota_off);* Turn quotas on on a device */ -/* -* Helper function to turn quotas on when we already have the inode of -* quota file and no quota information is loaded. -*/ -static int vfs_load_quota_inode (struct inode *inode,int type,int format_id, +static int vfs_setup_quota_inode (struct inode *inode,int type) +{ +struct super_block *sb = inode->i_sb; +struct quota_info *dqopt =sb_dqopt (sb); + +if (!S_ISREG (inode->i_mode)) +return -EACCES ; +if (IS_RDONLY (inode)) +return -EROFS ; +if (sb_has_quota_loaded (sb, type)) +return -EBUSY ; + + dqopt->files[type] =igrab (inode); +if (!dqopt->files[type]) +return -EIO ; +if (!(dqopt->flags &DQUOT_QUOTA_SYS_FILE )) { +/* We don't want quota and atime on quota files (deadlocks +* possible) Also nobody should write to the file - we use +* special IO operations which ignore the immutable bit. */ +inode_lock (inode); + inode->i_flags |=S_NOQUOTA ; +inode_unlock (inode); +/* +* When S_NOQUOTA is set, remove dquot references as no more +* references can be added +*/ +__dquot_drop (inode); + } +return 0 ; +} + +static void vfs_cleanup_quota_inode (struct super_block *sb,int type) +{ +struct quota_info *dqopt =sb_dqopt (sb); +struct inode *inode = dqopt->files[type]; + +if (!(dqopt->flags &DQUOT_QUOTA_SYS_FILE )) { +inode_lock (inode); + inode->i_flags &= ~S_NOQUOTA ; +inode_unlock (inode); + } + dqopt->files[type] =NULL ; +iput (inode); +} + +int dquot_load_quota_sb (struct super_block *sb,int type,int format_id,unsigned int flags) {struct quota_format_type *fmt =find_quota_format (format_id); -struct super_block *sb = inode->i_sb;struct quota_info *dqopt =sb_dqopt (sb);int error;if (!fmt)return -ESRCH ; -if (!S_ISREG (inode->i_mode)) { - error = -EACCES ; - goto out_fmt; - } -if (IS_RDONLY (inode)) { - error = -EROFS ; - goto out_fmt; - }if (!sb->s_op->quota_write || !sb->s_op->quota_read || (type ==PRJQUOTA && sb->dq_op->get_projid ==NULL )) { error = -EINVAL ;
@@ -2359,27 +2391,9 @@ static int vfs_load_quota_inode(struct inode *inode, int type, int format_id,invalidate_bdev (sb->s_bdev); } -if (!(dqopt->flags &DQUOT_QUOTA_SYS_FILE )) { -/* We don't want quota and atime on quota files (deadlocks -* possible) Also nobody should write to the file - we use -* special IO operations which ignore the immutable bit. */ -inode_lock (inode); - inode->i_flags |=S_NOQUOTA ; -inode_unlock (inode); -/* -* When S_NOQUOTA is set, remove dquot references as no more -* references can be added -*/ -__dquot_drop (inode); - } - - error = -EIO ; - dqopt->files[type] =igrab (inode); -if (!dqopt->files[type]) - goto out_file_flags; error = -EINVAL ;if (!fmt->qf_ops->check_quota_file (sb, type)) - goto out_file_init; + goto out_fmt; dqopt->ops[type] = fmt->qf_ops; dqopt->info[type].dqi_format = fmt;
@@ -2387,7 +2401,7 @@ static int vfs_load_quota_inode(struct inode *inode, int type, int format_id,INIT_LIST_HEAD (&dqopt->info[type].dqi_dirty_list); error = dqopt->ops[type]->read_file_info (sb, type);if (error <0 ) - goto out_file_init; + goto out_fmt;if (dqopt->flags &DQUOT_QUOTA_SYS_FILE ) {spin_lock (&dq_data_lock); dqopt->info[type].dqi_flags |=DQF_SYS_FILE ;
@@ -2402,18 +2416,30 @@ static int vfs_load_quota_inode(struct inode *inode, int type, int format_id,dquot_disable (sb, type, flags);return error; -out_file_init: - dqopt->files[type] =NULL ; -iput (inode); -out_file_flags: -inode_lock (inode); - inode->i_flags &= ~S_NOQUOTA ; -inode_unlock (inode); out_fmt:put_quota_format (fmt);return error; } +EXPORT_SYMBOL (dquot_load_quota_sb); + +/* +* Helper function to turn quotas on when we already have the inode of +* quota file and no quota information is loaded. +*/ +static int vfs_load_quota_inode (struct inode *inode,int type,int format_id, +unsigned int flags) +{ +int err; + + err =vfs_setup_quota_inode (inode, type); +if (err <0 ) +return err; + err =dquot_load_quota_sb (inode->i_sb, type, format_id, flags); +if (err <0 ) +vfs_cleanup_quota_inode (inode->i_sb, type); +return err; +}/* Reenable quotas on remount RW */ int dquot_resume (struct super_block *sb,int type)
include/linux/quotaops.h +2 -0
@@ -99,6 +99,8 @@ int dquot_file_open(struct inode *inode, struct file *file);int dquot_enable (struct inode *inode,int type,int format_id,unsigned int flags); +int dquot_load_quota_sb (struct super_block *sb,int type,int format_id, +unsigned int flags);int dquot_quota_on (struct super_block *sb,int type,int format_id,const struct path *path); int dquot_quota_on_mount(struct super_block *sb, char *qf_name,
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 625/658 ext4: fix bug_on in __es_tree_search caused by bad quota inode
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
[ Upstream commit d323877484765aaacbb2769b06e355c2041ed115 ]
We got a issue as fllows:
==================================================================
kernel BUG at fs/ext4/extents_status.c:202!
invalid opcode: 0000 [#1] PREEMPT SMP
CPU: 1 PID: 810 Comm: mount Not tainted 6.1.0-rc1-next-g9631525255e3 #352 RIP: 0010:__es_tree_search.isra.0+0xb8/0xe0 RSP: 0018:ffffc90001227900 EFLAGS: 00010202 RAX: 0000000000000000 RBX: 0000000077512a0f RCX: 0000000000000000 RDX: 0000000000000002 RSI: 0000000000002a10 RDI: ffff8881004cd0c8 RBP: ffff888177512ac8 R08: 47ffffffffffffff R09: 0000000000000001 R10: 0000000000000001 R11: 00000000000679af R12: 0000000000002a10 R13: ffff888177512d88 R14: 0000000077512a10 R15: 0000000000000000 FS: 00007f4bd76dbc40(0000)GS:ffff88842fd00000(0000)knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00005653bf993cf8 CR3: 000000017bfdf000 CR4: 00000000000006e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: <TASK> ext4_es_cache_extent+0xe2/0x210 ext4_cache_extents+0xd2/0x110 ext4_find_extent+0x5d5/0x8c0 ext4_ext_map_blocks+0x9c/0x1d30 ext4_map_blocks+0x431/0xa50 ext4_getblk+0x82/0x340 ext4_bread+0x14/0x110 ext4_quota_read+0xf0/0x180 v2_read_header+0x24/0x90 v2_check_quota_file+0x2f/0xa0 dquot_load_quota_sb+0x26c/0x760 dquot_load_quota_inode+0xa5/0x190 ext4_enable_quotas+0x14c/0x300 __ext4_fill_super+0x31cc/0x32c0 ext4_fill_super+0x115/0x2d0 get_tree_bdev+0x1d2/0x360 ext4_get_tree+0x19/0x30 vfs_get_tree+0x26/0xe0 path_mount+0x81d/0xfc0 do_mount+0x8d/0xc0 __x64_sys_mount+0xc0/0x160 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x63/0xcd </TASK> ==================================================================
Above issue may happen as follows:
-------------------------------------ext4_fill_super
ext4_orphan_cleanup
ext4_enable_quotas
ext4_quota_enable
ext4_iget --> get error inode <5>
ext4_ext_check_inode --> Wrong imode makes it escape inspection
make_bad_inode(inode) --> EXT4_BOOT_LOADER_INO set imode
dquot_load_quota_inode
vfs_setup_quota_inode --> check pass
dquot_load_quota_sb
v2_check_quota_file
v2_read_header
ext4_quota_read
ext4_bread
ext4_getblk
ext4_map_blocks
ext4_ext_map_blocks
ext4_find_extent
ext4_cache_extents
ext4_es_cache_extent
__es_tree_search.isra.0
ext4_es_end --> Wrong extents trigger BUG_ONIn the above issue, s_usr_quota_inum is set to 5, but inode<5> contains incorrect imode and disordered extents. Because 5 is EXT4_BOOT_LOADER_INO, the ext4_ext_check_inode check in the ext4_iget function can be bypassed, finally, the extents that are not checked trigger the BUG_ON in the __es_tree_search function. To solve this issue, check whether the inode is bad_inode in vfs_setup_quota_inode().
--- fs/quota/dquot.c | 2 ++ 1 file changed, 2 insertions(+)
fs/quota/dquot.c +2 -0
@@ -2311,6 +2311,8 @@ static int vfs_setup_quota_inode(struct inode *inode, int type)struct super_block *sb = inode->i_sb;struct quota_info *dqopt =sb_dqopt (sb); +if (is_bad_inode (inode)) +return -EUCLEAN ;if (!S_ISREG (inode->i_mode))return -EACCES ;if (IS_RDONLY (inode))
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 626/658 ext4: lost matching-pair of trace in ext4_truncate
In reply to Greg Kroah-HartmanFrom: zhengliang <[email protected]>
[ Upstream commit 9a5d265fed014115f35e598022c956e5d2fb863e ]
It should call trace exit in all return path for ext4_truncate.
Stable-dep-of: a71248b1accb ("ext4: fix use-after-free in ext4_orphan_cleanup")
--- fs/ext4/inode.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
fs/ext4/inode.c +9 -8
@@ -4513,7 +4513,7 @@ int ext4_truncate(struct inode *inode)trace_ext4_truncate_enter (inode);if (!ext4_can_truncate (inode)) -return 0 ; + goto out_trace;ext4_clear_inode_flag (inode,EXT4_INODE_EOFBLOCKS );
@@ -4524,16 +4524,14 @@ int ext4_truncate(struct inode *inode)int has_inline =1 ; err =ext4_inline_data_truncate (inode, &has_inline); -if (err) -return err; -if (has_inline) -return 0 ; +if (err || has_inline) + goto out_trace; }/* If we zero-out tail of the page, we have to create jinode for jbd2 */ if (inode->i_size & (inode->i_sb->s_blocksize -1 )) {if (ext4_inode_attach_jinode (inode) <0 ) -return 0 ; + goto out_trace; }if (ext4_test_inode_flag (inode,EXT4_INODE_EXTENTS ))
@@ -4542,8 +4540,10 @@ int ext4_truncate(struct inode *inode) credits =ext4_blocks_for_truncate (inode); handle =ext4_journal_start (inode,EXT4_HT_TRUNCATE , credits); -if (IS_ERR (handle)) -return PTR_ERR (handle); +if (IS_ERR (handle)) { + err =PTR_ERR (handle); + goto out_trace; + }if (inode->i_size & (inode->i_sb->s_blocksize -1 ))ext4_block_truncate_page (handle, mapping, inode->i_size);
@@ -4592,6 +4592,7 @@ int ext4_truncate(struct inode *inode)ext4_mark_inode_dirty (handle, inode);ext4_journal_stop (handle); +out_trace:trace_ext4_truncate_exit (inode);return err; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 627/658 ext4: fix use-after-free in ext4_orphan_cleanup
In reply to Greg Kroah-HartmanFrom: Baokun Li <[email protected]>
[ Upstream commit a71248b1accb2b42e4980afef4fa4a27fa0e36f5 ]
I caught a issue as follows:
==================================================================
BUG: KASAN: use-after-free in __list_add_valid+0x28/0x1a0 Read of size 8 at addr ffff88814b13f378 by task mount/710 CPU: 1 PID: 710 Comm: mount Not tainted 6.1.0-rc3-next #370 Call Trace: <TASK> dump_stack_lvl+0x73/0x9f print_report+0x25d/0x759 kasan_report+0xc0/0x120 __asan_load8+0x99/0x140 __list_add_valid+0x28/0x1a0 ext4_orphan_cleanup+0x564/0x9d0 [ext4] __ext4_fill_super+0x48e2/0x5300 [ext4] ext4_fill_super+0x19f/0x3a0 [ext4] get_tree_bdev+0x27b/0x450 ext4_get_tree+0x19/0x30 [ext4] vfs_get_tree+0x49/0x150 path_mount+0xaae/0x1350 do_mount+0xe2/0x110 __x64_sys_mount+0xf0/0x190 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x63/0xcd </TASK> [...] ==================================================================
Above issue may happen as follows:
-------------------------------------ext4_fill_super
ext4_orphan_cleanup
--- loop1: assume last_orphan is 12 ---
list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan)
ext4_truncate --> return 0
ext4_inode_attach_jinode --> return -ENOMEM
iput(inode) --> free inode<12>
--- loop2: last_orphan is still 12 ---
list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan);
// use inode<12> and trigger UAFTo solve this issue, we need to propagate the return value of ext4_inode_attach_jinode() appropriately.
--- fs/ext4/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ext4/inode.c +2 -1
@@ -4530,7 +4530,8 @@ int ext4_truncate(struct inode *inode)/* If we zero-out tail of the page, we have to create jinode for jbd2 */ if (inode->i_size & (inode->i_sb->s_blocksize -1 )) { -if (ext4_inode_attach_jinode (inode) <0 ) + err =ext4_inode_attach_jinode (inode); +if (err) goto out_trace; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 628/658 ext4: fix uninititialized value in ext4_evict_inode
In reply to Greg Kroah-HartmanFrom: Ye Bin <[email protected]>
[ Upstream commit 7ea71af94eaaaf6d9aed24bc94a05b977a741cb9 ]
Syzbot found the following issue:
=====================================================
BUG: KMSAN: uninit-value in ext4_evict_inode+0xdd/0x26b0 fs/ext4/inode.c:180 ext4_evict_inode+0xdd/0x26b0 fs/ext4/inode.c:180 evict+0x365/0x9a0 fs/inode.c:664 iput_final fs/inode.c:1747 [inline] iput+0x985/0xdd0 fs/inode.c:1773 __ext4_new_inode+0xe54/0x7ec0 fs/ext4/ialloc.c:1361 ext4_mknod+0x376/0x840 fs/ext4/namei.c:2844 vfs_mknod+0x79d/0x830 fs/namei.c:3914 do_mknodat+0x47d/0xaa0 __do_sys_mknodat fs/namei.c:3992 [inline] __se_sys_mknodat fs/namei.c:3989 [inline] __ia32_sys_mknodat+0xeb/0x150 fs/namei.c:3989 do_syscall_32_irqs_on arch/x86/entry/common.c:112 [inline] __do_fast_syscall_32+0xa2/0x100 arch/x86/entry/common.c:178 do_fast_syscall_32+0x33/0x70 arch/x86/entry/common.c:203 do_SYSENTER_32+0x1b/0x20 arch/x86/entry/common.c:246 entry_SYSENTER_compat_after_hwframe+0x70/0x82
Uninit was created at:
__alloc_pages+0x9f1/0xe80 mm/page_alloc.c:5578 alloc_pages+0xaae/0xd80 mm/mempolicy.c:2285 alloc_slab_page mm/slub.c:1794 [inline] allocate_slab+0x1b5/0x1010 mm/slub.c:1939 new_slab mm/slub.c:1992 [inline] ___slab_alloc+0x10c3/0x2d60 mm/slub.c:3180 __slab_alloc mm/slub.c:3279 [inline] slab_alloc_node mm/slub.c:3364 [inline] slab_alloc mm/slub.c:3406 [inline] __kmem_cache_alloc_lru mm/slub.c:3413 [inline] kmem_cache_alloc_lru+0x6f3/0xb30 mm/slub.c:3429 alloc_inode_sb include/linux/fs.h:3117 [inline] ext4_alloc_inode+0x5f/0x860 fs/ext4/super.c:1321 alloc_inode+0x83/0x440 fs/inode.c:259 new_inode_pseudo fs/inode.c:1018 [inline] new_inode+0x3b/0x430 fs/inode.c:1046 __ext4_new_inode+0x2a7/0x7ec0 fs/ext4/ialloc.c:959 ext4_mkdir+0x4d5/0x1560 fs/ext4/namei.c:2992 vfs_mkdir+0x62a/0x870 fs/namei.c:4035 do_mkdirat+0x466/0x7b0 fs/namei.c:4060 __do_sys_mkdirat fs/namei.c:4075 [inline] __se_sys_mkdirat fs/namei.c:4073 [inline] __ia32_sys_mkdirat+0xc4/0x120 fs/namei.c:4073 do_syscall_32_irqs_on arch/x86/entry/common.c:112 [inline] __do_fast_syscall_32+0xa2/0x100 arch/x86/entry/common.c:178 do_fast_syscall_32+0x33/0x70 arch/x86/entry/common.c:203 do_SYSENTER_32+0x1b/0x20 arch/x86/entry/common.c:246 entry_SYSENTER_compat_after_hwframe+0x70/0x82 CPU: 1 PID: 4625 Comm: syz-executor.2 Not tainted 6.1.0-rc4-syzkaller-62821-gcb231e2f67ec #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022 =====================================================
Now, 'ext4_alloc_inode()' didn't init 'ei->i_flags'. If new inode failed before set 'ei->i_flags' in '__ext4_new_inode()', then do 'iput()'. As after 6bc0d63dad7f commit will access 'ei->i_flags' in 'ext4_evict_inode()' which will lead to access uninit-value.
To solve above issue just init 'ei->i_flags' in 'ext4_alloc_inode()'.
--- fs/ext4/super.c | 1 + 1 file changed, 1 insertion(+)
fs/ext4/super.c +1 -0
@@ -1085,6 +1085,7 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)return NULL ;inode_set_iversion (&ei->vfs_inode,1 ); + ei->i_flags =0 ;spin_lock_init (&ei->i_raw_lock);INIT_LIST_HEAD (&ei->i_prealloc_list);spin_lock_init (&ei->i_prealloc_lock);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 629/658 netfilter: ipset: Fix overflow before widen in the bitmap_ip_create() function.
In reply to Greg Kroah-HartmanFrom: Gavrilov Ilia <[email protected]>
commit 9ea4b476cea1b7d461d16dda25ca3c7e616e2d15 upstream.
When first_ip is 0, last_ip is 0xFFFFFFFF, and netmask is 31, the value of an arithmetic expression 2 << (netmask - mask_bits - 1) is subject to overflow due to a failure casting operands to a larger data type before performing the arithmetic.
Note that it's harmless since the value will be checked at the next step.
Found by InfoTeCS on behalf of Linux Verification Center (linuxtesting.org) with SVACE.
--- net/netfilter/ipset/ip_set_bitmap_ip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/ipset/ip_set_bitmap_ip.c +2 -2
@@ -296,8 +296,8 @@ bitmap_ip_create(struct net *net, structreturn -IPSET_ERR_BITMAP_RANGE ;pr_debug ("mask_bits %u, netmask %u\n" , mask_bits, netmask); - hosts =2 << (32 - netmask -1 ); - elements =2 << (netmask - mask_bits -1 ); + hosts =2U << (32 - netmask -1 ); + elements =2UL << (netmask - mask_bits -1 ); }if (elements >IPSET_BITMAP_MAX_RANGE +1 )return -IPSET_ERR_BITMAP_RANGE_SIZE ;
Greg Kroah-Hartman
maintainerPATCH 630/658 powerpc/imc-pmu: Fix use of mutex in IRQs disabled section
In reply to Greg Kroah-HartmanFrom: Kajol Jain <[email protected]>
commit 76d588dddc459fefa1da96e0a081a397c5c8e216 upstream.
Current imc-pmu code triggers a WARNING with CONFIG_DEBUG_ATOMIC_SLEEP and CONFIG_PROVE_LOCKING enabled, while running a thread_imc event.
Command to trigger the warning:
# perf stat -e thread_imc/CPM_CS_FROM_L4_MEM_X_DPTEG/ sleep 5
Performance counter stats for 'sleep 5':
0 thread_imc/CPM_CS_FROM_L4_MEM_X_DPTEG/
5.002117947 seconds time elapsed
0.000131000 seconds user
0.001063000 seconds sysBelow is snippet of the warning in dmesg:
BUG: sleeping function called from invalid context at kernel/locking/mutex.c:580
in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 2869, name: perf-exec
preempt_count: 2, expected: 0
4 locks held by perf-exec/2869:
#0: c00000004325c540 (&sig->cred_guard_mutex){+.+.}-{3:3}, at: bprm_execve+0x64/0xa90
#1: c00000004325c5d8 (&sig->exec_update_lock){++++}-{3:3}, at: begin_new_exec+0x460/0xef0
#2: c0000003fa99d4e0 (&cpuctx_lock){-...}-{2:2}, at: perf_event_exec+0x290/0x510
#3: c000000017ab8418 (&ctx->lock){....}-{2:2}, at: perf_event_exec+0x29c/0x510
irq event stamp: 4806
hardirqs last enabled at (4805): [<c000000000f65b94>] _raw_spin_unlock_irqrestore+0x94/0xd0
hardirqs last disabled at (4806): [<c0000000003fae44>] perf_event_exec+0x394/0x510
softirqs last enabled at (0): [<c00000000013c404>] copy_process+0xc34/0x1ff0
softirqs last disabled at (0): [<0000000000000000>] 0x0
CPU: 36 PID: 2869 Comm: perf-exec Not tainted 6.2.0-rc2-00011-g1247637727f2 #61
Hardware name: 8375-42A POWER9 0x4e1202 opal:v7.0-16-g9b85f7d961 PowerNV
Call Trace:
dump_stack_lvl+0x98/0xe0 (unreliable)
__might_resched+0x2f8/0x310
__mutex_lock+0x6c/0x13f0
thread_imc_event_add+0xf4/0x1b0
event_sched_in+0xe0/0x210
merge_sched_in+0x1f0/0x600
visit_groups_merge.isra.92.constprop.166+0x2bc/0x6c0
ctx_flexible_sched_in+0xcc/0x140
ctx_sched_in+0x20c/0x2a0
ctx_resched+0x104/0x1c0
perf_event_exec+0x340/0x510
begin_new_exec+0x730/0xef0
load_elf_binary+0x3f8/0x1e10
...
do not call blocking ops when !TASK_RUNNING; state=2001 set at [<00000000fd63e7cf>] do_nanosleep+0x60/0x1a0
WARNING: CPU: 36 PID: 2869 at kernel/sched/core.c:9912 __might_sleep+0x9c/0xb0
CPU: 36 PID: 2869 Comm: sleep Tainted: G W 6.2.0-rc2-00011-g1247637727f2 #61
Hardware name: 8375-42A POWER9 0x4e1202 opal:v7.0-16-g9b85f7d961 PowerNV
NIP: c000000000194a1c LR: c000000000194a18 CTR: c000000000a78670
REGS: c00000004d2134e0 TRAP: 0700 Tainted: G W (6.2.0-rc2-00011-g1247637727f2)
MSR: 9000000000021033 <SF,HV,ME,IR,DR,RI,LE> CR: 48002824 XER: 00000000
CFAR: c00000000013fb64 IRQMASK: 1The above warning triggered because the current imc-pmu code uses mutex lock in interrupt disabled sections. The function mutex_lock() internally calls __might_resched(), which will check if IRQs are disabled and in case IRQs are disabled, it will trigger the warning.
Fix the issue by changing the mutex lock to spinlock.
--- arch/powerpc/include/asm/imc-pmu.h | 2 arch/powerpc/perf/imc-pmu.c | 136 +++++++++++++++++-------------------- 2 files changed, 67 insertions(+), 71 deletions(-)
arch/powerpc/include/asm/imc-pmu.h +1 -1
@@ -132,7 +132,7 @@ struct imc_pmu {* are inited. */ struct imc_pmu_ref { -struct mutex lock; +spinlock_t lock;unsigned int id;int refc; };
arch/powerpc/perf/imc-pmu.c +66 -70
474 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 631/658 x86/boot: Avoid using Intel mnemonics in AT&T syntax asm
In reply to Greg Kroah-HartmanFrom: Peter Zijlstra <[email protected]>
commit 7c6dd961d0c8e7e8f9fdc65071fb09ece702e18d upstream.
With 'GNU assembler (GNU Binutils for Debian) 2.39.90.20221231' the build now reports:
arch/x86/realmode/rm/../../boot/bioscall.S: Assembler messages:
arch/x86/realmode/rm/../../boot/bioscall.S:35: Warning: found movsd'; assuming movsl' was meant arch/x86/realmode/rm/../../boot/bioscall.S:70: Warning: found movsd'; assuming movsl' was meant
arch/x86/boot/bioscall.S: Assembler messages:
arch/x86/boot/bioscall.S:35: Warning: found movsd'; assuming movsl' was meant arch/x86/boot/bioscall.S:70: Warning: found movsd'; assuming movsl' was meant
Which is due to:
PR gas/29525
Note that with the dropped CMPSD and MOVSD Intel Syntax string insn templates taking operands, mixed IsString/non-IsString template groups (with memory operands) cannot occur anymore. With that maybe_adjust_templates() becomes unnecessary (and is hence being removed).
More details: https://sourceware.org/bugzilla/show_bug.cgi?id=29525
Borislav Petkov further explains:
" the particular problem here is is that the 'd' suffix is
"conflicting" in the sense that you can have SSE mnemonics like movsD %xmm... and the same thing also for string ops (which is the case here) so apparently the agreement in binutils land is to use the always accepted suffixes 'l' or 'q' and phase out 'd' slowly... "
--- arch/x86/boot/bioscall.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/boot/bioscall.S +2 -2
@@ -32,7 +32,7 @@ intcall: movw %dx, %si movw %sp, %di movw $11, %cx - rep; movsd + rep; movsl /* Pop full state from the stack */ popal
@@ -67,7 +67,7 @@ intcall: jz 4f movw %sp, %si movw $11, %cx - rep; movsd + rep; movsl 4: addw $44, %sp /* Restore state and return */
Greg Kroah-Hartman
maintainerPATCH 632/658 EDAC/device: Fix period calculation in edac_device_reset_delay_period()
In reply to Greg Kroah-HartmanFrom: Eliav Farber <[email protected]>
commit e84077437902ec99eba0a6b516df772653f142c7 upstream.
Fix period calculation in case user sets a value of 1000. The input of round_jiffies_relative() should be in jiffies and not in milli-seconds.
[ bp: Use the same code pattern as in edac_device_workq_setup() for
clarity. ]
--- drivers/edac/edac_device.c | 17 ++++++++--------- drivers/edac/edac_module.h | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-)
drivers/edac/edac_device.c +8 -9
@@ -424,17 +424,16 @@ static void edac_device_workq_teardown(s* Then restart the workq on the new delay */ void edac_device_reset_delay_period (struct edac_device_ctl_info *edac_dev, -unsigned long value) +unsigned long msec) { -unsigned long jiffs =msecs_to_jiffies (value); + edac_dev->poll_msec = msec; + edac_dev->delay =msecs_to_jiffies (msec); -if (value ==1000 ) - jiffs =round_jiffies_relative (value); - - edac_dev->poll_msec = value; - edac_dev->delay = jiffs; - -edac_mod_work (&edac_dev->work, jiffs); +/* See comment in edac_device_workq_setup() above */ +if (edac_dev->poll_msec ==1000 ) +edac_mod_work (&edac_dev->work,round_jiffies_relative (edac_dev->delay)); +else +edac_mod_work (&edac_dev->work, edac_dev->delay); }int edac_device_alloc_index (void )
drivers/edac/edac_module.h +1 -1
@@ -57,7 +57,7 @@ bool edac_stop_work(struct delayed_workbool edac_mod_work (struct delayed_work *work,unsigned long delay);extern void edac_device_reset_delay_period (struct edac_device_ctl_info - *edac_dev,unsigned long value); + *edac_dev,unsigned long msec);extern void edac_mc_reset_delay_period (unsigned long value);extern void *edac_align_ptr (void **p,unsigned size,int n_elems);
Greg Kroah-Hartman
maintainerPATCH 633/658 regulator: da9211: Use irq handler when ready
In reply to Greg Kroah-HartmanFrom: Ricardo Ribalda <[email protected]>
[ Upstream commit 02228f6aa6a64d588bc31e3267d05ff184d772eb ]
If the system does not come from reset (like when it is kexec()), the regulator might have an IRQ waiting for us.
If we enable the IRQ handler before its structures are ready, we crash.
This patch fixes:
[ 1.141839] Unable to handle kernel read from unreadable memory at virtual address 0000000000000078 [ 1.316096] Call trace: [ 1.316101] blocking_notifier_call_chain+0x20/0xa8 [ 1.322757] cpu cpu0: dummy supplies not allowed for exclusive requests [ 1.327823] regulator_notifier_call_chain+0x1c/0x2c [ 1.327825] da9211_irq_handler+0x68/0xf8 [ 1.327829] irq_thread+0x11c/0x234 [ 1.327833] kthread+0x13c/0x154
--- drivers/regulator/da9211-regulator.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/regulator/da9211-regulator.c +6 -5
@@ -471,6 +471,12 @@ static int da9211_i2c_probe(struct i2c_client *i2c, chip->chip_irq = i2c->irq; + ret =da9211_regulator_init (chip); +if (ret <0 ) { +dev_err (chip->dev,"Failed to initialize regulator: %d\n" , ret); +return ret; + } +if (chip->chip_irq !=0 ) { ret = devm_request_threaded_irq(chip->dev, chip->chip_irq, NULL, da9211_irq_handler,
@@ -485,11 +491,6 @@ static int da9211_i2c_probe(struct i2c_client *i2c,dev_warn (chip->dev,"No IRQ configured\n" ); } - ret =da9211_regulator_init (chip); - -if (ret <0 ) -dev_err (chip->dev,"Failed to initialize regulator: %d\n" , ret); -return ret; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 634/658 tipc: improve throughput between nodes in netns
In reply to Greg Kroah-HartmanFrom: Hoang Le <[email protected]>
[ Upstream commit f73b12812a3d1d798b7517547ccdcf864844d2cd ]
Currently, TIPC transports intra-node user data messages directly socket to socket, hence shortcutting all the lower layers of the communication stack. This gives TIPC very good intra node performance, both regarding throughput and latency.
We now introduce a similar mechanism for TIPC data traffic across network namespaces located in the same kernel. On the send path, the call chain is as always accompanied by the sending node's network name space pointer. However, once we have reliably established that the receiving node is represented by a namespace on the same host, we just replace the namespace pointer with the receiving node/namespace's ditto, and follow the regular socket receive patch though the receiving node. This technique gives us a throughput similar to the node internal throughput, several times larger than if we let the traffic go though the full network stacks. As a comparison, max throughput for 64k messages is four times larger than TCP throughput for the same type of traffic.
To meet any security concerns, the following should be noted.
- All nodes joining a cluster are supposed to have been be certified and authenticated by mechanisms outside TIPC. This is no different for nodes/namespaces on the same host; they have to auto discover each other using the attached interfaces, and establish links which are supervised via the regular link monitoring mechanism. Hence, a kernel local node has no other way to join a cluster than any other node, and have to obey to policies set in the IP or device layers of the stack.
- Only when a sender has established with 100% certainty that the peer node is located in a kernel local namespace does it choose to let user data messages, and only those, take the crossover path to the receiving node/namespace.
- If the receiving node/namespace is removed, its namespace pointer is invalidated at all peer nodes, and their neighbor link monitoring will eventually note that this node is gone.
- To ensure the "100% certainty" criteria, and prevent any possible spoofing, received discovery messages must contain a proof that the sender knows a common secret. We use the hash mix of the sending node/namespace for this purpose, since it can be accessed directly by all other namespaces in the kernel. Upon reception of a discovery message, the receiver checks this proof against all the local namespaces'hash_mix:es. If it finds a match, that, along with a matching node id and cluster id, this is deemed sufficient proof that the peer node in question is in a local namespace, and a wormhole can be opened.
- We should also consider that TIPC is intended to be a cluster local IPC mechanism (just like e.g. UNIX sockets) rather than a network protocol, and hence we think it can justified to allow it to shortcut the lower protocol layers.
Regarding traceability, we should notice that since commit 6c9081a3915d ("tipc: add loopback device tracking") it is possible to follow the node internal packet flow by just activating tcpdump on the loopback interface. This will be true even for this mechanism; by activating tcpdump on the involved nodes' loopback interfaces their inter-name space messaging can easily be tracked.
v2:
- update 'net' pointer when node left/rejoined
v3:
- grab read/write lock when using node ref obj
v4:
- clone traffics between netns to loopback
Stable-dep-of: c244c092f1ed ("tipc: fix unexpected link reset due to discovery messages")
--- net/tipc/core.c | 16 +++++ net/tipc/core.h | 6 ++ net/tipc/discover.c | 4 +- net/tipc/msg.h | 14 ++++ net/tipc/name_distr.c | 2 +- net/tipc/node.c | 155 ++++++++++++++++++++++++++++++++++++++++-- net/tipc/node.h | 5 +- net/tipc/socket.c | 6 +- 8 files changed, 197 insertions(+), 11 deletions(-)
net/tipc/core.c +16 -0
@@ -112,6 +112,15 @@ static void __net_exit tipc_exit_net(struct net *net)cond_resched (); } +static void __net_exit tipc_pernet_pre_exit(struct net *net) +{ +tipc_node_pre_cleanup_net (net); +} + +static struct pernet_operations tipc_pernet_pre_exit_ops = { + .pre_exit = tipc_pernet_pre_exit, +}; +static struct pernet_operations tipc_net_ops = { .init = tipc_init_net, .exit = tipc_exit_net,
@@ -150,6 +159,10 @@ static int __init tipc_init(void)if (err) goto out_pernet_topsrv; + err =register_pernet_subsys (&tipc_pernet_pre_exit_ops); +if (err) + goto out_register_pernet_subsys; + err =tipc_bearer_setup ();if (err) goto out_bearer;
@@ -170,6 +183,8 @@ static int __init tipc_init(void) out_netlink:tipc_bearer_cleanup (); out_bearer: +unregister_pernet_subsys (&tipc_pernet_pre_exit_ops); +out_register_pernet_subsys:unregister_pernet_device (&tipc_topsrv_net_ops); out_pernet_topsrv:tipc_socket_stop ();
@@ -187,6 +202,7 @@ static void __exit tipc_exit(void)tipc_netlink_compat_stop ();tipc_netlink_stop ();tipc_bearer_cleanup (); +unregister_pernet_subsys (&tipc_pernet_pre_exit_ops);unregister_pernet_device (&tipc_topsrv_net_ops);tipc_socket_stop ();unregister_pernet_device (&tipc_net_ops);
net/tipc/core.h +6 -0
@@ -59,6 +59,7 @@#include <net/netns/generic.h> #include <linux/rhashtable.h> #include <net/genetlink.h> +#include <net/netns/hash.h> #ifdef pr_fmt#undef pr_fmt
@@ -202,6 +203,11 @@ static inline int in_range(u16 val, u16 min, u16 max)return !less (val, min) && !more (val, max); } +static inline u32 tipc_net_hash_mixes (struct net *net,int tn_rand) +{ +return net_hash_mix (&init_net) ^net_hash_mix (net) ^ tn_rand; +} +#ifdef CONFIG_SYSCTL int tipc_register_sysctl (void );void tipc_unregister_sysctl (void );
net/tipc/discover.c +3 -1
@@ -94,6 +94,7 @@ static void tipc_disc_init_msg(struct net *net, struct sk_buff *skb,msg_set_dest_domain (hdr, dest_domain);msg_set_bc_netid (hdr, tn->net_id); b->media->addr2msg (msg_media_addr (hdr), &b->addr); +msg_set_peer_net_hash (hdr,tipc_net_hash_mixes (net, tn->random));msg_set_node_id (hdr,tipc_own_id (net)); }
@@ -245,7 +246,8 @@ void tipc_disc_rcv(struct net *net, struct sk_buff *skb,if (!tipc_in_scope (legacy, b->domain, src))return ;tipc_node_check_dest (net, src, peer_id, b, caps, signature, - &maddr, &respond, &dupl_addr); +msg_peer_net_hash (hdr), &maddr, &respond, + &dupl_addr);if (dupl_addr)disc_dupl_alert (b, src, &maddr);if (!respond)
net/tipc/msg.h +14 -0
@@ -1026,6 +1026,20 @@ static inline bool msg_is_reset(struct tipc_msg *hdr)return (msg_user (hdr) ==LINK_PROTOCOL ) && (msg_type (hdr) ==RESET_MSG ); } +/* Word 13 +*/ +static inline void msg_set_peer_net_hash (struct tipc_msg *m,u32 n) +{ +msg_set_word (m,13 , n); +} + +static inline u32 msg_peer_net_hash (struct tipc_msg *m) +{ +return msg_word (m,13 ); +} + +/* Word 14 +*/ static inline u32 msg_sugg_node_addr (struct tipc_msg *m) {return msg_word (m,14 );
net/tipc/name_distr.c +1 -1
@@ -146,7 +146,7 @@ static void named_distribute(struct net *net, struct sk_buff_head *list,struct publication *publ;struct sk_buff *skb =NULL ;struct distr_item *item =NULL ; -u32 msg_dsz = ((tipc_node_get_mtu (net, dnode,0 ) -INT_H_SIZE ) / +u32 msg_dsz = ((tipc_node_get_mtu (net, dnode,0 , false) -INT_H_SIZE ) /ITEM_SIZE ) *ITEM_SIZE ;u32 msg_rem = msg_dsz;
net/tipc/node.c +151 -4
243 lines not on this page · raw message
net/tipc/node.h +3 -2
@@ -75,7 +75,7 @@ u32 tipc_node_get_addr(struct tipc_node *node);u32 tipc_node_try_addr (struct net *net,u8 *id,u32 addr);void tipc_node_check_dest (struct net *net,u32 onode,u8 *peer_id128,struct tipc_bearer *bearer, -u16 capabilities,u32 signature, +u16 capabilities,u32 signature,u32 hash_mixes,struct tipc_media_addr *maddr,bool *respond,bool *dupl_addr);void tipc_node_delete_links (struct net *net,int bearer_id);
@@ -92,7 +92,7 @@ void tipc_node_unsubscribe(struct net *net, struct list_head *subscr, u32 addr);void tipc_node_broadcast (struct net *net,struct sk_buff *skb);int tipc_node_add_conn (struct net *net,u32 dnode,u32 port,u32 peer_port);void tipc_node_remove_conn (struct net *net,u32 dnode,u32 port); -int tipc_node_get_mtu (struct net *net,u32 addr,u32 sel); +int tipc_node_get_mtu (struct net *net,u32 addr,u32 sel,bool connected);bool tipc_node_is_up (struct net *net,u32 addr);u16 tipc_node_get_capabilities (struct net *net,u32 addr);int tipc_nl_node_dump (struct sk_buff *skb,struct netlink_callback *cb);
@@ -107,4 +107,5 @@ int tipc_nl_node_get_monitor(struct sk_buff *skb, struct genl_info *info);int tipc_nl_node_dump_monitor (struct sk_buff *skb,struct netlink_callback *cb);int tipc_nl_node_dump_monitor_peer (struct sk_buff *skb,struct netlink_callback *cb); +void tipc_node_pre_cleanup_net (struct net *exit_net);#endif
net/tipc/socket.c +3 -3
@@ -866,7 +866,7 @@ static int tipc_send_group_msg(struct net *net, struct tipc_sock *tsk,/* Build message as chain of buffers */ __skb_queue_head_init (&pkts); - mtu =tipc_node_get_mtu (net, dnode, tsk->portid); + mtu =tipc_node_get_mtu (net, dnode, tsk->portid, false); rc =tipc_msg_build (hdr, m,0 , dlen, mtu, &pkts);if (unlikely (rc != dlen))return rc;
@@ -1407,7 +1407,7 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen) }__skb_queue_head_init (&pkts); - mtu =tipc_node_get_mtu (net, dnode, tsk->portid); + mtu =tipc_node_get_mtu (net, dnode, tsk->portid, false); rc =tipc_msg_build (hdr, m,0 , dlen, mtu, &pkts);if (unlikely (rc != dlen))return rc;
@@ -1547,7 +1547,7 @@ static void tipc_sk_finish_conn(struct tipc_sock *tsk, u32 peer_port,sk_reset_timer (sk, &sk->sk_timer, jiffies +CONN_PROBING_INTV );tipc_set_sk_state (sk,TIPC_ESTABLISHED );tipc_node_add_conn (net, peer_node, tsk->portid, peer_port); - tsk->max_pkt =tipc_node_get_mtu (net, peer_node, tsk->portid); + tsk->max_pkt =tipc_node_get_mtu (net, peer_node, tsk->portid, true); tsk->peer_caps =tipc_node_get_capabilities (net, peer_node);__skb_queue_purge (&sk->sk_write_queue);if (tsk->peer_caps &TIPC_BLOCK_FLOWCTL )
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 635/658 tipc: eliminate checking netns if node established
In reply to Greg Kroah-HartmanFrom: Hoang Le <[email protected]>
[ Upstream commit d408bef4bfa60bac665b6e7239269570039a968b ]
Currently, we scan over all network namespaces at each received discovery message in order to check if the sending peer might be present in a host local namespaces.
This is unnecessary since we can assume that a peer will not change its location during an established session.
We now improve the condition for this testing so that we don't perform any redundant scans.
Stable-dep-of: c244c092f1ed ("tipc: fix unexpected link reset due to discovery messages")
--- net/tipc/node.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
net/tipc/node.c +5 -9
@@ -472,10 +472,6 @@ static struct tipc_node *tipc_node_create(struct net *net, u32 addr, tipc_bc_sndlink(net), &n->bc_entry.link)) {pr_warn ("Broadcast rcv link creation failed, no memory\n" ); -if (n->peer_net) { - n->peer_net =NULL ; - n->peer_hash_mix =0 ; - }kfree (n); n =NULL ; goto exit;
@@ -1068,6 +1064,9 @@ void tipc_node_check_dest(struct net *net, u32 addr,if (sign_match && addr_match && link_up) {/* All is fine. Do nothing. */ reset = false; +/* Peer node is not a container/local namespace */ +if (!n->peer_hash_mix) + n->peer_hash_mix = hash_mixes; }else if (sign_match && addr_match && !link_up) {/* Respond. The link will come up in due time */ *respond = true;
@@ -1393,11 +1392,8 @@ static void node_lost_contact(struct tipc_node *n,/* Notify publications from this node */ n->action_flags |=TIPC_NOTIFY_NODE_DOWN ; - -if (n->peer_net) { - n->peer_net =NULL ; - n->peer_hash_mix =0 ; - } + n->peer_net =NULL ; + n->peer_hash_mix =0 ;/* Notify sockets connected to node */ list_for_each_entry_safe (conn, safe, conns, list) { skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG,
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 636/658 tipc: fix unexpected link reset due to discovery messages
In reply to Greg Kroah-HartmanFrom: Tung Nguyen <[email protected]>
[ Upstream commit c244c092f1ed2acfb5af3d3da81e22367d3dd733 ]
This unexpected behavior is observed:
node 1 | node 2
------ | ------
link is established | link is established
reboot | link is reset
up | send discovery message
receive discovery message |
link is established | link is established
send discovery message |
| receive discovery message
| link is reset (unexpected)
| send reset message
link is reset |It is due to delayed re-discovery as described in function tipc_node_check_dest(): "this link endpoint has already reset and re-established contact with the peer, before receiving a discovery message from that node."
However, commit 598411d70f85 has changed the condition for calling tipc_node_link_down() which was the acceptance of new media address.
This commit fixes this by restoring the old and correct behavior.
--- net/tipc/node.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
net/tipc/node.c +8 -4
@@ -1035,8 +1035,9 @@ void tipc_node_check_dest(struct net *net, u32 addr,bool addr_match = false;bool sign_match = false;bool link_up = false; +bool link_is_reset = false;bool accept_addr = false; -bool reset = true; +bool reset = false;char *if_name;unsigned long intv;u16 session;
@@ -1056,14 +1057,14 @@ void tipc_node_check_dest(struct net *net, u32 addr,/* Prepare to validate requesting node's signature and media address */ l = le->link; link_up = l &&tipc_link_is_up (l); + link_is_reset = l &&tipc_link_is_reset (l); addr_match = l && !memcmp (&le->maddr, maddr,sizeof (*maddr)); sign_match = (signature == n->signature);/* These three flags give us eight permutations: */ if (sign_match && addr_match && link_up) { -/* All is fine. Do nothing. */ - reset = false; +/* All is fine. Ignore requests. */ /* Peer node is not a container/local namespace */ if (!n->peer_hash_mix) n->peer_hash_mix = hash_mixes;
@@ -1088,6 +1089,7 @@ void tipc_node_check_dest(struct net *net, u32 addr,*/ accept_addr = true; *respond = true; + reset = true; }else if (!sign_match && addr_match && link_up) {/* Peer node rebooted. Two possibilities: * - Delayed re-discovery; this link endpoint has already
@@ -1119,6 +1121,7 @@ void tipc_node_check_dest(struct net *net, u32 addr, n->signature = signature; accept_addr = true; *respond = true; + reset = true; }if (!accept_addr)
@@ -1147,6 +1150,7 @@ void tipc_node_check_dest(struct net *net, u32 addr,tipc_link_fsm_evt (l,LINK_RESET_EVT );if (n->state ==NODE_FAILINGOVER )tipc_link_fsm_evt (l,LINK_FAILOVER_BEGIN_EVT ); + link_is_reset =tipc_link_is_reset (l); le->link = l; n->link_cnt++;tipc_node_calculate_timer (n, l);
@@ -1159,7 +1163,7 @@ void tipc_node_check_dest(struct net *net, u32 addr,memcpy (&le->maddr, maddr,sizeof (*maddr)); exit:tipc_node_write_unlock (n); -if (reset && l && !tipc_link_is_reset (l)) +if (reset && !link_is_reset)tipc_node_link_down (n, b->identity, false);tipc_node_put (n); }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 637/658 hvc/xen: lock console list traversal
In reply to Greg Kroah-HartmanFrom: Roger Pau Monne <[email protected]>
[ Upstream commit c0dccad87cf68fc6012aec7567e354353097ec1a ]
The currently lockless access to the xen console list in vtermno_to_xencons() is incorrect, as additions and removals from the list can happen anytime, and as such the traversal of the list to get the private console data for a given termno needs to happen with the lock held. Note users that modify the list already do so with the lock taken.
Adjust current lock takers to use the _irq{save,restore} helpers, since the context in which vtermno_to_xencons() is called can have interrupts disabled. Use the _irq{save,restore} set of helpers to switch the current callers to disable interrupts in the locked region. I haven't checked if existing users could instead use the _irq variant, as I think it's safer to use _irq{save,restore} upfront.
While there switch from using list_for_each_entry_safe tolist_for_each_entry: the current entry cursor won't be removed as part of the code in the loop body, so using the _safe variant is pointless.
--- drivers/tty/hvc/hvc_xen.c | 46 ++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 17 deletions(-)
drivers/tty/hvc/hvc_xen.c +29 -17
@@ -52,17 +52,22 @@ static DEFINE_SPINLOCK(xencons_lock);static struct xencons_info *vtermno_to_xencons (int vtermno) { -struct xencons_info *entry, *n, *ret =NULL ; +struct xencons_info *entry, *ret =NULL ; +unsigned long flags; -if (list_empty (&xenconsoles)) -return NULL ; +spin_lock_irqsave (&xencons_lock, flags); +if (list_empty (&xenconsoles)) { +spin_unlock_irqrestore (&xencons_lock, flags); +return NULL ; + } -list_for_each_entry_safe (entry, n, &xenconsoles, list) { +list_for_each_entry (entry, &xenconsoles, list) {if (entry->vtermno == vtermno) { ret = entry;break ; } } +spin_unlock_irqrestore (&xencons_lock, flags);return ret; }
@@ -223,7 +228,7 @@ static int xen_hvm_console_init(void) {int r;uint64_t v =0 ; -unsigned long gfn; +unsigned long gfn, flags;struct xencons_info *info;if (!xen_hvm_domain ())
@@ -258,9 +263,9 @@ static int xen_hvm_console_init(void) goto err; info->vtermno =HVC_COOKIE ; -spin_lock (&xencons_lock); +spin_lock_irqsave (&xencons_lock, flags);list_add_tail (&info->list, &xenconsoles); -spin_unlock (&xencons_lock); +spin_unlock_irqrestore (&xencons_lock, flags);return 0 ; err:
@@ -283,6 +288,7 @@ static int xencons_info_pv_init(struct xencons_info *info, int vtermno)static int xen_pv_console_init (void ) {struct xencons_info *info; +unsigned long flags;if (!xen_pv_domain ())return -ENODEV ;
@@ -299,9 +305,9 @@ static int xen_pv_console_init(void)/* already configured */ return 0 ; } -spin_lock (&xencons_lock); +spin_lock_irqsave (&xencons_lock, flags);xencons_info_pv_init (info,HVC_COOKIE ); -spin_unlock (&xencons_lock); +spin_unlock_irqrestore (&xencons_lock, flags);return 0 ; }
@@ -309,6 +315,7 @@ static int xen_pv_console_init(void)static int xen_initial_domain_console_init (void ) {struct xencons_info *info; +unsigned long flags;if (!xen_initial_domain ())return -ENODEV ;
@@ -323,9 +330,9 @@ static int xen_initial_domain_console_init(void) info->irq =bind_virq_to_irq (VIRQ_CONSOLE ,0 , false); info->vtermno =HVC_COOKIE ; -spin_lock (&xencons_lock); +spin_lock_irqsave (&xencons_lock, flags);list_add_tail (&info->list, &xenconsoles); -spin_unlock (&xencons_lock); +spin_unlock_irqrestore (&xencons_lock, flags);return 0 ; }
@@ -380,10 +387,12 @@ static void xencons_free(struct xencons_info *info)static int xen_console_remove (struct xencons_info *info) { +unsigned long flags; +xencons_disconnect_backend (info); -spin_lock (&xencons_lock); +spin_lock_irqsave (&xencons_lock, flags);list_del (&info->list); -spin_unlock (&xencons_lock); +spin_unlock_irqrestore (&xencons_lock, flags);if (info->xbdev !=NULL )xencons_free (info);else {
@@ -464,6 +473,7 @@ static int xencons_probe(struct xenbus_device *dev, {int ret, devid;struct xencons_info *info; +unsigned long flags; devid = dev->nodename[strlen (dev->nodename) -1 ] -'0' ;if (devid ==0 )
@@ -482,9 +492,9 @@ static int xencons_probe(struct xenbus_device *dev, ret =xencons_connect_backend (dev, info);if (ret <0 ) goto error; -spin_lock (&xencons_lock); +spin_lock_irqsave (&xencons_lock, flags);list_add_tail (&info->list, &xenconsoles); -spin_unlock (&xencons_lock); +spin_unlock_irqrestore (&xencons_lock, flags);return 0 ;
@@ -583,10 +593,12 @@ static int __init xen_hvc_init(void) info->hvc =hvc_alloc (HVC_COOKIE , info->irq, ops,256 );if (IS_ERR (info->hvc)) { +unsigned long flags; + r =PTR_ERR (info->hvc); -spin_lock (&xencons_lock); +spin_lock_irqsave (&xencons_lock, flags);list_del (&info->list); -spin_unlock (&xencons_lock); +spin_unlock_irqrestore (&xencons_lock, flags);if (info->irq)unbind_from_irqhandler (info->irq,NULL );kfree (info);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 638/658 nfc: pn533: Wait for out_urbs completion in pn533_usb_send_frame()
In reply to Greg Kroah-HartmanFrom: Minsuk Kang <[email protected]>
[ Upstream commit 9dab880d675b9d0dd56c6428e4e8352a3339371d ]
Fix a use-after-free that occurs in hcd when in_urb sent from pn533_usb_send_frame() is completed earlier than out_urb. Its callback frees the skb data in pn533_send_async_complete() that is used as a transfer buffer of out_urb. Wait before sending in_urb until the callback of out_urb is called. To modify the callback of out_urb alone, separate the complete function of out_urb and ack_urb.
Found by a modified version of syzkaller.
BUG: KASAN: use-after-free in dummy_timer Call Trace: memcpy (mm/kasan/shadow.c:65) dummy_perform_transfer (drivers/usb/gadget/udc/dummy_hcd.c:1352) transfer (drivers/usb/gadget/udc/dummy_hcd.c:1453) dummy_timer (drivers/usb/gadget/udc/dummy_hcd.c:1972) arch_static_branch (arch/x86/include/asm/jump_label.h:27) static_key_false (include/linux/jump_label.h:207) timer_expire_exit (include/trace/events/timer.h:127) call_timer_fn (kernel/time/timer.c:1475) expire_timers (kernel/time/timer.c:1519) __run_timers (kernel/time/timer.c:1790) run_timer_softirq (kernel/time/timer.c:1803)
--- drivers/nfc/pn533/usb.c | 44 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-)
drivers/nfc/pn533/usb.c +41 -3
@@ -153,10 +153,17 @@ static int pn533_usb_send_ack(struct pn533 *dev, gfp_t flags)return usb_submit_urb (phy->ack_urb, flags); } +struct pn533_out_arg { +struct pn533_usb_phy *phy; +struct completion done; +}; +static int pn533_usb_send_frame (struct pn533 *dev,struct sk_buff *out) {struct pn533_usb_phy *phy = dev->phy; +struct pn533_out_arg arg; +void *cntx;int rc;if (phy->priv ==NULL )
@@ -168,10 +175,17 @@ static int pn533_usb_send_frame(struct pn533 *dev,print_hex_dump_debug ("PN533 TX: " ,DUMP_PREFIX_NONE ,16 ,1 , out->data, out->len, false); +init_completion (&arg.done); + cntx = phy->out_urb->context; + phy->out_urb->context = &arg; + rc =usb_submit_urb (phy->out_urb,GFP_KERNEL );if (rc)return rc; +wait_for_completion (&arg.done); + phy->out_urb->context = cntx; +if (dev->protocol_type ==PN533_PROTO_REQ_RESP ) {/* request for response for sent packet directly */ rc =pn533_submit_urb_for_response (phy,GFP_KERNEL );
@@ -412,7 +426,31 @@ static int pn533_acr122_poweron_rdr(struct pn533_usb_phy *phy)return arg.rc; } -static void pn533_send_complete (struct urb *urb) +static void pn533_out_complete (struct urb *urb) +{ +struct pn533_out_arg *arg = urb->context; +struct pn533_usb_phy *phy = arg->phy; + +switch (urb->status) { +case 0 : +break ;/* success */ +case -ECONNRESET : +case -ENOENT : +dev_dbg (&phy->udev->dev, +"The urb has been stopped (status %d)\n" , + urb->status); +break ; +case -ESHUTDOWN : +default : +nfc_err (&phy->udev->dev, +"Urb failure (status %d)\n" , + urb->status); + } + +complete (&arg->done); +} + +static void pn533_ack_complete (struct urb *urb) {struct pn533_usb_phy *phy = urb->context;
@@ -500,10 +538,10 @@ static int pn533_usb_probe(struct usb_interface *interface,usb_fill_bulk_urb (phy->out_urb, phy->udev,usb_sndbulkpipe (phy->udev, out_endpoint), -NULL ,0 , pn533_send_complete, phy); +NULL ,0 , pn533_out_complete, phy);usb_fill_bulk_urb (phy->ack_urb, phy->udev,usb_sndbulkpipe (phy->udev, out_endpoint), -NULL ,0 , pn533_send_complete, phy); +NULL ,0 , pn533_ack_complete, phy);switch (id->driver_info) {case PN533_DEVICE_STD :
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 639/658 net/sched: act_mpls: Fix warning during failed attribute validation
In reply to Greg Kroah-HartmanFrom: Ido Schimmel <[email protected]>
[ Upstream commit 9e17f99220d111ea031b44153fdfe364b0024ff2 ]
The 'TCA_MPLS_LABEL' attribute is of 'NLA_U32' type, but has a validation type of 'NLA_VALIDATE_FUNCTION'. This is an invalid combination according to the comment above 'struct nla_policy':
"
Meaning of `validate' field, use via NLA_POLICY_VALIDATE_FN:
NLA_BINARY Validation function called for the attribute.
All other Unused - but note that it's a union
"
This can trigger the warning [1] in nla_get_range_unsigned() when validation of the attribute fails. Despite being of 'NLA_U32' type, the associated 'min'/'max' fields in the policy are negative as they are aliased by the 'validate' field.
Fix by changing the attribute type to 'NLA_BINARY' which is consistent with the above comment and all other users of NLA_POLICY_VALIDATE_FN(). As a result, move the length validation to the validation function.
No regressions in MPLS tests:
# ./tdc.py -f tc-tests/actions/mpls.json [...] # echo $? 0
[1]
WARNING: CPU: 0 PID: 17743 at lib/nlattr.c:118 nla_get_range_unsigned+0x1d8/0x1e0 lib/nlattr.c:117 Modules linked in: CPU: 0 PID: 17743 Comm: syz-executor.0 Not tainted 6.1.0-rc8 #3 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.13.0-48-gd9c812dda519-prebuilt.qemu.org 04/01/2014 RIP: 0010:nla_get_range_unsigned+0x1d8/0x1e0 lib/nlattr.c:117 [...] Call Trace: <TASK> __netlink_policy_dump_write_attr+0x23d/0x990 net/netlink/policy.c:310 netlink_policy_dump_write_attr+0x22/0x30 net/netlink/policy.c:411 netlink_ack_tlv_fill net/netlink/af_netlink.c:2454 [inline] netlink_ack+0x546/0x760 net/netlink/af_netlink.c:2506 netlink_rcv_skb+0x1b7/0x240 net/netlink/af_netlink.c:2546 rtnetlink_rcv+0x18/0x20 net/core/rtnetlink.c:6109 netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline] netlink_unicast+0x5e9/0x6b0 net/netlink/af_netlink.c:1345 netlink_sendmsg+0x739/0x860 net/netlink/af_netlink.c:1921 sock_sendmsg_nosec net/socket.c:714 [inline] sock_sendmsg net/socket.c:734 [inline] ____sys_sendmsg+0x38f/0x500 net/socket.c:2482 ___sys_sendmsg net/socket.c:2536 [inline] __sys_sendmsg+0x197/0x230 net/socket.c:2565 __do_sys_sendmsg net/socket.c:2574 [inline] __se_sys_sendmsg net/socket.c:2572 [inline] __x64_sys_sendmsg+0x42/0x50 net/socket.c:2572 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x2b/0x70 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd
--- net/sched/act_mpls.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
net/sched/act_mpls.c +7 -1
@@ -116,6 +116,11 @@ static int valid_label(const struct nlattr *attr, {const u32 *label =nla_data (attr); +if (nla_len (attr) !=sizeof (*label)) { +NL_SET_ERR_MSG_MOD (extack,"Invalid MPLS label length" ); +return -EINVAL ; + } +if (*label & ~MPLS_LABEL_MASK || *label ==MPLS_LABEL_IMPLNULL ) {NL_SET_ERR_MSG_MOD (extack,"MPLS label out of range" );return -EINVAL ;
@@ -128,7 +133,8 @@ static const struct nla_policy mpls_policy[TCA_MPLS_MAX + 1] = { [TCA_MPLS_UNSPEC] = { .strict_start_type = TCA_MPLS_UNSPEC + 1 }, [TCA_MPLS_PARMS] = NLA_POLICY_EXACT_LEN(sizeof(struct tc_mpls)), [TCA_MPLS_PROTO] = { .type = NLA_U16 }, - [TCA_MPLS_LABEL] = NLA_POLICY_VALIDATE_FN(NLA_U32, valid_label), + [TCA_MPLS_LABEL ] =NLA_POLICY_VALIDATE_FN (NLA_BINARY , + valid_label), [TCA_MPLS_TC] = NLA_POLICY_RANGE(NLA_U8, 0, 7), [TCA_MPLS_TTL] = NLA_POLICY_MIN(NLA_U8, 1), [TCA_MPLS_BOS] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 640/658 net/mlx5: Rename ptp clock info
In reply to Greg Kroah-HartmanFrom: Eran Ben Elisha <[email protected]>
[ Upstream commit aac2df7f022eccb5d117f07b1e231410db1a863a ]
Fix a typo in ptp_clock_info naming: mlx5_p2p -> mlx5_ptp.
Stable-dep-of: fe91d57277ee ("net/mlx5: Fix ptp max frequency adjustment range")
--- drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +1 -1
@@ -417,7 +417,7 @@ static int mlx5_ptp_verify(struct ptp_clock_info *ptp, unsigned int pin,static const struct ptp_clock_info mlx5_ptp_clock_info = { .owner =THIS_MODULE , - .name ="mlx5_p2p" , + .name ="mlx5_ptp" , .max_adj =100000000 , .n_alarm =0 , .n_ext_ts =0 ,
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 641/658 net/mlx5: Fix ptp max frequency adjustment range
In reply to Greg Kroah-HartmanFrom: Rahul Rameshbabu <[email protected]>
[ Upstream commit fe91d57277eef8bb4aca05acfa337b4a51d0bba4 ]
.max_adj of ptp_clock_info acts as an absolute value for the amount in ppb that can be set for a single call of .adjfine. This means that a single call to .getfine cannot be greater than .max_adj or less than -(.max_adj). Provides correct value for max frequency adjustment value supported by devices.
--- drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c +1 -1
@@ -418,7 +418,7 @@ static int mlx5_ptp_verify(struct ptp_clock_info *ptp, unsigned int pin,static const struct ptp_clock_info mlx5_ptp_clock_info = { .owner =THIS_MODULE , .name ="mlx5_ptp" , - .max_adj =100000000 , + .max_adj =50000000 , .n_alarm =0 , .n_ext_ts =0 , .n_per_out =0 ,
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 642/658 iommu/mediatek-v1: Add error handle for mtk_iommu_probe
In reply to Greg Kroah-HartmanFrom: Yong Wu <[email protected]>
[ Upstream commit ac304c070c54413efabf29f9e73c54576d329774 ]
In the original code, we lack the error handle. This patch adds them.
Stable-dep-of: 142e821f68cf ("iommu/mediatek-v1: Fix an error handling path in mtk_iommu_v1_probe()")
--- drivers/iommu/mtk_iommu_v1.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/iommu/mtk_iommu_v1.c +18 -4
@@ -632,12 +632,26 @@ static int mtk_iommu_probe(struct platform_device *pdev) ret =iommu_device_register (&data->iommu);if (ret) -return ret; + goto out_sysfs_remove; -if (!iommu_present (&platform_bus_type)) -bus_set_iommu (&platform_bus_type, &mtk_iommu_ops); +if (!iommu_present (&platform_bus_type)) { + ret =bus_set_iommu (&platform_bus_type, &mtk_iommu_ops); +if (ret) + goto out_dev_unreg; + } -return component_master_add_with_match (dev, &mtk_iommu_com_ops, match); + ret =component_master_add_with_match (dev, &mtk_iommu_com_ops, match); +if (ret) + goto out_bus_set_null; +return ret; + +out_bus_set_null: +bus_set_iommu (&platform_bus_type,NULL ); +out_dev_unreg: +iommu_device_unregister (&data->iommu); +out_sysfs_remove: +iommu_device_sysfs_remove (&data->iommu); +return ret; }static int mtk_iommu_remove (struct platform_device *pdev)
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 643/658 iommu/mediatek-v1: Fix an error handling path in mtk_iommu_v1_probe()
In reply to Greg Kroah-HartmanFrom: Christophe JAILLET <[email protected]>
[ Upstream commit 142e821f68cf5da79ce722cb9c1323afae30e185 ]
A clk, prepared and enabled in mtk_iommu_v1_hw_init(), is not released in the error handling path of mtk_iommu_v1_probe().
Add the corresponding clk_disable_unprepare(), as already done in the remove function.
--- drivers/iommu/mtk_iommu_v1.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/mtk_iommu_v1.c +3 -1
@@ -626,7 +626,7 @@ static int mtk_iommu_probe(struct platform_device *pdev) ret =iommu_device_sysfs_add (&data->iommu, &pdev->dev,NULL ,dev_name (&pdev->dev));if (ret) -return ret; + goto out_clk_unprepare;iommu_device_set_ops (&data->iommu, &mtk_iommu_ops);
@@ -651,6 +651,8 @@ static int mtk_iommu_probe(struct platform_device *pdev)iommu_device_unregister (&data->iommu); out_sysfs_remove:iommu_device_sysfs_remove (&data->iommu); +out_clk_unprepare: +clk_disable_unprepare (data->bclk);return ret; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 644/658 x86/resctrl: Use task_curr() instead of task_struct->on_cpu to prevent unnecessary IPI
In reply to Greg Kroah-HartmanFrom: Reinette Chatre <[email protected]>
[ Upstream commit e0ad6dc8969f790f14bddcfd7ea284b7e5f88a16 ]
James reported in [1] that there could be two tasks running on the same CPU with task_struct->on_cpu set. Using task_struct->on_cpu as a test if a task is running on a CPU may thus match the old task for a CPU while the scheduler is running and IPI it unnecessarily.
task_curr() is the correct helper to use. While doing so move the #ifdef check of the CONFIG_SMP symbol to be a C conditional used to determine if this helper should be used to ensure the code is always checked for correctness by the compiler.
[1] https://lore.kernel.org/lkml/[email protected]
Stable-dep-of: fe1f0714385f ("x86/resctrl: Fix task CLOSID/RMID update race")
--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +5 -9
@@ -2178,19 +2178,15 @@ static void rdt_move_group_tasks(struct rdtgroup *from, struct rdtgroup *to, t->closid = to->closid; t->rmid = to->mon.rmid; -#ifdef CONFIG_SMP /* -* This is safe on x86 w/o barriers as the ordering -* of writing to task_cpu() and t->on_cpu is -* reverse to the reading here. The detection is -* inaccurate as tasks might move or schedule -* before the smp function call takes place. In -* such a case the function call is pointless, but +* If the task is on a CPU, set the CPU in the mask. +* The detection is inaccurate as tasks might move or +* schedule before the smp function call takes place. +* In such a case the function call is pointless, but * there is no other side effect. */ -if (mask && t->on_cpu) +if (IS_ENABLED (CONFIG_SMP ) && mask &&task_curr (t))cpumask_set_cpu (task_cpu (t), mask); -#endif } }read_unlock (&tasklist_lock);
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 645/658 x86/resctrl: Fix task CLOSID/RMID update race
In reply to Greg Kroah-HartmanFrom: Peter Newman <[email protected]>
[ Upstream commit fe1f0714385fbcf76b0cbceb02b7277d842014fc ]
When the user moves a running task to a new rdtgroup using the task's file interface or by deleting its rdtgroup, the resulting change in CLOSID/RMID must be immediately propagated to the PQR_ASSOC MSR on the task(s) CPUs.
x86 allows reordering loads with prior stores, so if the task starts running between a task_curr() check that the CPU hoisted before the stores in the CLOSID/RMID update then it can start running with the old CLOSID/RMID until it is switched again because __rdtgroup_move_task() failed to determine that it needs to be interrupted to obtain the new CLOSID/RMID.
Refer to the diagram below:
CPU 0 CPU 1
----- -----__rdtgroup_move_task():
curr <- t1->cpu->rq->curr
__schedule():
rq->curr <- t1
resctrl_sched_in():
t1->{closid,rmid} -> {1,1} t1->{closid,rmid} <- {2,2}
if (curr == t1) // false
IPI(t1->cpu)
A similar race impacts rdt_move_group_tasks(), which updates tasks in a deleted rdtgroup.
In both cases, use smp_mb() to order the task_struct::{closid,rmid} stores before the loads in task_curr(). In particular, in the rdt_move_group_tasks() case, simply execute an smp_mb() on every iteration with a matching task.
It is possible to use a single smp_mb() in rdt_move_group_tasks(), but this would require two passes and a means of remembering which task_structs were updated in the first loop. However, benchmarking results below showed too little performance impact in the simple approach to justify implementing the two-pass approach.
Times below were collected using perf stat to measure the time to remove a group containing a 1600-task, parallel workload.
CPU: Intel(R) Xeon(R) Platinum P-8136 CPU @ 2.00GHz (112 threads)
# mkdir /sys/fs/resctrl/test # echo $$ > /sys/fs/resctrl/test/tasks # perf bench sched messaging -g 40 -l 100000
task-clock time ranges collected using:
# perf stat rmdir /sys/fs/resctrl/test
Baseline: 1.54 - 1.60 ms smp_mb() every matching task: 1.57 - 1.67 ms
[ bp: Massage commit message. ]
--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +11 -1
@@ -577,8 +577,10 @@ static int __rdtgroup_move_task(struct task_struct *tsk,/* * Ensure the task's closid and rmid are written before determining if * the task is current that will decide if it will be interrupted. +* This pairs with the full barrier between the rq->curr update and +* resctrl_sched_in() during context switch. */ -barrier (); +smp_mb ();/* * By now, the task's closid and rmid are set. If the task is current
@@ -2178,6 +2180,14 @@ static void rdt_move_group_tasks(struct rdtgroup *from, struct rdtgroup *to, t->closid = to->closid; t->rmid = to->mon.rmid; +/* +* Order the closid/rmid stores above before the loads +* in task_curr(). This pairs with the full barrier +* between the rq->curr update and resctrl_sched_in() +* during context switch. +*/ +smp_mb (); +/* * If the task is on a CPU, set the CPU in the mask. * The detection is inaccurate as tasks might move or
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 646/658 drm/virtio: Fix GEM handle creation UAF
In reply to Greg Kroah-HartmanFrom: Rob Clark <[email protected]>
[ Upstream commit 52531258318ed59a2dc5a43df2eaf0eb1d65438e ]
Userspace can guess the handle value and try to race GEM object creation with handle close, resulting in a use-after-free if we dereference the object after dropping the handle's reference. For that reason, dropping the handle's reference must be done *after* we are done dereferencing the object.
--- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_ioctl.c +9 -1
@@ -327,10 +327,18 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,drm_gem_object_release (obj);return ret; } -drm_gem_object_put_unlocked (obj); rc->res_handle = qobj->hw_res_handle;/* similiar to a VM address */ rc->bo_handle = handle; + +/* +* The handle owns the reference now. But we must drop our +* remaining reference *after* we no longer need to dereference +* the obj. Otherwise userspace could guess the handle and +* race closing it from another thread. +*/ +drm_gem_object_put_unlocked (obj); +return 0 ; }
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 647/658 arm64: atomics: format whitespace consistently
In reply to Greg Kroah-HartmanFrom: Mark Rutland <[email protected]>
[ Upstream commit 8e6082e94aac6d0338883b5953631b662a5a9188 ]
The code for the atomic ops is formatted inconsistently, and while this is not a functional problem it is rather distracting when working on them.
Some have ops have consistent indentation, e.g.
| #define ATOMIC_OP_ADD_RETURN(name, mb, cl...) \
| static inline int __lse_atomic_add_return##name(int i, atomic_t *v) \
| { \
| u32 tmp; \
| \
| asm volatile( \
| __LSE_PREAMBLE \
| " ldadd" #mb " %w[i], %w[tmp], %[v]\n" \
| " add %w[i], %w[i], %w[tmp]" \
| : [i] "+r" (i), [v] "+Q" (v->counter), [tmp] "=&r" (tmp) \
| : "r" (v) \
| : cl); \
| \
| return i; \
| }While others have negative indentation for some lines, and/or have misaligned trailing backslashes, e.g.
| static inline void __lse_atomic_##op(int i, atomic_t *v) \
| { \
| asm volatile( \
| __LSE_PREAMBLE \
| " " #asm_op " %w[i], %[v]\n" \
| : [i] "+r" (i), [v] "+Q" (v->counter) \
| : "r" (v)); \
| }This patch makes the indentation consistent and also aligns the trailing backslashes. This makes the code easier to read for those (like myself) who are easily distracted by these inconsistencies.
This is intended as a cleanup.
There should be no functional change as a result of this patch.
Stable-dep-of: 031af50045ea ("arm64: cmpxchg_double*: hazard against entire exchange variable")
--- arch/arm64/include/asm/atomic_ll_sc.h | 86 +++++++++++++-------------- arch/arm64/include/asm/atomic_lse.h | 14 ++--- 2 files changed, 50 insertions(+), 50 deletions(-)
arch/arm64/include/asm/atomic_ll_sc.h +43 -43
@@ -44,11 +44,11 @@ __ll_sc_atomic_##op(int i, atomic_t *v) \ \ asm volatile("// atomic_" #op "\n" \ __LL_SC_FALLBACK( \ -" prfm pstl1strm, %2\n" \ -"1: ldxr %w0, %2\n" \ -" " #asm_op " %w0, %w0, %w3\n" \ -" stxr %w1, %w0, %2\n" \ -" cbnz %w1, 1b\n") \ + " prfm pstl1strm, %2\n" \ + "1: ldxr %w0, %2\n" \ + " " #asm_op " %w0, %w0, %w3\n" \ + " stxr %w1, %w0, %2\n" \ + " cbnz %w1, 1b\n") \ : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) \ : __stringify(constraint) "r" (i)); \ }
@@ -62,12 +62,12 @@ __ll_sc_atomic_##op##_return##name(int i, atomic_t *v) \ \ asm volatile("// atomic_" #op "_return" #name "\n" \ __LL_SC_FALLBACK( \ -" prfm pstl1strm, %2\n" \ -"1: ld" #acq "xr %w0, %2\n" \ -" " #asm_op " %w0, %w0, %w3\n" \ -" st" #rel "xr %w1, %w0, %2\n" \ -" cbnz %w1, 1b\n" \ -" " #mb ) \ + " prfm pstl1strm, %2\n" \ + "1: ld" #acq "xr %w0, %2\n" \ + " " #asm_op " %w0, %w0, %w3\n" \ + " st" #rel "xr %w1, %w0, %2\n" \ + " cbnz %w1, 1b\n" \ + " " #mb ) \ : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) \ : __stringify(constraint) "r" (i) \ : cl); \
@@ -84,12 +84,12 @@ __ll_sc_atomic_fetch_##op##name(int i, atomic_t *v) \ \ asm volatile("// atomic_fetch_" #op #name "\n" \ __LL_SC_FALLBACK( \ -" prfm pstl1strm, %3\n" \ -"1: ld" #acq "xr %w0, %3\n" \ -" " #asm_op " %w1, %w0, %w4\n" \ -" st" #rel "xr %w2, %w1, %3\n" \ -" cbnz %w2, 1b\n" \ -" " #mb ) \ + " prfm pstl1strm, %3\n" \ + "1: ld" #acq "xr %w0, %3\n" \ + " " #asm_op " %w1, %w0, %w4\n" \ + " st" #rel "xr %w2, %w1, %3\n" \ + " cbnz %w2, 1b\n" \ + " " #mb ) \ : "=&r" (result), "=&r" (val), "=&r" (tmp), "+Q" (v->counter) \ : __stringify(constraint) "r" (i) \ : cl); \
@@ -143,11 +143,11 @@ __ll_sc_atomic64_##op(s64 i, atomic64_t *v) \ \ asm volatile("// atomic64_" #op "\n" \ __LL_SC_FALLBACK( \ -" prfm pstl1strm, %2\n" \ -"1: ldxr %0, %2\n" \ -" " #asm_op " %0, %0, %3\n" \ -" stxr %w1, %0, %2\n" \ -" cbnz %w1, 1b") \ + " prfm pstl1strm, %2\n" \ + "1: ldxr %0, %2\n" \ + " " #asm_op " %0, %0, %3\n" \ + " stxr %w1, %0, %2\n" \ + " cbnz %w1, 1b") \ : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) \ : __stringify(constraint) "r" (i)); \ }
@@ -161,12 +161,12 @@ __ll_sc_atomic64_##op##_return##name(s64 i, atomic64_t *v) \ \ asm volatile("// atomic64_" #op "_return" #name "\n" \ __LL_SC_FALLBACK( \ -" prfm pstl1strm, %2\n" \ -"1: ld" #acq "xr %0, %2\n" \ -" " #asm_op " %0, %0, %3\n" \ -" st" #rel "xr %w1, %0, %2\n" \ -" cbnz %w1, 1b\n" \ -" " #mb ) \ + " prfm pstl1strm, %2\n" \ + "1: ld" #acq "xr %0, %2\n" \ + " " #asm_op " %0, %0, %3\n" \ + " st" #rel "xr %w1, %0, %2\n" \ + " cbnz %w1, 1b\n" \ + " " #mb ) \ : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) \ : __stringify(constraint) "r" (i) \ : cl); \
@@ -176,19 +176,19 @@ __ll_sc_atomic64_##op##_return##name(s64 i, atomic64_t *v) \#define ATOMIC64_FETCH_OP (name, mb, acq, rel, cl, op, asm_op, constraint)\ static inline long \ -__ll_sc_atomic64_fetch_##op##name(s64 i, atomic64_t *v) \ +__ll_sc_atomic64_fetch_##op##name(s64 i, atomic64_t *v) \ { \ s64 result, val; \ unsigned long tmp; \ \ asm volatile("// atomic64_fetch_" #op #name "\n" \ __LL_SC_FALLBACK( \ -" prfm pstl1strm, %3\n" \ -"1: ld" #acq "xr %0, %3\n" \ -" " #asm_op " %1, %0, %4\n" \ -" st" #rel "xr %w2, %1, %3\n" \ -" cbnz %w2, 1b\n" \ -" " #mb ) \ + " prfm pstl1strm, %3\n" \ + "1: ld" #acq "xr %0, %3\n" \ + " " #asm_op " %1, %0, %4\n" \ + " st" #rel "xr %w2, %1, %3\n" \ + " cbnz %w2, 1b\n" \ + " " #mb ) \ : "=&r" (result), "=&r" (val), "=&r" (tmp), "+Q" (v->counter) \ : __stringify(constraint) "r" (i) \ : cl); \
@@ -241,14 +241,14 @@ __ll_sc_atomic64_dec_if_positive(atomic64_t *v) asmvolatile ("// atomic64_dec_if_positive\n" __LL_SC_FALLBACK( -" prfm pstl1strm, %2\n" -"1: ldxr %0, %2\n" -" subs %0, %0, #1\n" -" b.lt 2f\n" -" stlxr %w1, %0, %2\n" -" cbnz %w1, 1b\n" -" dmb ish\n" -"2:" ) +" prfm pstl1strm, %2\n" +"1: ldxr %0, %2\n" +" subs %0, %0, #1\n" +" b.lt 2f\n" +" stlxr %w1, %0, %2\n" +" cbnz %w1, 1b\n" +" dmb ish\n" +"2:" ) : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) : : "cc", "memory");
arch/arm64/include/asm/atomic_lse.h +7 -7
@@ -11,11 +11,11 @@#define __ASM_ATOMIC_LSE_H#define ATOMIC_OP (op, asm_op) \ -static inline void __lse_atomic_##op(int i, atomic_t *v) \ +static inline void __lse_atomic_##op(int i, atomic_t *v) \ { \ asm volatile( \ __LSE_PREAMBLE \ -" " #asm_op " %w[i], %[v]\n" \ + " " #asm_op " %w[i], %[v]\n" \ : [i] "+r" (i), [v] "+Q" (v->counter) \ : "r" (v)); \ }
@@ -32,7 +32,7 @@ static inline int __lse_atomic_fetch_##op##name(int i, atomic_t *v) \ { \ asm volatile( \ __LSE_PREAMBLE \ -" " #asm_op #mb " %w[i], %w[i], %[v]" \ + " " #asm_op #mb " %w[i], %w[i], %[v]" \ : [i] "+r" (i), [v] "+Q" (v->counter) \ : "r" (v) \ : cl); \
@@ -130,7 +130,7 @@ static inline int __lse_atomic_sub_return##name(int i, atomic_t *v) \" add %w[i], %w[i], %w[tmp]" \ : [i] "+&r" (i), [v] "+Q" (v->counter), [tmp] "=&r" (tmp) \: " r" (v) \ -: cl); \ +: cl); \ \ return i; \ }
@@ -168,7 +168,7 @@ static inline void __lse_atomic64_##op(s64 i, atomic64_t *v) \ { \ asmvolatile ( \ __LSE_PREAMBLE \ -" " #asm_op " %[i], %[v]\n" \ + " " #asm_op " %[i], %[v]\n" \ : [i]"+r" (i), [v]"+Q" (v->counter) \ :"r" (v)); \ }
@@ -185,7 +185,7 @@ static inline long __lse_atomic64_fetch_##op##name(s64 i, atomic64_t *v)\ { \ asm volatile( \ __LSE_PREAMBLE \ -" " #asm_op #mb " %[i], %[i], %[v]" \ + " " #asm_op #mb " %[i], %[i], %[v]" \ : [i] "+r" (i), [v] "+Q" (v->counter) \ : "r" (v) \ : cl); \
@@ -272,7 +272,7 @@ static inline void __lse_atomic64_sub(s64 i, atomic64_t *v) } #define ATOMIC64_OP_SUB_RETURN(name, mb, cl...) \ -static inline long __lse_atomic64_sub_return##name(s64 i, atomic64_t *v) \ +static inline long __lse_atomic64_sub_return##name(s64 i, atomic64_t *v)\ { \ unsigned long tmp; \ \
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 648/658 arm64: atomics: remove LL/SC trampolines
In reply to Greg Kroah-HartmanFrom: Mark Rutland <[email protected]>
[ Upstream commit b2c3ccbd0011bb3b51d0fec24cb3a5812b1ec8ea ]
When CONFIG_ARM64_LSE_ATOMICS=y, each use of an LL/SC atomic results in a fragment of code being generated in a subsection without a clear association with its caller. A trampoline in the caller branches to the LL/SC atomic with with a direct branch, and the atomic directly branches back into its trampoline.
This breaks backtracing, as any PC within the out-of-line fragment will be symbolized as an offset from the nearest prior symbol (which may not be the function using the atomic), and since the atomic returns with a direct branch, the caller's PC may be missing from the backtrace.
For example, with secondary_start_kernel() hacked to contain atomic_inc(NULL), the resulting exception can be reported as being taken from cpus_are_stuck_in_kernel():
| Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 | Mem abort info: | ESR = 0x0000000096000004 | EC = 0x25: DABT (current EL), IL = 32 bits | SET = 0, FnV = 0 | EA = 0, S1PTW = 0 | FSC = 0x04: level 0 translation fault | Data abort info: | ISV = 0, ISS = 0x00000004 | CM = 0, WnR = 0 | [0000000000000000] user address but active_mm is swapper | Internal error: Oops: 96000004 [#1] PREEMPT SMP | Modules linked in: | CPU: 1 PID: 0 Comm: swapper/1 Not tainted 5.19.0-11219-geb555cb5b794-dirty #3 | Hardware name: linux,dummy-virt (DT) | pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) | pc : cpus_are_stuck_in_kernel+0xa4/0x120 | lr : secondary_start_kernel+0x164/0x170 | sp : ffff80000a4cbe90 | x29: ffff80000a4cbe90 x28: 0000000000000000 x27: 0000000000000000 | x26: 0000000000000000 x25: 0000000000000000 x24: 0000000000000000 | x23: 0000000000000000 x22: 0000000000000000 x21: 0000000000000000 | x20: 0000000000000001 x19: 0000000000000001 x18: 0000000000000008 | x17: 3030383832343030 x16: 3030303030307830 x15: ffff80000a4cbab0 | x14: 0000000000000001 x13: 5d31666130663133 x12: 3478305b20313030 | x11: 3030303030303078 x10: 3020726f73736563 x9 : 726f737365636f72 | x8 : ffff800009ff2ef0 x7 : 0000000000000003 x6 : 0000000000000000 | x5 : 0000000000000000 x4 : 0000000000000000 x3 : 0000000000000100 | x2 : 0000000000000000 x1 : ffff0000029bd880 x0 : 0000000000000000 | Call trace: | cpus_are_stuck_in_kernel+0xa4/0x120 | __secondary_switched+0xb0/0xb4 | Code: 35ffffa3 17fffc6c d53cd040 f9800011 (885f7c01) | ---[ end trace 0000000000000000 ]---
This is confusing and hinders debugging, and will be problematic for CONFIG_LIVEPATCH as these cases cannot be unwound reliably.
This is very similar to recent issues with out-of-line exception fixups, which were removed in commits:
35d67794b8828333 ("arm64: lib: __arch_clear_user(): fold fixups into body") 4012e0e22739eef9 ("arm64: lib: __arch_copy_from_user(): fold fixups into body") 139f9ab73d60cf76 ("arm64: lib: __arch_copy_to_user(): fold fixups into body")
When the trampolines were introduced in commit:
addfc38672c73efd ("arm64: atomics: avoid out-of-line ll/sc atomics")
The rationale was to improve icache performance by grouping the LL/SC atomics together. This has never been measured, and this theoretical benefit is outweighed by other factors:
* As the subsections are collapsed into sections at object file granularity, these are spread out throughout the kernel and can share cachelines with unrelated code regardless.
* GCC 12.1.0 has been observed to place the trampoline out-of-line in specialised __ll_sc_*() functions, introducing more branching than was intended.
* Removing the trampolines has been observed to shrink a defconfig kernel Image by 64KiB when building with GCC 12.1.0.
This patch removes the LL/SC trampolines, meaning that the LL/SC atomics will be inlined into their callers (or placed in out-of line functions using regular BL/RET pairs). When CONFIG_ARM64_LSE_ATOMICS=y, the LL/SC atomics are always called in an unlikely branch, and will be placed in a cold portion of the function, so this should have minimal impact to the hot paths.
Other than the improved backtracing, there should be no functional change as a result of this patch.
Stable-dep-of: 031af50045ea ("arm64: cmpxchg_double*: hazard against entire exchange variable")
--- arch/arm64/include/asm/atomic_ll_sc.h | 40 ++++++--------------------- 1 file changed, 9 insertions(+), 31 deletions(-)
arch/arm64/include/asm/atomic_ll_sc.h +9 -31
@@ -12,19 +12,6 @@#include <linux/stringify.h> -#if IS_ENABLED (CONFIG_ARM64_LSE_ATOMICS ) &&IS_ENABLED (CONFIG_AS_LSE ) -#define __LL_SC_FALLBACK (asm_ops) \ -" b 3f\n" \ -" .subsection 1\n" \ -"3:\n" \ -asm_ops "\n" \ -" b 4f\n" \ -" .previous\n" \ -"4:\n" -#else -#define __LL_SC_FALLBACK (asm_ops) asm_ops -#endif -#ifndef CONFIG_CC_HAS_K_CONSTRAINT #define K #endif
@@ -43,12 +30,11 @@ __ll_sc_atomic_##op(int i, atomic_t *v) \int result; \ \ asm volatile("// atomic_" #op "\n" \ - __LL_SC_FALLBACK( \ " prfm pstl1strm, %2\n" \ "1: ldxr %w0, %2\n" \ " " #asm_op " %w0, %w0, %w3\n" \ " stxr %w1, %w0, %2\n" \ - " cbnz %w1, 1b\n") \ + " cbnz %w1, 1b\n" \ : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) \ : __stringify(constraint) "r" (i)); \ }
@@ -61,13 +47,12 @@ __ll_sc_atomic_##op##_return##name(int i, atomic_t *v) \int result; \ \ asm volatile("// atomic_" #op "_return" #name "\n" \ - __LL_SC_FALLBACK( \ " prfm pstl1strm, %2\n" \ "1: ld" #acq "xr %w0, %2\n" \ " " #asm_op " %w0, %w0, %w3\n" \ " st" #rel "xr %w1, %w0, %2\n" \ " cbnz %w1, 1b\n" \ - " " #mb ) \ + " " #mb \ : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) \ : __stringify(constraint) "r" (i) \ : cl); \
@@ -83,13 +68,12 @@ __ll_sc_atomic_fetch_##op##name(int i, atomic_t *v) \int val, result; \ \ asm volatile("// atomic_fetch_" #op #name "\n" \ - __LL_SC_FALLBACK( \ " prfm pstl1strm, %3\n" \ "1: ld" #acq "xr %w0, %3\n" \ " " #asm_op " %w1, %w0, %w4\n" \ " st" #rel "xr %w2, %w1, %3\n" \ " cbnz %w2, 1b\n" \ - " " #mb ) \ + " " #mb \ : "=&r" (result), "=&r" (val), "=&r" (tmp), "+Q" (v->counter) \ : __stringify(constraint) "r" (i) \ : cl); \
@@ -142,12 +126,11 @@ __ll_sc_atomic64_##op(s64 i, atomic64_t *v) \unsigned long tmp; \ \ asm volatile("// atomic64_" #op "\n" \ - __LL_SC_FALLBACK( \ " prfm pstl1strm, %2\n" \ "1: ldxr %0, %2\n" \ " " #asm_op " %0, %0, %3\n" \ " stxr %w1, %0, %2\n" \ - " cbnz %w1, 1b") \ + " cbnz %w1, 1b" \ : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) \ : __stringify(constraint) "r" (i)); \ }
@@ -160,13 +143,12 @@ __ll_sc_atomic64_##op##_return##name(s64 i, atomic64_t *v) \unsigned long tmp; \ \ asm volatile("// atomic64_" #op "_return" #name "\n" \ - __LL_SC_FALLBACK( \ " prfm pstl1strm, %2\n" \ "1: ld" #acq "xr %0, %2\n" \ " " #asm_op " %0, %0, %3\n" \ " st" #rel "xr %w1, %0, %2\n" \ " cbnz %w1, 1b\n" \ - " " #mb ) \ + " " #mb \ : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) \ : __stringify(constraint) "r" (i) \ : cl); \
@@ -182,13 +164,12 @@ __ll_sc_atomic64_fetch_##op##name(s64 i, atomic64_t *v) \unsigned long tmp; \ \ asm volatile("// atomic64_fetch_" #op #name "\n" \ - __LL_SC_FALLBACK( \ " prfm pstl1strm, %3\n" \ "1: ld" #acq "xr %0, %3\n" \ " " #asm_op " %1, %0, %4\n" \ " st" #rel "xr %w2, %1, %3\n" \ " cbnz %w2, 1b\n" \ - " " #mb ) \ + " " #mb \ : "=&r" (result), "=&r" (val), "=&r" (tmp), "+Q" (v->counter) \ : __stringify(constraint) "r" (i) \ : cl); \
@@ -240,7 +221,6 @@ __ll_sc_atomic64_dec_if_positive(atomic64_t *v)unsigned long tmp; asmvolatile ("// atomic64_dec_if_positive\n" - __LL_SC_FALLBACK(" prfm pstl1strm, %2\n" "1: ldxr %0, %2\n" " subs %0, %0, #1\n"
@@ -248,7 +228,7 @@ __ll_sc_atomic64_dec_if_positive(atomic64_t *v)" stlxr %w1, %0, %2\n" " cbnz %w1, 1b\n" " dmb ish\n" - "2:") +"2:" : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) : : "cc", "memory");
@@ -274,7 +254,6 @@ __ll_sc__cmpxchg_case_##name##sz(volatile void *ptr, \ old = (u##sz)old; \ \ asm volatile( \ - __LL_SC_FALLBACK( \ " prfm pstl1strm, %[v]\n" \ "1: ld" #acq "xr" #sfx "\t%" #w "[oldval], %[v]\n" \ " eor %" #w "[tmp], %" #w "[oldval], %" #w "[old]\n" \
@@ -282,7 +261,7 @@ __ll_sc__cmpxchg_case_##name##sz(volatile void *ptr, \ " st" #rel "xr" #sfx "\t%w[tmp], %" #w "[new], %[v]\n" \ " cbnz %w[tmp], 1b\n" \ " " #mb "\n" \ - "2:") \ + "2:" \ : [tmp] "=&r" (tmp), [oldval] "=&r" (oldval), \ [v] "+Q" (*(u##sz *)ptr) \ : [old] __stringify(constraint) "r" (old), [new] "r" (new) \
@@ -326,7 +305,6 @@ __ll_sc__cmpxchg_double##name(unsigned long old1, \unsigned long tmp, ret; \ \ asm volatile("// __cmpxchg_double" #name "\n" \ - __LL_SC_FALLBACK( \ " prfm pstl1strm, %2\n" \ "1: ldxp %0, %1, %2\n" \ " eor %0, %0, %3\n" \
@@ -336,7 +314,7 @@ __ll_sc__cmpxchg_double##name(unsigned long old1, \ " st" #rel "xp %w0, %5, %6, %2\n" \ " cbnz %w0, 1b\n" \ " " #mb "\n" \ - "2:") \ + "2:" \ : "=&r" (tmp), "=&r" (ret), "+Q" (*(unsigned long *)ptr) \ : "r" (old1), "r" (old2), "r" (new1), "r" (new2) \ : cl); \
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 649/658 arm64: cmpxchg_double*: hazard against entire exchange variable
In reply to Greg Kroah-HartmanFrom: Mark Rutland <[email protected]>
[ Upstream commit 031af50045ea97ed4386eb3751ca2c134d0fc911 ]
The inline assembly for arm64's cmpxchg_double*() implementations use a +Q constraint to hazard against other accesses to the memory location being exchanged. However, the pointer passed to the constraint is a pointer to unsigned long, and thus the hazard only applies to the first 8 bytes of the location.
GCC can take advantage of this, assuming that other portions of the location are unchanged, leading to a number of potential problems.
This is similar to what we fixed back in commit:
fee960bed5e857eb ("arm64: xchg: hazard against entire exchange variable")
... but we forgot to adjust cmpxchg_double*() similarly at the same time.
The same problem applies, as demonstrated with the following test:
| struct big {
| u64 lo, hi;
| } __aligned(128);
|
| unsigned long foo(struct big *b)
| {
| u64 hi_old, hi_new;
|
| hi_old = b->hi;
| cmpxchg_double_local(&b->lo, &b->hi, 0x12, 0x34, 0x56, 0x78);
| hi_new = b->hi;
|
| return hi_old ^ hi_new;
| }... which GCC 12.1.0 compiles as:
| 0000000000000000 <foo>: | 0: d503233f paciasp | 4: aa0003e4 mov x4, x0 | 8: 1400000e b 40 <foo+0x40> | c: d2800240 mov x0, #0x12 // #18 | 10: d2800681 mov x1, #0x34 // #52 | 14: aa0003e5 mov x5, x0 | 18: aa0103e6 mov x6, x1 | 1c: d2800ac2 mov x2, #0x56 // #86 | 20: d2800f03 mov x3, #0x78 // #120 | 24: 48207c82 casp x0, x1, x2, x3, [x4] | 28: ca050000 eor x0, x0, x5 | 2c: ca060021 eor x1, x1, x6 | 30: aa010000 orr x0, x0, x1 | 34: d2800000 mov x0, #0x0 // #0 <--- BANG | 38: d50323bf autiasp | 3c: d65f03c0 ret | 40: d2800240 mov x0, #0x12 // #18 | 44: d2800681 mov x1, #0x34 // #52 | 48: d2800ac2 mov x2, #0x56 // #86 | 4c: d2800f03 mov x3, #0x78 // #120 | 50: f9800091 prfm pstl1strm, [x4] | 54: c87f1885 ldxp x5, x6, [x4] | 58: ca0000a5 eor x5, x5, x0 | 5c: ca0100c6 eor x6, x6, x1 | 60: aa0600a6 orr x6, x5, x6 | 64: b5000066 cbnz x6, 70 <foo+0x70> | 68: c8250c82 stxp w5, x2, x3, [x4] | 6c: 35ffff45 cbnz w5, 54 <foo+0x54> | 70: d2800000 mov x0, #0x0 // #0 <--- BANG | 74: d50323bf autiasp | 78: d65f03c0 ret
Notice that at the lines with "BANG" comments, GCC has assumed that the higher 8 bytes are unchanged by the cmpxchg_double() call, and that hi_old ^ hi_new can be reduced to a constant zero, for both LSE and LL/SC versions of cmpxchg_double().
This patch fixes the issue by passing a pointer to __uint128_t into the +Q constraint, ensuring that the compiler hazards against the entire 16 bytes being modified.
With this change, GCC 12.1.0 compiles the above test as:
| 0000000000000000 <foo>: | 0: f9400407 ldr x7, [x0, #8] | 4: d503233f paciasp | 8: aa0003e4 mov x4, x0 | c: 1400000f b 48 <foo+0x48> | 10: d2800240 mov x0, #0x12 // #18 | 14: d2800681 mov x1, #0x34 // #52 | 18: aa0003e5 mov x5, x0 | 1c: aa0103e6 mov x6, x1 | 20: d2800ac2 mov x2, #0x56 // #86 | 24: d2800f03 mov x3, #0x78 // #120 | 28: 48207c82 casp x0, x1, x2, x3, [x4] | 2c: ca050000 eor x0, x0, x5 | 30: ca060021 eor x1, x1, x6 | 34: aa010000 orr x0, x0, x1 | 38: f9400480 ldr x0, [x4, #8] | 3c: d50323bf autiasp | 40: ca0000e0 eor x0, x7, x0 | 44: d65f03c0 ret | 48: d2800240 mov x0, #0x12 // #18 | 4c: d2800681 mov x1, #0x34 // #52 | 50: d2800ac2 mov x2, #0x56 // #86 | 54: d2800f03 mov x3, #0x78 // #120 | 58: f9800091 prfm pstl1strm, [x4] | 5c: c87f1885 ldxp x5, x6, [x4] | 60: ca0000a5 eor x5, x5, x0 | 64: ca0100c6 eor x6, x6, x1 | 68: aa0600a6 orr x6, x5, x6 | 6c: b5000066 cbnz x6, 78 <foo+0x78> | 70: c8250c82 stxp w5, x2, x3, [x4] | 74: 35ffff45 cbnz w5, 5c <foo+0x5c> | 78: f9400480 ldr x0, [x4, #8] | 7c: d50323bf autiasp | 80: ca0000e0 eor x0, x7, x0 | 84: d65f03c0 ret
... sampling the high 8 bytes before and after the cmpxchg, and performing an EOR, as we'd expect.
For backporting, I've tested this atop linux-4.9.y with GCC 5.5.0. Note that linux-4.9.y is oldest currently supported stable release, and mandates GCC 5.1+. Unfortunately I couldn't get a GCC 5.1 binary to run on my machines due to library incompatibilities.
I've also used a standalone test to check that we can use a __uint128_t pointer in a +Q constraint at least as far back as GCC 4.8.5 and LLVM 3.9.1.
--- arch/arm64/include/asm/atomic_ll_sc.h | 2 +- arch/arm64/include/asm/atomic_lse.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/arm64/include/asm/atomic_ll_sc.h +1 -1
@@ -315,7 +315,7 @@ __ll_sc__cmpxchg_double##name(unsigned long old1, \" cbnz %w0, 1b\n" \ " " #mb "\n" \ "2:" \ - : "=&r" (tmp), "=&r" (ret), "+Q" (*(unsigned long *)ptr) \ + : "=&r" (tmp), "=&r" (ret), "+Q" (*(__uint128_t *)ptr) \ : "r" (old1), "r" (old2), "r" (new1), "r" (new2) \ : cl); \ \
arch/arm64/include/asm/atomic_lse.h +1 -1
@@ -403,7 +403,7 @@ __lse__cmpxchg_double##name(unsigned long old1, \" eor %[old2], %[old2], %[oldval2]\n" \" orr %[old1], %[old1], %[old2]" \ : [old1] "+&r" (x0), [old2] "+&r" (x1), \ -[v] " +Q " (*(unsigned long *)ptr) \ +[v] " +Q " (*(__uint128_t *)ptr) \ : [new1] " r" (x2), [new2] " r" (x3), [ptr] " r" (x4), \ [oldval1] " r" (oldval1), [oldval2] " r" (oldval2) \ : cl); \
Signature · 1 line
2.35.1
Greg Kroah-Hartman
maintainerPATCH 650/658 efi: fix NULL-deref in init error path
In reply to Greg Kroah-HartmanFrom: Johan Hovold <[email protected]>
[ Upstream commit 703c13fe3c9af557d312f5895ed6a5fda2711104 ]
In cases where runtime services are not supported or have been disabled, the runtime services workqueue will never have been allocated.
Do not try to destroy the workqueue unconditionally in the unlikely event that EFI initialisation fails to avoid dereferencing a NULL pointer.
--- drivers/firmware/efi/efi.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/firmware/efi/efi.c +6 -3
@@ -345,8 +345,8 @@ static int __init efisubsys_init(void) efi_kobj =kobject_create_and_add ("efi" , firmware_kobj);if (!efi_kobj) {pr_err ("efi: Firmware registration failed.\n" ); -destroy_workqueue (efi_rts_wq); -return -ENOMEM ; + error = -ENOMEM ; + goto err_destroy_wq; } error =generic_ops_register ();
@@ -382,7 +382,10 @@ err_unregister:generic_ops_unregister (); err_put:kobject_put (efi_kobj); -destroy_workqueue (efi_rts_wq); +err_destroy_wq: +if (efi_rts_wq) +destroy_workqueue (efi_rts_wq); +return error; }
Greg Kroah-Hartman
maintainerPATCH 651/658 mm: Always release pages to the buddy allocator in memblock_free_late().
In reply to Greg Kroah-HartmanFrom: Aaron Thompson <[email protected]>
commit 115d9d77bb0f9152c60b6e8646369fa7f6167593 upstream.
If CONFIG_DEFERRED_STRUCT_PAGE_INIT is enabled, memblock_free_pages() only releases pages to the buddy allocator if they are not in the deferred range. This is correct for free pages (as defined by for_each_free_mem_pfn_range_in_zone()) because free pages in the deferred range will be initialized and released as part of the deferred init process. memblock_free_pages() is called by memblock_free_late(), which is used to free reserved ranges after memblock_free_all() has run. All pages in reserved ranges have been initialized at that point, and accordingly, those pages are not touched by the deferred init process. This means that currently, if the pages that memblock_free_late() intends to release are in the deferred range, they will never be released to the buddy allocator. They will forever be reserved.
In addition, memblock_free_pages() calls kmsan_memblock_free_pages(), which is also correct for free pages but is not correct for reserved pages. KMSAN metadata for reserved pages is initialized by kmsan_init_shadow(), which runs shortly before memblock_free_all().
For both of these reasons, memblock_free_pages() should only be called for free pages, and memblock_free_late() should call __free_pages_core() directly instead.
One case where this issue can occur in the wild is EFI boot on x86_64. The x86 EFI code reserves all EFI boot services memory ranges via memblock_reserve() and frees them later via memblock_free_late() (efi_reserve_boot_services() and efi_free_boot_services(), respectively). If any of those ranges happens to fall within the deferred init range, the pages will not be released and that memory will be unavailable.
For example, on an Amazon EC2 t3.micro VM (1 GB) booting via EFI:
v6.2-rc2:
# grep -E 'Node|spanned|present|managed' /proc/zoneinfo
Node 0, zone DMA
spanned 4095
present 3999
managed 3840
Node 0, zone DMA32
spanned 246652
present 245868
managed 178867v6.2-rc2 + patch:
# grep -E 'Node|spanned|present|managed' /proc/zoneinfo
Node 0, zone DMA
spanned 4095
present 3999
managed 3840
Node 0, zone DMA32
spanned 246652
present 245868
managed 222816 # +43,949 pages--- mm/memblock.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
mm/memblock.c +7 -1
@@ -1546,7 +1546,13 @@ void __init __memblock_free_late(phys_ad end =PFN_DOWN (base + size);for (; cursor < end; cursor++) { -memblock_free_pages (pfn_to_page (cursor), cursor,0 ); +/* +* Reserved pages are always initialized by the end of +* memblock_free_all() (by memmap_init() and, if deferred +* initialization is enabled, memmap_init_reserved_pages()), so +* these pages can be released directly to the buddy allocator. +*/ +__free_pages_core (pfn_to_page (cursor),0 );totalram_pages_inc (); } }
Greg Kroah-Hartman
maintainerPATCH 652/658 Revert "usb: ulpi: defer ulpi_register on ulpi_read_id timeout"
In reply to Greg Kroah-HartmanFrom: Ferry Toth <[email protected]>
commit b659b613cea2ae39746ca8bd2b69d1985dd9d770 upstream.
This reverts commit 8a7b31d545d3a15f0e6f5984ae16f0ca4fd76aac.
This patch results in some qemu test failures, specifically xilinx-zynq-a9 machine and zynq-zc702 as well as zynq-zed devicetree files, when trying to boot from USB drive.
--- drivers/usb/common/ulpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/common/ulpi.c +1 -1
@@ -207,7 +207,7 @@ static int ulpi_read_id(struct ulpi *ulp/* Test the interface */ ret =ulpi_write (ulpi,ULPI_SCRATCH ,0xaa );if (ret <0 ) -return ret; + goto err; ret =ulpi_read (ulpi,ULPI_SCRATCH );if (ret <0 )
Greg Kroah-Hartman
maintainerPATCH 653/658 tipc: fix use-after-free in tipc_disc_rcv()
In reply to Greg Kroah-HartmanFrom: Tuong Lien <[email protected]>
commit 31e4ccc99eda8a5a7e6902c98bee6e78ffd3edb9 upstream.
In the function 'tipc_disc_rcv()', the 'msg_peer_net_hash()' is called to read the header data field but after the message skb has been freed, that might result in a garbage value...
This commit fixes it by defining a new local variable to store the data first, just like the other header fields' handling.
--- net/tipc/discover.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/tipc/discover.c +3 -3
@@ -194,6 +194,7 @@ void tipc_disc_rcv(struct net *net, stru {struct tipc_net *tn =tipc_net (net);struct tipc_msg *hdr =buf_msg (skb); +u32 pnet_hash =msg_peer_net_hash (hdr);u16 caps =msg_node_capabilities (hdr);bool legacy = tn->legacy_addr_format;u32 sugg =msg_sugg_node_addr (hdr);
@@ -245,9 +246,8 @@ void tipc_disc_rcv(struct net *net, strureturn ;if (!tipc_in_scope (legacy, b->domain, src))return ; -tipc_node_check_dest (net, src, peer_id, b, caps, signature, -msg_peer_net_hash (hdr), &maddr, &respond, - &dupl_addr); +tipc_node_check_dest (net, src, peer_id, b, caps, signature, pnet_hash, + &maddr, &respond, &dupl_addr);if (dupl_addr)disc_dupl_alert (b, src, &maddr);if (!respond)
Greg Kroah-Hartman
maintainerPATCH 654/658 tty: serial: tegra: Handle RX transfer in PIO mode if DMA wasnt started
In reply to Greg Kroah-HartmanFrom: Dmitry Osipenko <[email protected]>
commit 1f69a1273b3f204a9c00dc3bbdcc4afcd0787428 upstream.
It is possible to get an instant RX timeout or end-of-transfer interrupt before RX DMA was started, if transaction is less than 16 bytes. Transfer should be handled in PIO mode in this case because DMA can't handle it. This patch brings back the original behaviour of the driver that was changed by accident by a previous commit, it fixes occasional Bluetooth HW initialization failures which I started to notice recently.
--- drivers/tty/serial/serial-tegra.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-)
drivers/tty/serial/serial-tegra.c +16 -19
@@ -694,11 +694,22 @@ static void tegra_uart_copy_rx_to_tty(st TEGRA_UART_RX_DMA_BUFFER_SIZE, DMA_TO_DEVICE); } +static void do_handle_rx_pio (struct tegra_uart_port *tup) +{ +struct tty_struct *tty =tty_port_tty_get (&tup->uport.state->port); +struct tty_port *port = &tup->uport.state->port; + +tegra_uart_handle_rx_pio (tup, port); +if (tty) { +tty_flip_buffer_push (port); +tty_kref_put (tty); + } +} +static void tegra_uart_rx_buffer_push (struct tegra_uart_port *tup,unsigned int residue) {struct tty_port *port = &tup->uport.state->port; -struct tty_struct *tty =tty_port_tty_get (port);unsigned int count;async_tx_ack (tup->rx_dma_desc);
@@ -707,11 +718,7 @@ static void tegra_uart_rx_buffer_push(st/* If we are here, DMA is stopped */ tegra_uart_copy_rx_to_tty (tup, port, count); -tegra_uart_handle_rx_pio (tup, port); -if (tty) { -tty_flip_buffer_push (port); -tty_kref_put (tty); - } +do_handle_rx_pio (tup); }static void tegra_uart_rx_dma_complete (void *args)
@@ -751,8 +758,10 @@ static void tegra_uart_terminate_rx_dma( {struct dma_tx_state state; -if (!tup->rx_dma_active) +if (!tup->rx_dma_active) { +do_handle_rx_pio (tup);return ; + }dmaengine_pause (tup->rx_dma_chan);dmaengine_tx_status (tup->rx_dma_chan, tup->rx_cookie, &state);
@@ -821,18 +830,6 @@ static void tegra_uart_handle_modem_signuart_handle_cts_change (&tup->uport, msr &UART_MSR_CTS ); } -static void do_handle_rx_pio (struct tegra_uart_port *tup) -{ -struct tty_struct *tty =tty_port_tty_get (&tup->uport.state->port); -struct tty_port *port = &tup->uport.state->port; - -tegra_uart_handle_rx_pio (tup, port); -if (tty) { -tty_flip_buffer_push (port); -tty_kref_put (tty); - } -} -static irqreturn_t tegra_uart_isr (int irq,void *data) {struct tegra_uart_port *tup = data;
Greg Kroah-Hartman
maintainerPATCH 655/658 tipc: Add a missing case of TIPC_DIRECT_MSG type
In reply to Greg Kroah-HartmanFrom: Hoang Le <[email protected]>
commit 8b1e5b0a99f04bda2d6c85ecfe5e68a356c10914 upstream.
In the commit f73b12812a3d
("tipc: improve throughput between nodes in netns"), we're missing a check to handle TIPC_DIRECT_MSG type, it's still using old sending mechanism for this message type. So, throughput improvement is not significant as expected.
Besides that, when sending a large message with that type, we're also handle wrong receiving queue, it should be enqueued in socket receiving instead of multicast messages.
Fix this by adding the missing case for TIPC_DIRECT_MSG.
--- net/tipc/msg.h | 5 +++++ net/tipc/node.c | 3 ++- net/tipc/socket.c | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-)
net/tipc/msg.h +5 -0
@@ -358,6 +358,11 @@ static inline u32 msg_connected(struct treturn msg_type (m) ==TIPC_CONN_MSG ; } +static inline u32 msg_direct (struct tipc_msg *m) +{ +return msg_type (m) ==TIPC_DIRECT_MSG ; +} +static inline u32 msg_errcode (struct tipc_msg *m) {return msg_bits (m,1 ,25 ,0xf );
net/tipc/node.c +2 -1
@@ -1489,7 +1489,8 @@ static void tipc_lxc_xmit(struct net *pecase TIPC_MEDIUM_IMPORTANCE :case TIPC_HIGH_IMPORTANCE :case TIPC_CRITICAL_IMPORTANCE : -if (msg_connected (hdr) ||msg_named (hdr)) { +if (msg_connected (hdr) ||msg_named (hdr) || +msg_direct (hdr)) {tipc_loopback_trace (peer_net, list);spin_lock_init (&list->lock);tipc_sk_rcv (peer_net, list);
net/tipc/socket.c +1 -1
@@ -1407,7 +1407,7 @@ static int __tipc_sendmsg(struct socket }__skb_queue_head_init (&pkts); - mtu =tipc_node_get_mtu (net, dnode, tsk->portid, false); + mtu =tipc_node_get_mtu (net, dnode, tsk->portid, true); rc =tipc_msg_build (hdr, m,0 , dlen, mtu, &pkts);if (unlikely (rc != dlen))return rc;
Greg Kroah-Hartman
maintainerPATCH 656/658 pseries/eeh: Fix the kdump kernel crash during eeh_pseries_init
In reply to Greg Kroah-HartmanFrom: Mahesh Salgaonkar <[email protected]>
commit eb8257a12192f43ffd41bd90932c39dade958042 upstream.
On pseries LPAR when an empty slot is assigned to partition OR in single LPAR mode, kdump kernel crashes during issuing PHB reset.
In the kdump scenario, we traverse all PHBs and issue reset using the pe_config_addr of the first child device present under each PHB. However the code assumes that none of the PHB slots can be empty and uses list_first_entry() to get the first child device under the PHB. Since list_first_entry() expects the list to be non-empty, it returns an invalid pci_dn entry and ends up accessing NULL phb pointer under pci_dn->phb causing kdump kernel crash.
This patch fixes the below kdump kernel crash by skipping empty slots:
audit: initializing netlink subsys (disabled)
thermal_sys: Registered thermal governor 'fair_share'
thermal_sys: Registered thermal governor 'step_wise'
cpuidle: using governor menu
pstore: Registered nvram as persistent store backend
Issue PHB reset ...
audit: type=2000 audit(1631267818.000:1): state=initialized audit_enabled=0 res=1
BUG: Kernel NULL pointer dereference on read at 0x00000268
Faulting instruction address: 0xc000000008101fb0
Oops: Kernel access of bad area, sig: 7 [#1]
LE PAGE_SIZE=64K MMU=Radix SMP NR_CPUS=2048 NUMA pSeries
Modules linked in:
CPU: 7 PID: 1 Comm: swapper/7 Not tainted 5.14.0 #1
NIP: c000000008101fb0 LR: c000000009284ccc CTR: c000000008029d70
REGS: c00000001161b840 TRAP: 0300 Not tainted (5.14.0)
MSR: 8000000002009033 <SF,VEC,EE,ME,IR,DR,RI,LE> CR: 28000224 XER: 20040002
CFAR: c000000008101f0c DAR: 0000000000000268 DSISR: 00080000 IRQMASK: 0
...
NIP pseries_eeh_get_pe_config_addr+0x100/0x1b0
LR __machine_initcall_pseries_eeh_pseries_init+0x2cc/0x350
Call Trace:
0xc00000001161bb80 (unreliable)
__machine_initcall_pseries_eeh_pseries_init+0x2cc/0x350
do_one_initcall+0x60/0x2d0
kernel_init_freeable+0x350/0x3f8
kernel_init+0x3c/0x17c
ret_from_kernel_thread+0x5c/0x64--- arch/powerpc/platforms/pseries/eeh_pseries.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/powerpc/platforms/pseries/eeh_pseries.c +4 -0
@@ -879,6 +879,10 @@ static int __init eeh_pseries_init(void)if (is_kdump_kernel () || reset_devices) {pr_info ("Issue PHB reset ...\n" );list_for_each_entry (phb, &hose_list, list_node) { +// Skip if the slot is empty +if (list_empty (&PCI_DN (phb->dn)->child_list)) +continue ; + pdn = list_first_entry(&PCI_DN(phb->dn)->child_list, struct pci_dn, list); addr = (pdn->busno <<16 ) | (pdn->devfn <<8 ); config_addr =pseries_eeh_get_config_addr (phb, addr);
Greg Kroah-Hartman
maintainerPATCH 657/658 ocfs2: fix freeing uninitialized resource on ocfs2_dlm_shutdown
In reply to Greg Kroah-HartmanFrom: Heming Zhao <[email protected]>
commit 550842cc60987b269e31b222283ade3e1b6c7fc8 upstream.
After commit 0737e01de9c4 ("ocfs2: ocfs2_mount_volume does cleanup job before return error"), any procedure after ocfs2_dlm_init() fails will trigger crash when calling ocfs2_dlm_shutdown().
ie: On local mount mode, no dlm resource is initialized. If ocfs2_mount_volume() fails in ocfs2_find_slot(), error handling will call ocfs2_dlm_shutdown(), then does dlm resource cleanup job, which will trigger kernel crash.
This solution should bypass uninitialized resources in ocfs2_dlm_shutdown().
--- fs/ocfs2/dlmglue.c | 8 +++++--- fs/ocfs2/super.c | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-)
fs/ocfs2/dlmglue.c +5 -3
@@ -3396,10 +3396,12 @@ void ocfs2_dlm_shutdown(struct ocfs2_supocfs2_lock_res_free (&osb->osb_nfs_sync_lockres);ocfs2_lock_res_free (&osb->osb_orphan_scan.os_lockres); -ocfs2_cluster_disconnect (osb->cconn, hangup_pending); - osb->cconn =NULL ; +if (osb->cconn) { +ocfs2_cluster_disconnect (osb->cconn, hangup_pending); + osb->cconn =NULL ; -ocfs2_dlm_shutdown_debug (osb); +ocfs2_dlm_shutdown_debug (osb); + } } static int ocfs2_drop_lock(struct ocfs2_super *osb,
fs/ocfs2/super.c +1 -2
@@ -1922,8 +1922,7 @@ static void ocfs2_dismount_volume(struct !ocfs2_is_hard_readonly(osb)) hangup_needed =1 ; -if (osb->cconn) -ocfs2_dlm_shutdown (osb, hangup_needed); +ocfs2_dlm_shutdown (osb, hangup_needed);ocfs2_blockcheck_stats_debugfs_remove (&osb->osb_ecc_stats);debugfs_remove_recursive (osb->osb_debug_root);
Greg Kroah-Hartman
maintainerPATCH 658/658 tipc: call tipc_lxc_xmit without holding node_read_lock
In reply to Greg Kroah-HartmanFrom: Xin Long <[email protected]>
commit 88956177db179e4eba7cd590971961857d1565b8 upstream.
When sending packets between nodes in netns, it calls tipc_lxc_xmit() for peer node to receive the packets where tipc_sk_mcast_rcv()/tipc_sk_rcv() might be called, and it's pretty much like in tipc_rcv().
Currently the local 'node rw lock' is held during calling tipc_lxc_xmit() to protect the peer_net not being freed by another thread. However, when receiving these packets, tipc_node_add_conn() might be called where the peer 'node rw lock' is acquired. Then a dead lock warning is triggered by lockdep detector, although it is not a real dead lock:
WARNING: possible recursive locking detected
--------------------------------------------
conn_server/1086 is trying to acquire lock:
ffff8880065cb020 (&n->lock#2){++--}-{2:2}, \
at: tipc_node_add_conn.cold.76+0xaa/0x211 [tipc]
but task is already holding lock:
ffff8880065cd020 (&n->lock#2){++--}-{2:2}, \
at: tipc_node_xmit+0x285/0xb30 [tipc]
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0
----
lock(&n->lock#2);
lock(&n->lock#2);
*** DEADLOCK ***
May be due to missing lock nesting notation
4 locks held by conn_server/1086:
#0: ffff8880036d1e40 (sk_lock-AF_TIPC){+.+.}-{0:0}, \
at: tipc_accept+0x9c0/0x10b0 [tipc]
#1: ffff8880036d5f80 (sk_lock-AF_TIPC/1){+.+.}-{0:0}, \
at: tipc_accept+0x363/0x10b0 [tipc]
#2: ffff8880065cd020 (&n->lock#2){++--}-{2:2}, \
at: tipc_node_xmit+0x285/0xb30 [tipc]
#3: ffff888012e13370 (slock-AF_TIPC){+...}-{2:2}, \
at: tipc_sk_rcv+0x2da/0x1b40 [tipc]
Call Trace:
<TASK>
dump_stack_lvl+0x44/0x5b
__lock_acquire.cold.77+0x1f2/0x3d7
lock_acquire+0x1d2/0x610
_raw_write_lock_bh+0x38/0x80
tipc_node_add_conn.cold.76+0xaa/0x211 [tipc]
tipc_sk_finish_conn+0x21e/0x640 [tipc]
tipc_sk_filter_rcv+0x147b/0x3030 [tipc]
tipc_sk_rcv+0xbb4/0x1b40 [tipc]
tipc_lxc_xmit+0x225/0x26b [tipc]
tipc_node_xmit.cold.82+0x4a/0x102 [tipc]
__tipc_sendstream+0x879/0xff0 [tipc]
tipc_accept+0x966/0x10b0 [tipc]
do_accept+0x37d/0x590This patch avoids this warning by not holding the 'node rw lock' before calling tipc_lxc_xmit(). As to protect the 'peer_net', rcu_read_lock() should be enough, as in cleanup_net() when freeing the netns, it calls synchronize_rcu() before the free is continued.
Also since tipc_lxc_xmit() is like the RX path in tipc_rcv(), it makes sense to call it under rcu_read_lock(). Note that the right lock order must be:
rcu_read_lock(); tipc_node_read_lock(n); tipc_node_read_unlock(n); tipc_lxc_xmit(); rcu_read_unlock();
instead of:
tipc_node_read_lock(n); rcu_read_lock(); tipc_node_read_unlock(n); tipc_lxc_xmit(); rcu_read_unlock();
and we have to call tipc_node_read_lock/unlock() twice in tipc_node_xmit().
--- net/tipc/node.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
net/tipc/node.c +9 -3
@@ -1546,6 +1546,7 @@ int tipc_node_xmit(struct net *net, strustruct tipc_node *n;struct sk_buff_head xmitq;bool node_up = false; +struct net *peer_net;int bearer_id;int rc;
@@ -1562,18 +1563,23 @@ int tipc_node_xmit(struct net *net, strureturn -EHOSTUNREACH ; } +rcu_read_lock ();tipc_node_read_lock (n); node_up =node_is_up (n); -if (node_up && n->peer_net &&check_net (n->peer_net)) { + peer_net = n->peer_net; +tipc_node_read_unlock (n); +if (node_up && peer_net &&check_net (peer_net)) {/* xmit inner linux container */ -tipc_lxc_xmit (n->peer_net, list); +tipc_lxc_xmit (peer_net, list);if (likely (skb_queue_empty (list))) { -tipc_node_read_unlock (n); +rcu_read_unlock ();tipc_node_put (n);return 0 ; } } +rcu_read_unlock (); +tipc_node_read_lock (n); bearer_id = n->active_links[selector &1 ];if (unlikely (bearer_id ==INVALID_BEARER_ID )) {tipc_node_read_unlock (n);
Quoted 8 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.4.229 release. There are 658 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Wed, 18 Jan 2023 15:47:28 +0000. Anything received after that time might be too late.
Note: Exactly the same failures are seen in v4.19.269-522-gc75d2b5524ab, so I won't bother sending test results for that branch.
---
Build results:
total: 159 pass: 153 fail: 6 Failed builds: i386:tools/perf riscv:defconfig s390:allnoconfig s390:tinyconfig um:defconfig x86_64:tools/perf Qemu test results: total: 449 pass: 413 fail: 36 Failed tests: <all ppc64:pseries> <all riscv>
Details follow.
Guenter
========
Building i386:tools/perf ... failed
Building x86_64:tools/perf ... failed
--------------
Error log:util/debug.c: In function ‘perf_quiet_option’:util/debug.c:237:2: error: ‘debug_peo_args’ undeclared
Building riscv:defconfig ... failed
--------------
Error log:arch/riscv/kernel/stacktrace.c: In function 'walk_stackframe':arch/riscv/kernel/stacktrace.c:58:36: error: 'struct pt_regs' has no member named 'epc'
Building s390:allnoconfig ... failed
Building s390:tinyconfig ... failed
--------------
Error log:
s390-linux-ld: drivers/base/platform.o: in function `devm_platform_get_and_ioremap_resource':
platform.c:(.text+0x594): undefined reference to `devm_ioremap_resource'
s390-linux-ld: platform.c:(.text+0x5c2): undefined reference to `devm_ioremap_resource'
Building um:defconfig ... failed
--------------
Error log:
ld: drivers/base/platform.o: in function `devm_platform_get_and_ioremap_resource':drivers/base/platform.c:82: undefined reference to `devm_ioremap_resource'
Runtime:
Building ppc64:pseries:pseries_defconfig:smp2:net,pcnet:initrd ... running ......R... failed (crashed)
BUG: Kernel NULL pointer dereference at 0x00000000 Faulting instruction address: 0xc000000000046cc8 Oops: Kernel access of bad area, sig: 11 [#1] BE SMP NR_CPUS=2048 NUMA pSeries Modules linked in: CPU: 1 PID: 1 Comm: swapper/0 Not tainted 4.19.270-rc1-00522-gc75d2b5524ab #1 NIP: c000000000046cc8 LR: c000000000046ca4 CTR: 0000000000000000 REGS: c00000003e6878f0 TRAP: 0380 Not tainted (4.19.270-rc1-00522-gc75d2b5524ab) MSR: 8000000002009032 <SF,VEC,EE,ME,IR,DR,RI> CR: 84000882 XER: 00000000
CFAR: c000000000162cf8 IRQMASK: 0
GPR00: c000000000046ca4 c00000003e687b70 c000000001772000 0000000000000000
GPR04: 0000000000000001 0000000000000001 c00000003e687990 00000000bc24d52c
GPR08: 0000000000000000 0000000000000000 0000000000000000 0000000000000003
GPR12: 0000000024000882 c00000003ffff300 c000000000010e34 0000000000000000
GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR20: 0000000000000000 0000000000000000 c00000000125eea8 0000000000000001
GPR24: c000000001379cd8 c000000001419f20 c0000000017b7d68 c0000000017b7d68
GPR28: 0000000000000000 0000000000000002 c00000000160efe8 c00000000168ac60 NIP [c000000000046cc8] .eeh_init+0x48/0x220
LR [c000000000046ca4] .eeh_init+0x24/0x220
Call Trace: [c00000003e687b70] [c000000000046ca4] .eeh_init+0x24/0x220 (unreliable) [c00000003e687c00] [c00000000001065c] .do_one_initcall+0x7c/0x430 [c00000003e687ce0] [c000000001394db4] .kernel_init_freeable+0x538/0x62c [c00000003e687dc0] [c000000000010e4c] .kernel_init+0x18/0x14c [c00000003e687e30] [c00000000000c0d0] .ret_from_kernel_thread+0x58/0x68 Instruction dump: 3c62ffd7 38631c10 4811c021 60000000 2c030000 408201c8 3d22000b e92904e0 2c290000 41820198 f8410028 e9290008 <e9490000> 7d4903a6 e8490008 4e800421 ---[ end trace 8912d02d3e80c4ae ]---
riscv64 images fail to compile (see above)
Quoted 44 lines · Guenter Roeck
Quoted 8 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.4.229 release. There are 658 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Wed, 18 Jan 2023 15:47:28 +0000. Anything received after that time might be too late.
Note: Exactly the same failures are seen in v4.19.269-522-gc75d2b5524ab, so I won't bother sending test results for that branch.
---
Build results:
total: 159 pass: 153 fail: 6 Failed builds: i386:tools/perf riscv:defconfig s390:allnoconfig s390:tinyconfig um:defconfig x86_64:tools/perf Qemu test results: total: 449 pass: 413 fail: 36 Failed tests: <all ppc64:pseries> <all riscv>Details follow.
Guenter
========
Building i386:tools/perf ... failed
Building x86_64:tools/perf ... failed
--------------
Error log:util/debug.c: In function ‘perf_quiet_option’:util/debug.c:237:2: error: ‘debug_peo_args’ undeclared
Quoted 5 lines
Building riscv:defconfig ... failed
--------------
Error log:arch/riscv/kernel/stacktrace.c: In function 'walk_stackframe':arch/riscv/kernel/stacktrace.c:58:36: error: 'structpt_regs' has no member named 'epc'
The above build error is caused due to, riscv/stacktrace: Fix stack output without ra on the stack top
Quoted 9 lines
Building s390:allnoconfig ... failed
Building s390:tinyconfig ... failed
--------------
Error log:
s390-linux-ld:drivers/base/platform.o: in function `devm_platform_get_and_ioremap_resource':
platform.c:(.text+0x594): undefined reference to `devm_ioremap_resource'
s390-linux-ld: platform.c:(.text+0x5c2): undefined reference to `devm_ioremap_resource'
Quoted 5 lines
Building um:defconfig ... failed
--------------
Error log:
ld:drivers/base/platform.o: in function `devm_platform_get_and_ioremap_resource':drivers/base/platform.c:82: undefined reference to `devm_ioremap_resource'
Linaro test farm also noticed above listed build errors
+ x86_64 clang-nightly deconfig, allnoconfig and tinyconfig.
arch/x86/kernel/fpu/init.c:181:2: error: 'struct (unnamed at arch/x86/kernel/fpu/init.c:181:2)' cannot be defined in '__builtin_offsetof'
CHECK_MEMBER_AT_END_OF(struct fpu, state);
^--
Linaro LKFT
https://lkft.linaro.org
Greg Kroah-Hartman
maintainerQuoted 34 lines · Guenter Roeck
Quoted 8 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.4.229 release. There are 658 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Wed, 18 Jan 2023 15:47:28 +0000. Anything received after that time might be too late.
Note: Exactly the same failures are seen in v4.19.269-522-gc75d2b5524ab, so I won't bother sending test results for that branch.
---
Build results:
total: 159 pass: 153 fail: 6 Failed builds: i386:tools/perf riscv:defconfig s390:allnoconfig s390:tinyconfig um:defconfig x86_64:tools/perf Qemu test results: total: 449 pass: 413 fail: 36 Failed tests: <all ppc64:pseries> <all riscv>Details follow.
Guenter
Quoted 8 lines
========
Building i386:tools/perf ... failed
Building x86_64:tools/perf ... failed
--------------
Error log:util/debug.c: In function ‘perf_quiet_option’:util/debug.c:237:2: error: ‘debug_peo_args’ undeclared
Offending commit now dropped.
Quoted 5 lines
Building riscv:defconfig ... failed
--------------
Error log:arch/riscv/kernel/stacktrace.c: In function 'walk_stackframe':arch/riscv/kernel/stacktrace.c:58:36: error: 'structpt_regs' has no member named 'epc'
Patch dropped.
Quoted 9 lines
Building s390:allnoconfig ... failed
Building s390:tinyconfig ... failed
--------------
Error log:
s390-linux-ld:drivers/base/platform.o: in function `devm_platform_get_and_ioremap_resource':
platform.c:(.text+0x594): undefined reference to `devm_ioremap_resource'
s390-linux-ld: platform.c:(.text+0x5c2): undefined reference to `devm_ioremap_resource'
Quoted 5 lines
Building um:defconfig ... failed
--------------
Error log:
ld:drivers/base/platform.o: in function `devm_platform_get_and_ioremap_resource':drivers/base/platform.c:82: undefined reference to `devm_ioremap_resource'
Same patches now dropped.
Quoted 25 lines
Runtime:
Building ppc64:pseries:pseries_defconfig:smp2:net,pcnet:initrd ... running ......R... failed (crashed)
BUG: Kernel NULL pointer dereference at 0x00000000 Faulting instruction address: 0xc000000000046cc8 Oops: Kernel access of bad area, sig: 11 [#1] BE SMP NR_CPUS=2048 NUMA pSeries Modules linked in: CPU: 1 PID: 1 Comm: swapper/0 Not tainted 4.19.270-rc1-00522-gc75d2b5524ab #1 NIP: c000000000046cc8 LR: c000000000046ca4 CTR: 0000000000000000 REGS: c00000003e6878f0 TRAP: 0380 Not tainted (4.19.270-rc1-00522-gc75d2b5524ab) MSR: 8000000002009032 <SF,VEC,EE,ME,IR,DR,RI> CR: 84000882 XER: 00000000CFAR:
c000000000162cf8IRQMASK: 0
GPR00:c000000000046ca4c00000003e687b70c0000000017720000000000000000000
GPR04: 0000000000000001 0000000000000001c00000003e68799000000000bc24d52c
GPR08: 0000000000000000 0000000000000000 0000000000000000 0000000000000003
GPR12: 0000000024000882c00000003ffff300c000000000010e340000000000000000
GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR20: 0000000000000000 0000000000000000c00000000125eea80000000000000001
GPR24:c000000001379cd8c000000001419f20c0000000017b7d68c0000000017b7d68
GPR28: 0000000000000000 0000000000000002c00000000160efe8c00000000168ac60NIP [c000000000046cc8] .eeh_init+0x48/0x220
LR [c000000000046ca4] .eeh_init+0x24/0x220
Quoted 10 lines
Call Trace: [c00000003e687b70] [c000000000046ca4] .eeh_init+0x24/0x220 (unreliable) [c00000003e687c00] [c00000000001065c] .do_one_initcall+0x7c/0x430 [c00000003e687ce0] [c000000001394db4] .kernel_init_freeable+0x538/0x62c [c00000003e687dc0] [c000000000010e4c] .kernel_init+0x18/0x14c [c00000003e687e30] [c00000000000c0d0] .ret_from_kernel_thread+0x58/0x68 Instruction dump: 3c62ffd7 38631c10 4811c021 60000000 2c030000 408201c8 3d22000b e92904e0 2c290000 41820198 f8410028 e9290008 <e9490000> 7d4903a6 e8490008 4e800421 ---[ end trace 8912d02d3e80c4ae ]---
This is odd, and I don't know how to track that down. Any hints?
thanks,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 36 lines · Greg Kroah-Hartman
Quoted 24 lines · Guenter Roeck
Runtime:
Building ppc64:pseries:pseries_defconfig:smp2:net,pcnet:initrd ... running ......R... failed (crashed)
BUG: Kernel NULL pointer dereference at 0x00000000 Faulting instruction address: 0xc000000000046cc8 Oops: Kernel access of bad area, sig: 11 [#1] BE SMP NR_CPUS=2048 NUMA pSeries Modules linked in: CPU: 1 PID: 1 Comm: swapper/0 Not tainted 4.19.270-rc1-00522-gc75d2b5524ab #1 NIP: c000000000046cc8 LR: c000000000046ca4 CTR: 0000000000000000 REGS: c00000003e6878f0 TRAP: 0380 Not tainted (4.19.270-rc1-00522-gc75d2b5524ab) MSR: 8000000002009032 <SF,VEC,EE,ME,IR,DR,RI> CR: 84000882 XER: 00000000CFAR:
c000000000162cf8IRQMASK: 0
GPR00:c000000000046ca4c00000003e687b70c0000000017720000000000000000000
GPR04: 0000000000000001 0000000000000001c00000003e68799000000000bc24d52c
GPR08: 0000000000000000 0000000000000000 0000000000000000 0000000000000003
GPR12: 0000000024000882c00000003ffff300c000000000010e340000000000000000
GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR20: 0000000000000000 0000000000000000c00000000125eea80000000000000001
GPR24:c000000001379cd8c000000001419f20c0000000017b7d68c0000000017b7d68
GPR28: 0000000000000000 0000000000000002c00000000160efe8c00000000168ac60NIP [c000000000046cc8] .eeh_init+0x48/0x220
LR [c000000000046ca4] .eeh_init+0x24/0x220Quoted 10 lines
Call Trace: [c00000003e687b70] [c000000000046ca4] .eeh_init+0x24/0x220 (unreliable) [c00000003e687c00] [c00000000001065c] .do_one_initcall+0x7c/0x430 [c00000003e687ce0] [c000000001394db4] .kernel_init_freeable+0x538/0x62c [c00000003e687dc0] [c000000000010e4c] .kernel_init+0x18/0x14c [c00000003e687e30] [c00000000000c0d0] .ret_from_kernel_thread+0x58/0x68 Instruction dump: 3c62ffd7 38631c10 4811c021 60000000 2c030000 408201c8 3d22000b e92904e0 2c290000 41820198 f8410028 e9290008 <e9490000> 7d4903a6 e8490008 4e800421 ---[ end trace 8912d02d3e80c4ae ]---
Quoted 1 line
This is odd, and I don't know how to track that down. Any hints?
Let me pull out some powerpc patches that are in this area and push out a -rc2 to see if that resolves the issue.
thanks,
greg k-h
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.4.229 release. There are 658 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Wed, 18 Jan 2023 15:47:28 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 9 lines
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.4.229-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.4.y
and the diffstat can be found below.thanks,
greg k-h
Compiled and booted on my test system. No dmesg regressions.
thanks,
-- Shuah
Hi Greg,
Quoted 7 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.4.229 release. There are 658 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Wed, 18 Jan 2023 15:47:28 +0000. Anything received after that time might be too late.
Build test (gcc version 11.3.1 20221127):
mips: 65 configs -> no failure
arm: 106 configs -> no failure
arm64: 2 configs -> no failurex86_64: 4 configs -> no failure
alpha allmodconfig -> no failure
powerpc allmodconfig -> no failure
riscv allmodconfig -> fails
s390 allmodconfig -> no failure
xtensa allmodconfig -> no failure
Note:
riscv build fails with the error (same error as v4.19.270-rc1) arch/riscv/kernel/stacktrace.c: In function 'walk_stackframe':arch/riscv/kernel/stacktrace.c:66:36: error: 'struct pt_regs' has no member named 'epc'; did you mean 'sepc'?
66 | if (regs && (regs->epc == pc) && (frame->fp & 0x7)) {
| ^~~
Boot test:x86_64: Booted on my test laptop. No regression.x86_64: Booted on qemu. No regression. [1]
[1]. https://openqa.qa.codethink.co.uk/tests/2660
Signature · 2 lines
Regards Sudip