6.12.114-rc1 review
Subsystems (5)
Greg Kroah-Hartman
maintainerPATCH 514/869 btrfs: lzo: reject inline extents without valid headers
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Lee <[email protected]>
[ Upstream commit 0fa78ef637deb5dbe341582f88553a4bce496de0 ]
[BUG]
For a crafted btrfs image, the following KASAN can be triggered when reading an inline lzo compressed file extent:
BUG: KASAN: slab-out-of-bounds in lzo_decompress+0x57d/0x700 Read of size 4 at addr ffff888006f2e644 by task btrfs_lzo_inlin/77 Call Trace: <TASK> dump_stack_lvl+0x5b/0x70 print_report+0xd1/0x610 kasan_report+0xe0/0x110 __asan_report_load_n_noabort+0x13/0x20 lzo_decompress+0x57d/0x700 btrfs_decompress+0x140/0x1c0 uncompress_inline+0x147/0x1b0 btrfs_get_extent+0xb23/0x10a0 btrfs_do_readpage.constprop.0+0x538/0x1ac0 btrfs_readahead+0x32f/0x5f0 read_pages+0x16f/0x850 page_cache_ra_unbounded+0x296/0x490 do_page_cache_ra+0xd9/0x130 page_cache_sync_ra+0x3ee/0x6f0 filemap_get_pages+0x306/0x15c0 filemap_read+0x329/0xd00 btrfs_file_read_iter+0x1f8/0x2b0 vfs_read+0x4ef/0x720 ksys_read+0xf8/0x1d0 __x64_sys_read+0x71/0xb0 x64_sys_call+0x1ab0/0x1b70 do_syscall_64+0x61/0x470 entry_SYSCALL_64_after_hwframe+0x4b/0x53 </TASK>
[CAUSE]
For an inline lzo compressed file extent, there should always be one lzo header, recording the total length of the compressed data, followed by one segment header, recording the compressed lzo payload.
But if a crafted inline lzo compressed file extent contains only an lzo header, without the segment header or payload, lzo_decompress() will still try to read the segment header, causing a read beyond the item boundary.
Furthermore if the inline lzo compressed file extent is the first item of the leaf, it will be at the extent buffer boundary. The above out-of-boundary read will go beyond the extent buffer boundary, triggering the above KASAN report.
[FIX]
Validate the total length of the inlined lzo compressed file extent, to make sure there is at least one LZO header and one segment header, and a non-zero payload.
--- fs/btrfs/lzo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/lzo.c +1 -1
@@ -449,7 +449,7 @@ int lzo_decompress(struct list_head *ws, const u8 *data_in,size_t max_segment_len =WORKSPACE_BUF_LENGTH ;int ret =0 ; -if (srclen <LZO_LEN || srclen > max_segment_len +LZO_LEN *2 ) +if (srclen <=LZO_LEN *2 || srclen > max_segment_len +LZO_LEN *2 )return -EUCLEAN ; in_len =read_compress_length (data_in);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 515/869 xfs: handle NULL b_addr in xfs_buf_free
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yun Zhou <[email protected]>
[ Upstream commit d852729c5f4f830fbe7413df032e29459b3daf83 ]
When xfs_buf_alloc_backing_mem() fails, xfs_buf_free() is called with bp->b_addr still NULL. The code falls through to the folio_put path which calls virt_to_folio(NULL), dereferencing an invalid address and causing a kernel crash.
Call Trace: xfs_buf_free+0x25f/0x510 xfs_buf_alloc+0xc98/0x19b0 xfs_buf_find_insert+0x55/0x14d0 xfs_buf_get_map+0x122b/0x17c0 xfbtree_init_leaf_block+0x11c/0x4a0 xfbtree_init+0x1bb/0x460 xrep_rmap_setup_scan+0x100/0x1f0 xrep_rmapbt+0x41/0xc0
Fix this by skipping folio_put() when bp->b_addr is NULL.
--- fs/xfs/xfs_buf.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
fs/xfs/xfs_buf.c +6 -4
@@ -319,12 +319,14 @@ xfs_buf_free(ASSERT (list_empty (&bp->b_lru)); -if (xfs_buftarg_is_mem (bp->b_target)) -xmbuf_unmap_page (bp); -else if (bp->b_flags & _XBF_PAGES) +if (xfs_buftarg_is_mem (bp->b_target)) { +if (bp->b_addr) +xmbuf_unmap_page (bp); + }else if (bp->b_flags & _XBF_PAGES) {xfs_buf_free_pages (bp); -else if (bp->b_flags & _XBF_KMEM) + }else if (bp->b_flags & _XBF_KMEM) {kfree (bp->b_addr); + }call_rcu (&bp->b_rcu, xfs_buf_free_callback); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 516/869 soc: aspeed: lpc-snoop: Fix usercopy overflow in snoop_file_read
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karthikeyan KS <[email protected]>
[ Upstream commit 1acef6d85bfd98bd9dfe1f08bffa397a4dda8a6f ]
put_fifo_with_discard() acts as both producer and consumer on the kfifo:
it calls kfifo_skip() (advances out) and kfifo_put() (advances in) from the IRQ handler without synchronizing with snoop_file_read(), which also consumes via kfifo_to_user(). On SMP systems this concurrent access can leave (in - out) larger than the ring buffer, so __kfifo_to_user()'s clamp to (in - out) is ineffective and kfifo_copy_to_user() can attempt a copy_to_user() past the kmalloc-2k backing store:
usercopy: Kernel memory exposure attempt detected from SLUB object 'kmalloc-2k' (offset 0, size 2049)!
kernel BUG at mm/usercopy.c!
Call trace: usercopy_abort __check_heap_object __check_object_size kfifo_copy_to_user __kfifo_to_user snoop_file_read vfs_read
Serialize kfifo access with a per-channel spinlock shared between the IRQ handler (producer) and the file reader (consumer). Annotate @fifo with __guarded_by(&lock) and opt the driver into context analysis so the compiler enforces that all fifo access holds the lock.
--- drivers/soc/aspeed/aspeed-lpc-snoop.c | 31 ++++++++++++++++++++------- 1 file changed, 23 insertions(+), 8 deletions(-)
drivers/soc/aspeed/aspeed-lpc-snoop.c +23 -8
@@ -11,6 +11,7 @@*/ #include <linux/bitops.h> +#include <linux/cleanup.h> #include <linux/clk.h> #include <linux/interrupt.h> #include <linux/fs.h>
@@ -59,6 +60,7 @@ struct aspeed_lpc_snoop_model_data {struct aspeed_lpc_snoop_channel {bool enabled; +spinlock_t lock;struct kfifo fifo;wait_queue_head_t wq;struct miscdevice miscdev;
@@ -82,6 +84,7 @@ static ssize_t snoop_file_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos) { struct aspeed_lpc_snoop_channel *chan = snoop_file_to_chan(file); + u8 *buf __free(kfree) = NULL;unsigned int copied;int ret =0 ;
@@ -93,9 +96,16 @@ static ssize_t snoop_file_read(struct file *file, char __user *buffer,if (ret == -ERESTARTSYS )return -EINTR ; } - ret =kfifo_to_user (&chan->fifo, buffer, count, &copied); -if (ret) -return ret; + + count =min_t (size_t, count,SNOOP_FIFO_SIZE ); + + buf =kmalloc (count,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + + copied =kfifo_out_spinlocked (&chan->fifo, buf, count, &chan->lock); +if (copied &©_to_user (buffer, buf, copied)) +return -EFAULT ;return copied; }
@@ -119,11 +129,13 @@ static const struct file_operations snoop_fops = {/* Save a byte to a FIFO and discard the oldest byte if FIFO is full */ static void put_fifo_with_discard (struct aspeed_lpc_snoop_channel *chan,u8 val) { -if (!kfifo_initialized (&chan->fifo)) -return ; -if (kfifo_is_full (&chan->fifo)) -kfifo_skip (&chan->fifo); -kfifo_put (&chan->fifo, val); + scoped_guard(spinlock, &chan->lock) { +if (!kfifo_initialized (&chan->fifo)) +return ; +if (kfifo_is_full (&chan->fifo)) +kfifo_skip (&chan->fifo); +kfifo_put (&chan->fifo, val); + }wake_up_interruptible (&chan->wq); }
@@ -292,6 +304,9 @@ static int aspeed_lpc_snoop_probe(struct platform_device *pdev)if (!lpc_snoop)return -ENOMEM ; +spin_lock_init (&lpc_snoop->chan[0 ].lock); +spin_lock_init (&lpc_snoop->chan[1 ].lock); + np = pdev->dev.parent->of_node; if (!of_device_is_compatible(np, "aspeed,ast2400-lpc-v2") && !of_device_is_compatible(np, "aspeed,ast2500-lpc-v2") &&
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 517/869 gpio: pca953x: fix pca953x_irq_bus_sync_unlock regmap lock
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Tomlinson <[email protected]>
[ Upstream commit 9dc325327babe7f159e84cbe9380a45342da0585 ]
Locking is disabled in the regmap config as this driver uses its own lock. This means that all calls to regmap functions (read or write) must hold the i2c_lock. The function pca953x_irq_bus_sync_unlock() did not do this, and it was therefore possible that multiple threads could cause an incorrect register to be read/written.
A previous patch partly fixed this, but only protected the write to the interrupt mask register, and not the read from the direction register.
--- drivers/gpio/gpio-pca953x.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/gpio/gpio-pca953x.c +13 -5
@@ -525,15 +525,23 @@ static int pca953x_read_regs(struct pca953x_chip *chip, int reg, unsigned long *return 0 ; } -static int pca953x_gpio_direction_input (struct gpio_chip *gc,unsigned off) +static int pca953x_gpio_direction_input_unlocked (struct gpio_chip *gc, +unsigned int off) {struct pca953x_chip *chip =gpiochip_get_data (gc);u8 dirreg = chip->recalc_addr (chip, chip->regs->direction, off);u8 bit =BIT (off %BANK_SZ ); +return regmap_write_bits (chip->regmap, dirreg, bit, bit); +} + +static int pca953x_gpio_direction_input (struct gpio_chip *gc,unsigned int off) +{ +struct pca953x_chip *chip =gpiochip_get_data (gc); +guard (mutex)(&chip->i2c_lock); -return regmap_write_bits (chip->regmap, dirreg, bit, bit); +return pca953x_gpio_direction_input_unlocked (gc, off); } static int pca953x_gpio_direction_output(struct gpio_chip *gc,
@@ -759,9 +767,9 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d)DECLARE_BITMAP (reg_direction,MAX_LINE );int level; -if (chip->driver_data &PCA_PCAL ) { -guard (mutex)(&chip->i2c_lock); +guard (mutex)(&chip->i2c_lock); +if (chip->driver_data &PCA_PCAL ) {/* Enable latch on interrupt-enabled inputs */ pca953x_write_regs (chip,PCAL953X_IN_LATCH , chip->irq_mask);
@@ -782,7 +790,7 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d)/* Look for any newly setup interrupt */ for_each_set_bit (level, irq_mask, gc->ngpio) -pca953x_gpio_direction_input (&chip->gpio_chip, level); +pca953x_gpio_direction_input_unlocked (&chip->gpio_chip, level);mutex_unlock (&chip->irq_lock); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 518/869 firewire: ohci: fix NULL pointer dereference in ar_context_release
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aleksandr Nogikh <[email protected]>
[ Upstream commit 42d217add8d80d6e7d9f58f80d11ea9b07ea113e ]
During the error handling path of the driver's probe function, a NULL pointer dereference can occur in ar_context_release().
When pci_probe() fails early (e.g., if pcim_enable_device() or MMIO mapping fails), the devres cleanup mechanism invokes release_ohci(). This function unconditionally calls ar_context_release() to clean up the asynchronous receive contexts. However, if ar_context_init() was not yet called, ctx->ohci remains NULL (as the fw_ohci structure is zero-initialized by devres_alloc()).
ar_context_release() immediately dereferences ctx->ohci to get the dev pointer before checking if the context was actually initialized, leading to a crash:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000001: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f] RIP: 0010:ar_context_release+0x3f/0x380 drivers/firewire/ohci.c:543 Call Trace: release_ohci+0x3f/0x60 drivers/firewire/ohci.c:3567 release_nodes drivers/base/devres.c:546 [inline] devres_release_all+0x1a8/0x260 drivers/base/devres.c:576 device_unbind_cleanup drivers/base/dd.c:597 [inline] really_probe+0x451/0xae0 drivers/base/dd.c:772
To fix this, move the assignment of the dev pointer after the !ctx->buffer check. If ctx->buffer is NULL, it indicates that the context was never successfully initialized and there is nothing to release, safely avoiding the dereference of the uninitialized ctx->ohci pointer.
--- drivers/firewire/ohci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/firewire/ohci.c +3 -1
@@ -753,12 +753,14 @@ static void ar_context_link_page(struct ar_context *ctx, unsigned int index)static void ar_context_release (struct ar_context *ctx) { -struct device *dev = ctx->ohci->card.device; +struct device *dev;unsigned int i;if (!ctx->buffer)return ; + dev = ctx->ohci->card.device; +vunmap (ctx->buffer);for (i =0 ; i <AR_BUFFERS ; i++) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 519/869 ipvs: revalidate ihl to prevent out-of-bounds access
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julian Anastasov <[email protected]>
[ Upstream commit d93660df4dd1d116f608ada4a29a80a5d6f0a6ed ]
While the outer IP header is already pulled into the skb head, we must be careful and revalidate the embedded headers after reading them from the skb frags to prevent out-of-bounds access.
One such place reported by Sashiko is ip_vs_nat_icmp() where local process can change the ihl field and after skb_ensure_writable() we can see larger value which is a problem for the ip_send_check(cih) calls.
Add check to drop the packet if the ihl field is changed.
--- include/net/ip_vs.h | 2 +- net/netfilter/ipvs/ip_vs_core.c | 11 +++++++++-- net/netfilter/ipvs/ip_vs_xmit.c | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-)
include/net/ip_vs.h +1 -1
@@ -1713,7 +1713,7 @@ static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)return fwd; } -void ip_vs_nat_icmp (struct sk_buff *skb,struct ip_vs_protocol *pp, +bool ip_vs_nat_icmp (struct sk_buff *skb,struct ip_vs_protocol *pp,struct ip_vs_conn *cp,int dir,unsigned int toff,bool has_ports,struct ip_vs_iphdr *ciph);
net/netfilter/ipvs/ip_vs_core.c +9 -2
@@ -745,7 +745,7 @@ static int ip_vs_route_me_harder(struct netns_ipvs *ipvs, int af,* Packet has been made sufficiently writable in caller * - inout: 1=in->out, 0=out->in */ -void ip_vs_nat_icmp (struct sk_buff *skb,struct ip_vs_protocol *pp, +bool ip_vs_nat_icmp (struct sk_buff *skb,struct ip_vs_protocol *pp,struct ip_vs_conn *cp,int inout,unsigned int toff,bool has_ports,struct ip_vs_iphdr *ciph) {
@@ -753,6 +753,11 @@ void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,struct icmphdr *icmph = (struct icmphdr *)(skb->data + toff);struct iphdr *cih = (struct iphdr *)(icmph +1 ); +/* Before now we may used ihl from skb frag, revalidate it after +* copying it into skb head to prevent out-of-bounds access +*/ +if (cih->ihl *4 != ciph->len - ciph->off) +return false;if (inout) { iph->saddr = cp->vaddr.ip;ip_send_check (iph);
@@ -786,6 +791,7 @@ void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,else IP_VS_DBG_PKT (11 ,AF_INET , pp, skb, ciph->off,"Forwarding altered incoming ICMP" ); +return true; }#ifdef CONFIG_IP_VS_IPV6
@@ -877,7 +883,8 @@ static int handle_response_icmp(int af, struct sk_buff *skb,ip_vs_nat_icmp_v6 (skb, pp, cp,1 , toff, has_ports, ciph); else#endif -ip_vs_nat_icmp (skb, pp, cp,1 , toff, has_ports, ciph); +if (!ip_vs_nat_icmp (skb, pp, cp,1 , toff, has_ports, ciph)) + goto out;if (ip_vs_route_me_harder (cp->ipvs, af, skb, hooknum)) goto out;
net/netfilter/ipvs/ip_vs_xmit.c +2 -1
@@ -1577,7 +1577,8 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,if (skb_cow (skb, rt->dst.dev->hard_header_len)) goto tx_error; -ip_vs_nat_icmp (skb, pp, cp,0 , toff, has_ports, ciph); +if (!ip_vs_nat_icmp (skb, pp, cp,0 , toff, has_ports, ciph)) + goto tx_error;/* Another hack: avoid icmp_send in ip_fragment */ skb->ignore_df =1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 520/869 sctp: validate cookie AUTH state before use
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit 3dbb44d88b1e94dd31fe43588af7437b34b44d56 ]
When cookie authentication is disabled, COOKIE_ECHO restores fixed-size AUTH fields directly from peer-controlled cookie bytes. A forged RANDOM length, HMAC list, or CHUNKS list can then reach association consumers with lengths or identifiers that were never validated against the local backing arrays.
A forged RANDOM length can cause out-of-bounds reads during key-vector construction. A forged HMAC identifier also caused a 32-byte write past a zero-length AUTH chunk, providing a primitive for a local privilege escalation chain.
Validate the cookie's RANDOM, HMACS, and CHUNKS parameters at the cookie trust boundary before copying them into the association. Reject invalid types, malformed lengths, unsupported HMAC identifiers, HMAC lists without SHA1, and forbidden chunk ids.
--- include/net/sctp/auth.h | 3 ++ net/sctp/auth.c | 76 ++++++++++++++++++++++++++++++++++++++++ net/sctp/sm_make_chunk.c | 3 ++ 3 files changed, 82 insertions(+)
include/net/sctp/auth.h +3 -0
@@ -23,6 +23,7 @@ struct sctp_association;struct sctp_authkey ;struct sctp_hmacalgo ;struct crypto_shash ; +struct sctp_cookie ;/* * Define a generic struct that will hold all the info
@@ -81,6 +82,8 @@ int sctp_auth_init_hmacs(struct sctp_endpoint *ep, gfp_t gfp);void sctp_auth_destroy_hmacs (struct crypto_shash *auth_hmacs[]);struct sctp_hmac *sctp_auth_get_hmac (__u16 hmac_id);struct sctp_hmac *sctp_auth_asoc_get_hmac (const struct sctp_association *asoc); +bool sctp_auth_verify_cookie_params (const struct sctp_endpoint *ep, +const struct sctp_cookie *cookie);void sctp_auth_asoc_set_default_hmac (struct sctp_association *asoc,struct sctp_hmac_algo_param *hmacs); int sctp_auth_asoc_verify_hmac_id(const struct sctp_association *asoc,
net/sctp/auth.c +76 -0
82 lines not on this page · raw message
net/sctp/sm_make_chunk.c +3 -0
@@ -1883,6 +1883,9 @@ struct sctp_association *sctp_unpack_cookie(/* Set up our peer's port number. */ retval->peer.port =ntohs (chunk->sctp_hdr->source); +if (!sctp_auth_verify_cookie_params (ep, bear_cookie)) + goto malformed; +/* Populate the association from the cookie. */ memcpy (&retval->c, bear_cookie,sizeof (*bear_cookie));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 521/869 scsi: core: pair EH runtime PM get and put
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongjie Fang <[email protected]>
[ Upstream commit 872f486259ae0bc6b73ca4735a15d013241f73e9 ]
shost->eh_noresume is currently consulted twice in one error handling
iteration: once before scsi_autopm_get_host() and once again before scsi_autopm_put_host().
That is racy when a PM-triggered error path flips shost->eh_noresume while the SCSI EH thread is still running.
The problem flow looks like this:
PM path
ufshcd_set_dev_pwr_mode()
shost->eh_noresume = 1
ufshcd_execute_start_stop <-- trigger EH
...
shost->eh_noresume = 0EH path
scsi_error_handler()
if (!shost->eh_noresume)
scsi_autopm_get_host() <-- skipped
...
if (!shost->eh_noresume)
scsi_autopm_put_host() <-- executed laterIn that case one EH iteration can skip autoresume on entry and still drop a runtime PM reference on exit. That leaves an unmatched runtime PM put and can trigger a runtime PM usage count underflow.
Fix this by making eh_noresume a regular bool so it can be accessed with READ_ONCE() and WRITE_ONCE(). Snapshot it once per EH iteration and use that snapshot for both runtime PM get and put decisions.
--- drivers/scsi/scsi_error.c | 6 ++++-- drivers/ufs/core/ufshcd.c | 4 ++-- include/scsi/scsi_host.h | 7 ++++--- 3 files changed, 10 insertions(+), 7 deletions(-)
drivers/scsi/scsi_error.c +4 -2
@@ -2338,6 +2338,7 @@ static void scsi_unjam_host(struct Scsi_Host *shost)int scsi_error_handler (void *data) {struct Scsi_Host *shost = data; +bool eh_noresume;/* * We use TASK_INTERRUPTIBLE so that the thread is not
@@ -2379,7 +2380,8 @@ int scsi_error_handler(void *data)* what we need to do to get it up and online again (if we can). * If we fail, we end up taking the thing offline. */ -if (!shost->eh_noresume &&scsi_autopm_get_host (shost) !=0 ) { + eh_noresume =READ_ONCE (shost->eh_noresume); +if (!eh_noresume &&scsi_autopm_get_host (shost) !=0 ) { SCSI_LOG_ERROR_RECOVERY(1, shost_printk(KERN_ERR, shost, "scsi_eh_%d: unable to autoresume\n",
@@ -2403,7 +2405,7 @@ int scsi_error_handler(void *data)* which are still online. */ scsi_restart_operations (shost); -if (!shost->eh_noresume) +if (!eh_noresume)scsi_autopm_put_host (shost); }__set_current_state (TASK_RUNNING );
drivers/ufs/core/ufshcd.c +2 -2
@@ -9561,7 +9561,7 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,* we are functional while we are here, skip host resume in error * handling context. */ - hba->host->eh_noresume =1 ; +WRITE_ONCE (hba->host->eh_noresume,1 );/* * Current function would be generally called from the power management
@@ -9583,7 +9583,7 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba, }scsi_device_put (sdp); - hba->host->eh_noresume =0 ; +WRITE_ONCE (hba->host->eh_noresume,0 );return ret; }
include/scsi/scsi_host.h +4 -3
@@ -633,6 +633,10 @@ struct Scsi_Host {*/ unsigned nr_hw_queues;unsigned nr_maps; + +/* Don't resume host in EH */ +bool eh_noresume; + unsigned active_mode:2;/*
@@ -654,9 +658,6 @@ struct Scsi_Host {/* Asynchronous scan in progress */ unsigned async_scan:1; -/* Don't resume host in EH */ - unsigned eh_noresume:1; -/* The controller does not support WRITE SAME */ unsigned no_write_same:1;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 522/869 ASoC: SOF: Relocate and rework functionality for PCM stream freeing
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
[ Upstream commit 169ec0a541aac8afb215ab591b0fd53276686014 ]
Move the sof_pcm_stream_free() from sof-audio.c to pcm.c as static function and add wrapper to free all active stream, which is going to be used in ipc3/4 topology code (removes duplicated code).
With this change most of the PCM stream related code is located in one source file for easier lookup and simplified flow.
Stable-dep-of: 17661c67b206 ("ASoC: SOF: ipc4-pcm: Continue the pipeline trigger in case of IPC timeout")
--- sound/soc/sof/ipc3-topology.c | 20 ++------- sound/soc/sof/ipc4-topology.c | 18 +------- sound/soc/sof/pcm.c | 78 +++++++++++++++++++++++++++++++++++ sound/soc/sof/sof-audio.c | 49 ---------------------- sound/soc/sof/sof-audio.h | 3 +- 5 files changed, 84 insertions(+), 84 deletions(-)
sound/soc/sof/ipc3-topology.c +4 -16
@@ -2386,28 +2386,16 @@ static int sof_ipc3_set_up_all_pipelines(struct snd_sof_dev *sdev, bool verify)static int sof_tear_down_left_over_pipelines (struct snd_sof_dev *sdev) {struct snd_sof_widget *swidget; -struct snd_sof_pcm *spcm; -int dir, ret; +int ret;/* * free all PCMs and their associated DAPM widgets if their connected DAPM widget * list is not NULL. This should only be true for paused streams at this point. * This is equivalent to the handling of FE DAI suspend trigger for running streams. */ -list_for_each_entry (spcm, &sdev->pcm_list, list) { -for_each_pcm_streams (dir) { -struct snd_pcm_substream *substream = spcm->stream[dir].substream; - -if (!substream || !substream->runtime || spcm->stream[dir].suspend_ignored) -continue ; - -if (spcm->stream[dir].list) { - ret =sof_pcm_stream_free (sdev, substream, spcm, dir, true); -if (ret <0 ) -return ret; - } - } - } + ret =sof_pcm_free_all_streams (sdev); +if (ret) +return ret;/* * free any left over DAI widgets. This is equivalent to the handling of suspend trigger
sound/soc/sof/ipc4-topology.c +1 -17
@@ -3345,9 +3345,6 @@ static int sof_ipc4_dai_get_param(struct snd_sof_dev *sdev, struct snd_sof_dai *static int sof_ipc4_tear_down_all_pipelines (struct snd_sof_dev *sdev,bool verify) { -struct snd_sof_pcm *spcm; -int dir, ret; -/* * This function is called during system suspend, we need to make sure * that all streams have been freed up.
@@ -3359,21 +3356,8 @@ static int sof_ipc4_tear_down_all_pipelines(struct snd_sof_dev *sdev, bool verif* * This will also make sure that paused streams handled correctly. */ -list_for_each_entry (spcm, &sdev->pcm_list, list) { -for_each_pcm_streams (dir) { -struct snd_pcm_substream *substream = spcm->stream[dir].substream; - -if (!substream || !substream->runtime || spcm->stream[dir].suspend_ignored) -continue ; -if (spcm->stream[dir].list) { - ret =sof_pcm_stream_free (sdev, substream, spcm, dir, true); -if (ret <0 ) -return ret; - } - } - } -return 0 ; +return sof_pcm_free_all_streams (sdev); }static int sof_ipc4_link_setup (struct snd_sof_dev *sdev,struct snd_soc_dai_link *link)
sound/soc/sof/pcm.c +78 -0
84 lines not on this page · raw message
sound/soc/sof/sof-audio.c +0 -49
55 lines not on this page · raw message
sound/soc/sof/sof-audio.h +1 -2
@@ -648,8 +648,7 @@ int sof_widget_list_setup(struct snd_sof_dev *sdev, struct snd_sof_pcm *spcm,int sof_widget_list_free (struct snd_sof_dev *sdev,struct snd_sof_pcm *spcm,int dir);int sof_pcm_dsp_pcm_free (struct snd_pcm_substream *substream,struct snd_sof_dev *sdev,struct snd_sof_pcm *spcm); -int sof_pcm_stream_free (struct snd_sof_dev *sdev,struct snd_pcm_substream *substream, -struct snd_sof_pcm *spcm,int dir,bool free_widget_list); +int sof_pcm_free_all_streams (struct snd_sof_dev *sdev);int get_token_u32 (void *elem,void *object,u32 offset);int get_token_u16 (void *elem,void *object,u32 offset);int get_token_comp_format (void *elem,void *object,u32 offset);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 523/869 ASoC: SOF: pcm: Move period/buffer configuration print after platform open
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
[ Upstream commit 4d2ea16576c8aa1437048cf436bff85653f139fe ]
The platform specific pcm_open call via snd_sof_pcm_platform_open() can modify the initial buffer configuration via constraints.
Move the prints as last step in the sof_pcm_open() function to reflect the final setup.
Stable-dep-of: 17661c67b206 ("ASoC: SOF: ipc4-pcm: Continue the pipeline trigger in case of IPC timeout")
--- sound/soc/sof/pcm.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
sound/soc/sof/pcm.c +13 -11
@@ -536,15 +536,6 @@ static int sof_pcm_open(struct snd_soc_component *component,*/ runtime->hw.buffer_bytes_max =le32_to_cpu (caps->buffer_size_max); -dev_dbg (component->dev,"period min %zd max %zd bytes\n" , - runtime->hw.period_bytes_min, - runtime->hw.period_bytes_max); -dev_dbg (component->dev,"period count %d max %d\n" , - runtime->hw.periods_min, - runtime->hw.periods_max); -dev_dbg (component->dev,"buffer max %zd bytes\n" , - runtime->hw.buffer_bytes_max); -/* set wait time - TODO: come from topology */ substream->wait_time =500 ;
@@ -554,10 +545,21 @@ static int sof_pcm_open(struct snd_soc_component *component, spcm->prepared[substream->stream] = false; ret =snd_sof_pcm_platform_open (sdev, substream); -if (ret <0 ) +if (ret <0 ) {dev_err (component->dev,"error: pcm open failed %d\n" , ret); +return ret; + } -return ret; +dev_dbg (component->dev,"period bytes min %zd, max %zd\n" , + runtime->hw.period_bytes_min, + runtime->hw.period_bytes_max); +dev_dbg (component->dev,"period count min %d, max %d\n" , + runtime->hw.periods_min, + runtime->hw.periods_max); +dev_dbg (component->dev,"buffer bytes max %zd\n" , + runtime->hw.buffer_bytes_max); + +return 0 ; } static int sof_pcm_close(struct snd_soc_component *component,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 524/869 ASoC: SOF: pcm: Add snd_sof_pcm specific wrappers for dev_dbg() and dev_err()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
[ Upstream commit 860693187c597645b28a421d8acb26428b8afd3f ]
Introduce spcm_dbg() and spcm_err() macros to provide consistent printing for debug and error messages which includes usable information in the print's prefix.
Update the prints in pcm.c, ipc3-pcm.c and ipc4-pcm.c to take advantage of the features provided by the macros.
Stable-dep-of: 17661c67b206 ("ASoC: SOF: ipc4-pcm: Continue the pipeline trigger in case of IPC timeout")
--- sound/soc/sof/ipc3-pcm.c | 13 +++--- sound/soc/sof/ipc4-pcm.c | 16 ++++--- sound/soc/sof/pcm.c | 95 +++++++++++++++++---------------------- sound/soc/sof/sof-audio.h | 14 ++++++ 4 files changed, 72 insertions(+), 66 deletions(-)
sound/soc/sof/ipc3-pcm.c +7 -6
@@ -117,22 +117,23 @@ static int sof_ipc3_pcm_hw_params(struct snd_soc_component *component,if (platform_params->cont_update_posn) pcm.params.cont_update_posn =1 ; -dev_dbg (component->dev,"stream_tag %d" , pcm.params.stream_tag); +spcm_dbg (spcm, substream->stream,"stream_tag %d\n" , + pcm.params.stream_tag);/* send hw_params IPC to the DSP */ ret =sof_ipc_tx_message (sdev->ipc, &pcm,sizeof (pcm), &ipc_params_reply,sizeof (ipc_params_reply));if (ret <0 ) { -dev_err (component->dev,"HW params ipc failed for stream %d\n" , - pcm.params.stream_tag); +spcm_err (spcm, substream->stream, +"STREAM_PCM_PARAMS ipc failed for stream_tag %d\n" , + pcm.params.stream_tag);return ret; } ret =snd_sof_set_stream_data_offset (sdev, &spcm->stream[substream->stream], ipc_params_reply.posn_offset);if (ret <0 ) { -dev_err (component->dev,"%s: invalid stream data offset for PCM %d\n" , - __func__, spcm->pcm.pcm_id); +spcm_err (spcm, substream->stream,"invalid stream data offset\n" );return ret; }
@@ -171,7 +172,7 @@ static int sof_ipc3_pcm_trigger(struct snd_soc_component *component, stream.hdr.cmd |=SOF_IPC_STREAM_TRIG_STOP ;break ;default : -dev_err (component->dev,"Unhandled trigger cmd %d\n" , cmd); +spcm_err (spcm, substream->stream,"Unhandled trigger cmd %d\n" , cmd);return -EINVAL ; }
sound/soc/sof/ipc4-pcm.c +9 -7
@@ -324,7 +324,7 @@ static int sof_ipc4_chain_dma_trigger(struct snd_sof_dev *sdev, set_fifo_size = false;break ;default : -dev_err (sdev->dev,"Unexpected state %d" , state); +spcm_err (spcm, direction,"Unexpected pipeline state %d\n" , state);return -EINVAL ; }
@@ -344,8 +344,8 @@ static int sof_ipc4_chain_dma_trigger(struct snd_sof_dev *sdev,struct sof_ipc4_pipeline *pipeline = pipe_widget->private;if (!pipeline->use_chain_dma) { -dev_err (sdev->dev, -"All pipelines in chained DMA stream should have use_chain_dma attribute set." ); +spcm_err (spcm, direction, +"All pipelines in chained DMA path should have use_chain_dma attribute set." );return -EINVAL ; }
@@ -400,12 +400,12 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,int ret;int i; -dev_dbg (sdev->dev,"trigger cmd: %d state: %d\n" , cmd, state); - spcm =snd_sof_find_spcm_dai (component, rtd);if (!spcm)return -EINVAL ; +spcm_dbg (spcm, substream->stream,"cmd: %d, state: %d\n" , cmd, state); + pipeline_list = &spcm->stream[substream->stream].pipeline_list;/* nothing to trigger if the list is empty */
@@ -500,7 +500,7 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,*/ ret =sof_ipc4_set_multi_pipeline_state (sdev,SOF_IPC4_PIPE_PAUSED , trigger_list);if (ret <0 ) { -dev_err (sdev->dev,"failed to pause all pipelines\n" ); +spcm_err (spcm, substream->stream,"failed to pause all pipelines\n" ); goto free; }
@@ -529,7 +529,9 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,/* else set the RUNNING/RESET state in the DSP */ ret =sof_ipc4_set_multi_pipeline_state (sdev, state, trigger_list);if (ret <0 ) { -dev_err (sdev->dev,"failed to set final state %d for all pipelines\n" , state); +spcm_err (spcm, substream->stream, +"failed to set final state %d for all pipelines\n" , + state);/* * workaround: if the firmware is crashed while setting the * pipelines to reset state we must ignore the error code and
sound/soc/sof/pcm.c +42 -53
223 lines not on this page · raw message
sound/soc/sof/sof-audio.h +14 -0
@@ -616,6 +616,20 @@ struct snd_sof_pcm *snd_sof_find_spcm_comp(struct snd_soc_component *scomp,void snd_sof_pcm_period_elapsed (struct snd_pcm_substream *substream);void snd_sof_pcm_init_elapsed_work (struct work_struct *work); +/* +* snd_sof_pcm specific wrappers for dev_dbg() and dev_err() to provide +* consistent and useful prints. +*/ +#define spcm_dbg (__spcm, __dir, __fmt, ...) \ + dev_dbg((__spcm)->scomp->dev, "pcm%u (%s), dir %d: " __fmt, \ + (__spcm)->pcm.pcm_id, (__spcm)->pcm.pcm_name, __dir, \ + ##__VA_ARGS__) + +#define spcm_err (__spcm, __dir, __fmt, ...) \ + dev_err((__spcm)->scomp->dev, "%s: pcm%u (%s), dir %d: " __fmt, \ + __func__, (__spcm)->pcm.pcm_id, (__spcm)->pcm.pcm_name, __dir, \ + ##__VA_ARGS__) +#if IS_ENABLED (CONFIG_SND_SOC_SOF_COMPRESS )void snd_sof_compr_fragment_elapsed (struct snd_compr_stream *cstream);void snd_sof_compr_init_elapsed_work (struct work_struct *work);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 525/869 ASoC: SOF: ipc4-pcm: Continue the pipeline trigger in case of IPC timeout
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
[ Upstream commit 17661c67b206612cb3ba65d5ae726cd2015d0a53 ]
Ignore IPC errors for pipeline state change if the firmware state is crashed or the IPC has timed out.
If the firmware has crashed the kernel still needs to go through the state changes to reset its internal to be able to correctly work the next time the DSP is booted up.
The case with IPC timeout is a bit more problematic, but it has been rootcaused to be the result of system scheduling blockage and the firmware did actually received and handled the message, but the reply handling got blocked by issues outside of the SOF stack.
So far the best way to handle this is to continue with setting the state.
--- sound/soc/sof/ipc4-pcm.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
sound/soc/sof/ipc4-pcm.c +19 -6
@@ -501,7 +501,19 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component, ret =sof_ipc4_set_multi_pipeline_state (sdev,SOF_IPC4_PIPE_PAUSED , trigger_list);if (ret <0 ) {spcm_err (spcm, substream->stream,"failed to pause all pipelines\n" ); - goto free; +/* +* workaround: if the firmware is crashed or the IPC timed out +* while setting the pipeline state we must ignore the error +* code and proceed to set adjust the local pipeline states. +* +* If the firmware is crashed we will not send IPC messages +* and we are going to see errors printed, but the state of the +* widgets will be correct for the next boot. +*/ +if (sdev->fw_state !=SOF_FW_CRASHED && ret != -ETIMEDOUT ) + goto free; + + ret =0 ; }/* update PAUSED state for all pipelines just triggered */
@@ -533,14 +545,15 @@ static int sof_ipc4_trigger_pipelines(struct snd_soc_component *component,"failed to set final state %d for all pipelines\n" , state);/* -* workaround: if the firmware is crashed while setting the -* pipelines to reset state we must ignore the error code and -* reset it to 0. -* Since the firmware is crashed we will not send IPC messages +* workaround: if the firmware is crashed or the IPC timed out +* while setting the pipeline state we must ignore the error +* code and proceed to set adjust the local pipeline states. +* +* If the firmware is crashed we will not send IPC messages * and we are going to see errors printed, but the state of the * widgets will be correct for the next boot. */ -if (sdev->fw_state !=SOF_FW_CRASHED || state !=SOF_IPC4_PIPE_RESET ) +if (sdev->fw_state !=SOF_FW_CRASHED && ret != -ETIMEDOUT ) goto free; ret =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 526/869 tracing/probes: Remove WARN_ON_ONCE from parse_btf_arg
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit 251a8fe1b9aedccd298b77bc28426d564c5a923f ]
Sashiko found that user can cause this WARN_ON_ONCE() easily with adding a kprobe event based on a raw address with BTF parameter.
Since this is not an unexpected condition, remove the WARN_ON_ONCE().
--- kernel/trace/trace_probe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_probe.c +1 -1
@@ -622,7 +622,7 @@ static int parse_btf_arg(char *varname,int i, is_ptr, ret;u32 tid; -if (WARN_ON_ONCE (!ctx->funcname)) +if (!ctx->funcname)return -EINVAL ; is_ptr =split_next_field (varname, &field, ctx);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 527/869 net: ibm: emac: use devm_platform_ioremap_resource
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit c9bf90863df5fc8bae9513ce9bfcc260fad2ea0e ]
No need to have a struct resource. Gets rid of the TODO.
Stable-dep-of: f623d38fe6c4 ("net: emac: Fix NULL pointer dereference in emac_probe")
--- drivers/net/ethernet/ibm/emac/core.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/ethernet/ibm/emac/core.c +3 -5
@@ -3049,12 +3049,10 @@ static int emac_probe(struct platform_device *ofdev) ndev->irq = dev->emac_irq; -/* Map EMAC regs */ -// TODO : platform_get_resource() and devm_ioremap_resource() - dev->emacp =devm_of_iomap (&ofdev->dev, np,0 ,NULL ); -if (!dev->emacp) { + dev->emacp =devm_platform_ioremap_resource (ofdev,0 ); +if (IS_ERR (dev->emacp)) {dev_err (&ofdev->dev,"can't map device registers" ); - err = -ENOMEM ; + err =PTR_ERR (dev->emacp); goto err_gone; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 528/869 net: ibm: emac: use platform_get_irq
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit a598f66d9169312e7eaab8cc7b8f175866e68997 ]
No need for irq_of_parse_and_map since we have platform_device.
Stable-dep-of: f623d38fe6c4 ("net: emac: Fix NULL pointer dereference in emac_probe")
--- drivers/net/ethernet/ibm/emac/core.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/net/ethernet/ibm/emac/core.c +1 -8
@@ -3030,15 +3030,8 @@ static int emac_probe(struct platform_device *ofdev)if (err) goto err_gone; -/* Get interrupts. EMAC irq is mandatory */ - dev->emac_irq =irq_of_parse_and_map (np,0 ); -if (!dev->emac_irq) { -printk (KERN_ERR "%pOF: Can't map main interrupt\n" , np); - err = -ENODEV ; - goto err_gone; - } -/* Setup error IRQ handler */ + dev->emac_irq =platform_get_irq (ofdev,0 ); err =devm_request_irq (&ofdev->dev, dev->emac_irq, emac_irq,0 ,"EMAC" , dev);if (err) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 529/869 net: emac: Fix NULL pointer dereference in emac_probe
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit f623d38fe6c4e8c40b23f42cc6fe6963fa49997b ]
Move devm_request_irq() after devm_platform_ioremap_resource() so that dev->emacp is mapped before the interrupt handler can fire. An early interrupt hitting emac_irq() would dereference the NULL dev->emacp and crash.
Also remove redundant error message. devm_platform_ioremap_resource() already returns an error message with dev_err_probe().
--- drivers/net/ethernet/ibm/emac/core.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/net/ethernet/ibm/emac/core.c +6 -7
@@ -3030,6 +3030,12 @@ static int emac_probe(struct platform_device *ofdev)if (err) goto err_gone; + dev->emacp =devm_platform_ioremap_resource (ofdev,0 ); +if (IS_ERR (dev->emacp)) { + err =PTR_ERR (dev->emacp); + goto err_gone; + } +/* Setup error IRQ handler */ dev->emac_irq =platform_get_irq (ofdev,0 ); err = devm_request_irq(&ofdev->dev, dev->emac_irq, emac_irq, 0, "EMAC",
@@ -3042,13 +3048,6 @@ static int emac_probe(struct platform_device *ofdev) ndev->irq = dev->emac_irq; - dev->emacp =devm_platform_ioremap_resource (ofdev,0 ); -if (IS_ERR (dev->emacp)) { -dev_err (&ofdev->dev,"can't map device registers" ); - err =PTR_ERR (dev->emacp); - goto err_gone; - } -/* Wait for dependent devices */ err =emac_wait_deps (dev);if (err)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 530/869 ieee802154: Avoid calling WARN_ON() on -ENOMEM in cfg802154_switch_netns()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivan Abramov <[email protected]>
[ Upstream commit 0569f67ed6a7af838e2141da93c68e6b6013f483 ]
It's pointless to call WARN_ON() in case of an allocation failure in dev_change_net_namespace() and device_rename(), since it only leads to useless splats caused by deliberate fault injections, so avoid it.
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
--- net/ieee802154/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ieee802154/core.c +2 -2
@@ -245,7 +245,7 @@ int cfg802154_switch_netns(struct cfg802154_registered_device *rdev, wpan_dev->netdev->netns_local = false; err =dev_change_net_namespace (wpan_dev->netdev, net,"wpan%d" ); -WARN_ON (err); +WARN_ON (err && err != -ENOMEM ); wpan_dev->netdev->netns_local = true; }
@@ -255,7 +255,7 @@ int cfg802154_switch_netns(struct cfg802154_registered_device *rdev,wpan_phy_net_set (&rdev->wpan_phy, net); err =device_rename (&rdev->wpan_phy.dev,dev_name (&rdev->wpan_phy.dev)); -WARN_ON (err); +WARN_ON (err && err != -ENOMEM );return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 531/869 coresight: ete: Always save state on power down
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Clark <[email protected]>
[ Upstream commit 2ab4645fe4206c142a5f1491e191c906279686cf ]
System register ETMs and ETE are unlikely to be preserved on CPU power down. The ETE DT binding also never documented "arm,coresight-loses-context-with-cpu" so nobody would have legitimately been able to use that binding to fix it and ACPI has no such binding at all.
Fix it by hard coding the setting for sysreg ETMs (ETE is always sysreg) or ACPI boots. Use a local variable when setting up save_state so that it's immune to concurrent probing when devices have different configurations which is an issue with modifying the global.
This fixes the following error when using Coresight with ACPI on the FVP which supports CPU PM:
coresight ete0: External agent took claim tag
WARNING: drivers/hwtracing/coresight/coresight-core.c:248 at coresight_disclaim_device_unlocked+0xe0/0xe8, CPU#0: perf/117
--- .../coresight/coresight-etm4x-core.c | 44 ++++++++++++++----- 1 file changed, 32 insertions(+), 12 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x-core.c +32 -12
@@ -54,10 +54,14 @@ MODULE_PARM_DESC(boot_enable, "Enable tracing on boot");#define PARAM_PM_SAVE_NEVER 1/* never save any state */ #define PARAM_PM_SAVE_SELF_HOSTED 2/* save self-hosted state only */ +/* +* Save option for ETM4. ETE, sysreg ETM4s and ACPI boots ignore this option and +* will always save. +*/ static int pm_save_enable =PARAM_PM_SAVE_FIRMWARE ;module_param (pm_save_enable, int,0444 );MODULE_PARM_DESC (pm_save_enable, -"Save/restore state on power down: 1 = never, 2 = self-hosted" ); +"Save/restore state on power down: 1 = never, 2 = self-hosted. MMIO and DT only." );static struct etmv4_drvdata *etmdrvdata[NR_CPUS ];static void etm4_set_default_config (struct etmv4_config *config);
@@ -2114,6 +2118,17 @@ static void etm4_pm_clear(void) } } +static bool etm4x_always_pm_save (struct device *dev,struct csdev_access *csa) +{ +/* +* Only IO mem ETM devices will benefit from skipping PM save and only +* DT has the option to control it, not ACPI. Otherwise system register +* based ETMs and ETEs will always lose context on CPU power down, so +* always save. +*/ +return !csa->io_mem ||is_acpi_device_node (dev_fwnode (dev)); +} +static int etm4_add_coresight_dev (struct etm4_init_arg *init_arg) {int ret;
@@ -2123,6 +2138,7 @@ static int etm4_add_coresight_dev(struct etm4_init_arg *init_arg)struct coresight_desc desc = {0 };u8 major, minor;char *type_name; +bool pm_save;if (!drvdata)return -EINVAL ;
@@ -2150,6 +2166,21 @@ static int etm4_add_coresight_dev(struct etm4_init_arg *init_arg)etm4_set_default (&drvdata->config); +if (etm4x_always_pm_save (dev, init_arg->csa)) + pm_save = true; +else if (pm_save_enable ==PARAM_PM_SAVE_FIRMWARE ) + pm_save =coresight_loses_context_with_cpu (dev); +else + pm_save = pm_save_enable !=PARAM_PM_SAVE_NEVER ; + +if (pm_save) { + drvdata->save_state =devm_kmalloc (dev, +sizeof (struct etmv4_save_state ), +GFP_KERNEL ); +if (!drvdata->save_state) +return -ENOMEM ; + } + pdata =coresight_get_platform_data (dev);if (IS_ERR (pdata))return PTR_ERR (pdata);
@@ -2206,17 +2237,6 @@ static int etm4_probe(struct device *dev)if (IS_ERR (drvdata->atclk))return PTR_ERR (drvdata->atclk); -if (pm_save_enable ==PARAM_PM_SAVE_FIRMWARE ) - pm_save_enable =coresight_loses_context_with_cpu (dev) ? -PARAM_PM_SAVE_SELF_HOSTED :PARAM_PM_SAVE_NEVER ; - -if (pm_save_enable !=PARAM_PM_SAVE_NEVER ) { - drvdata->save_state =devm_kmalloc (dev, -sizeof (struct etmv4_save_state ),GFP_KERNEL ); -if (!drvdata->save_state) -return -ENOMEM ; - } -spin_lock_init (&drvdata->spinlock); drvdata->cpu =coresight_get_cpu (dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 532/869 ALSA: seq: oss: Serialize readq reset state with q->lock
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 49ce92d207820f588b0406add82f053decfbe5d9 ]
snd_seq_oss_readq_clear() resets qlen, head, and tail without q->lock even though the normal reader and producer paths serialize the same ring state under that spinlock. A reset can therefore race snd_seq_oss_readq_free() or snd_seq_oss_readq_put_event() and leave stale records in the queue, drop freshly queued ones, or report the wrong readiness after wakeup. KCSAN reports a data race between snd_seq_oss_readq_clear() and snd_seq_oss_readq_free().
Take q->lock while clearing the ring and resetting input_time. Factor the enqueue logic into a caller-locked helper so snd_seq_oss_readq_put_timestamp() updates its suppression state under the same lock instead of racing the reset path.
The buggy scenario involves two paths, with each column showing the order within that path:
reset path: locked readq updater:
1. snd_seq_oss_reset() or 1. A reader or callback producer
release reaches takes q->lock on the same queue.
snd_seq_oss_readq_clear().
2. snd_seq_oss_readq_clear() 2. The updater tests or modifies
resets qlen, head, tail, qlen, head, and tail.
and input_time.
3. snd_seq_oss_readq_clear() 3. The updater completes its
wakes sleepers on read-modify-write sequence.
q->midi_sleep.
4. Without q->lock, the reset 4. The resulting ring state drives
can overlap the locked later reads and readiness.
update.
KCSAN reports:
BUG: KCSAN: data-race in snd_seq_oss_readq_clear /
snd_seq_oss_readq_free
write to 0xffff8881069fe608 of 4 bytes by task 120516 on cpu 0:
snd_seq_oss_readq_free+0x6c/0x80 snd_seq_oss_read+0xcb/0x250 odev_read+0x38/0x60 vfs_read+0xff/0x600 ksys_read+0xb4/0x140 __x64_sys_read+0x46/0x60 do_syscall_64+0xbb/0x2f0 entry_SYSCALL_64_after_hwframe+0x77/0x7f
read to 0xffff8881069fe608 of 4 bytes by task 120517 on cpu 1:
snd_seq_oss_readq_clear+0x1f/0x90 snd_seq_oss_reset+0xa7/0xf0 snd_seq_oss_ioctl+0x6f6/0x7e0 odev_ioctl+0x56/0xc0 __x64_sys_ioctl+0xd1/0x120 do_syscall_64+0xbb/0x2f0 entry_SYSCALL_64_after_hwframe+0x77/0x7f
value changed: 0x00000001 -> 0x00000000
--- sound/core/seq/oss/seq_oss_readq.c | 83 +++++++++++++++++++----------- 1 file changed, 52 insertions(+), 31 deletions(-)
sound/core/seq/oss/seq_oss_readq.c +52 -31
@@ -73,13 +73,17 @@ snd_seq_oss_readq_delete(struct seq_oss_readq *q)void snd_seq_oss_readq_clear (struct seq_oss_readq *q) { -if (q->qlen) { - q->qlen =0 ; - q->head = q->tail =0 ; + scoped_guard(spinlock_irqsave, &q->lock) { +if (q->qlen) { + q->qlen =0 ; + q->head =0 ; + q->tail =0 ; + } + q->input_time = (unsigned long )-1 ; } +/* if someone sleeping, wake'em up */ wake_up (&q->midi_sleep); - q->input_time = (unsigned long )-1 ; }/*
@@ -136,28 +140,37 @@ int snd_seq_oss_readq_sysex(struct seq_oss_readq *q, int dev,/* * copy an event to input queue: * return zero if enqueued +* caller must hold lock */ -int -snd_seq_oss_readq_put_event (struct seq_oss_readq *q,union evrec *ev) +static int snd_seq_oss_readq_put_event_locked (struct seq_oss_readq *q, +union evrec *ev) { -unsigned long flags; - -spin_lock_irqsave (&q->lock, flags); -if (q->qlen >= q->maxlen -1 ) { -spin_unlock_irqrestore (&q->lock, flags); +if (q->qlen >= q->maxlen -1 )return -ENOMEM ; - }memcpy (&q->q[q->tail], ev,sizeof (*ev)); q->tail = (q->tail +1 ) % q->maxlen; q->qlen++; -/* wake up sleeper */ -wake_up (&q->midi_sleep); +return 0 ; +} -spin_unlock_irqrestore (&q->lock, flags); +/* +* copy an event to input queue: +* return zero if enqueued +*/ +int +snd_seq_oss_readq_put_event (struct seq_oss_readq *q,union evrec *ev) +{ +int rc; -return 0 ; + scoped_guard(spinlock_irqsave, &q->lock) { + rc =snd_seq_oss_readq_put_event_locked (q, ev); +if (!rc) +wake_up (&q->midi_sleep); + } + +return rc; }
@@ -215,23 +228,31 @@ snd_seq_oss_readq_poll(struct seq_oss_readq *q, struct file *file, poll_table *wint snd_seq_oss_readq_put_timestamp (struct seq_oss_readq *q,unsigned long curt,int seq_mode) { -if (curt != q->input_time) { -union evrec rec; -memset (&rec,0 ,sizeof (rec)); -switch (seq_mode) { -case SNDRV_SEQ_OSS_MODE_SYNTH : - rec.echo = (curt <<8 ) |SEQ_WAIT ; -snd_seq_oss_readq_put_event (q, &rec); -break ; -case SNDRV_SEQ_OSS_MODE_MUSIC : - rec.t.code =EV_TIMING ; - rec.t.cmd =TMR_WAIT_ABS ; - rec.t.time = curt; -snd_seq_oss_readq_put_event (q, &rec); -break ; +int queued =0 ; + + scoped_guard(spinlock_irqsave, &q->lock) { +if (curt != q->input_time) { +union evrec rec; + +memset (&rec,0 ,sizeof (rec)); +switch (seq_mode) { +case SNDRV_SEQ_OSS_MODE_SYNTH : + rec.echo = (curt <<8 ) |SEQ_WAIT ; + queued = !snd_seq_oss_readq_put_event_locked (q, &rec); +break ; +case SNDRV_SEQ_OSS_MODE_MUSIC : + rec.t.code =EV_TIMING ; + rec.t.cmd =TMR_WAIT_ABS ; + rec.t.time = curt; + queued = !snd_seq_oss_readq_put_event_locked (q, &rec); +break ; + } + q->input_time = curt; } - q->input_time = curt; } +if (queued) +wake_up (&q->midi_sleep); +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 533/869 btrfs: lzo: reject compressed segment that overflows the compressed input
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit b0d27d43791b7a3057c3c4aedf9b4aa033d37c46 ]
lzo_decompress_bio() validates each on-disk segment length seg_len only against the workspace cbuf size, not against the compressed input size (compressed_len, the total folio bytes of the bio). A crafted extent can carry a segment whose seg_len passes the cbuf check but runs past the end of the bio, so copy_compressed_segment() walks off the last folio:get_current_folio() then returns the NULL folio from bio_next_folio(), and with CONFIG_BTRFS_ASSERT disabled (default) folio_size(NULL) faults.
BUG: KASAN: null-ptr-deref in lzo_decompress_bio (fs/btrfs/lzo.c:383) Read of size 8 at addr 0000000000000000 by task kworker/u8:1/29 Workqueue: btrfs-endio simple_end_io_work kasan_report (mm/kasan/report.c:590) lzo_decompress_bio (fs/btrfs/lzo.c:383) end_bbio_compressed_read (fs/btrfs/compression.c:1065) btrfs_bio_end_io (fs/btrfs/bio.c:135) btrfs_check_read_bio (fs/btrfs/bio.c:180 fs/btrfs/bio.c:285) simple_end_io_work process_one_work worker_thread
Reject any segment whose payload would extend beyond compressed_len before copying it, treating it as corruption like the other on-disk validation failures in this function.
--- fs/btrfs/lzo.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/btrfs/lzo.c +11 -0
@@ -400,6 +400,17 @@ int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb)return -EIO ; } +/* The segment must not extend beyond the compressed input. */ +if (unlikely (cur_in + seg_len > cb->compressed_len)) { +struct btrfs_inode *inode = cb->bbio.inode; + +btrfs_err (fs_info, +"lzo segment overflows compressed input, root %llu inode %llu offset %llu cur_in %u len %u compressed len %u" , +btrfs_root_id (inode->root),btrfs_ino (inode), + cb->start, cur_in, seg_len, cb->compressed_len); +return -EUCLEAN ; + } +/* Copy the compressed segment payload into workspace */ copy_compressed_segment (cb, workspace->cbuf, seg_len, &cur_in);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 534/869 netfilter: flowtable: avoid num_encaps underflow on bridge VLAN untag
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Carlier <[email protected]>
[ Upstream commit e052f920773b73be49eb4d8702a9f85de7464363 ]
The DEV_PATH_BR_VLAN_UNTAG case post-decrements info->num_encaps inside WARN_ON_ONCE(). num_encaps is u8, so if it's already 0 the decrement still happens and wraps it to 255. The break only leaves the inner switch -- a later path entry can set info->indev back to a real device, and we end up returning with num_encaps == 255.
nft_dev_forward_path() then walks info.encap[] (size 2) up to num_encaps, which means an OOB stack read and a bogus count copied into the route descriptor.
Should only happen on a malformed bridge path stack, hence the WARN, but worth handling sanely. Move the decrement out of the WARN.
[ While at this, remove the WARN_ON_ONCE since this can only happen
with a buggy bridge path stack --pablo ].
--- net/netfilter/nft_flow_offload.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nft_flow_offload.c +2 -1
@@ -150,10 +150,11 @@ static void nft_dev_path_info(const struct net_device_path_stack *stack, info->num_encaps++;break ;case DEV_PATH_BR_VLAN_UNTAG : -if (WARN_ON_ONCE (info->num_encaps-- ==0 )) { +if (info->num_encaps ==0 ) { info->indev =NULL ;break ; } + info->num_encaps--;break ;case DEV_PATH_BR_VLAN_KEEP :break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 535/869 EDAC/igen6: Initialize edac_op_state according to the configuration data
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiuxu Zhuo <[email protected]>
[ Upstream commit 1d512b1aa5a88f93170b0b9360de4fff7a2f8a0a ]
Currently, igen6_edac sets edac_op_state to EDAC_OPSTATE_NMI, while the driver also supports memory errors reported from Machine Check. Initialize edac_op_state to the correct value according to the configuration data that the driver probed.
Stable-dep-of: ab1f9d466c7d ("EDAC/igen6: Fix call trace due to missing release()")
--- drivers/edac/igen6_edac.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/edac/igen6_edac.c +11 -2
@@ -1357,6 +1357,15 @@ static void unregister_err_handler(void)unregister_nmi_handler (NMI_SERR ,IGEN6_NMI_NAME ); } +static void opstate_set (struct res_config *cfg) +{ +/* Set the mode according to the configuration data. */ +if (cfg->machine_check) + edac_op_state =EDAC_OPSTATE_INT ; +else + edac_op_state =EDAC_OPSTATE_NMI ; +} +static int igen6_probe (struct pci_dev *pdev,const struct pci_device_id *ent) {u64 mchbar;
@@ -1374,6 +1383,8 @@ static int igen6_probe(struct pci_dev *pdev, const struct pci_device_id *ent)if (rc) goto fail; +opstate_set (res_cfg); +for (i =0 ; i < res_cfg->num_imc; i++) { rc =igen6_register_mci (i, mchbar, pdev);if (rc)
@@ -1457,8 +1468,6 @@ static int __init igen6_init(void)if (owner &&strncmp (owner,EDAC_MOD_STR ,sizeof (EDAC_MOD_STR )))return -EBUSY ; - edac_op_state =EDAC_OPSTATE_NMI ; - rc =pci_register_driver (&igen6_driver);if (rc)return rc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 536/869 EDAC/igen6: Add polling support
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Orange Kao <[email protected]>
[ Upstream commit e14232afa94445e03fc3a0291b07a68f3408c120 ]
Some PCs with Intel N100 (with PCI device 8086:461c, DID_ADL_N_SKU4) experienced issues with error interrupts not working, even with the following configuration in the BIOS.
In-Band ECC Support: Enabled
In-Band ECC Operation Mode: 2 (make all requests protected and
ignore range checks)
IBECC Error Injection Control: Inject Correctable Error on insertion
counter
Error Injection Insertion Count: 251658240 (0xf000000)
Add polling mode support for these machines to ensure that memory error events are handled.
Stable-dep-of: ab1f9d466c7d ("EDAC/igen6: Fix call trace due to missing release()")
--- drivers/edac/igen6_edac.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-)
drivers/edac/igen6_edac.c +28 -2
@@ -1177,6 +1177,20 @@ static int igen6_pci_setup(struct pci_dev *pdev, u64 *mchbar)return -ENODEV ; } +static void igen6_check (struct mem_ctl_info *mci) +{ +struct igen6_imc *imc = mci->pvt_info; +u64 ecclog; + +/* errsts_clear() isn't NMI-safe. Delay it in the IRQ context */ + ecclog =ecclog_read_and_clear (imc); +if (!ecclog) +return ; + +if (!ecclog_gen_pool_add (imc->mc, ecclog)) +irq_work_queue (&ecclog_irq_work); +} +static int igen6_register_mci (int mc,u64 mchbar,struct pci_dev *pdev) {struct edac_mc_layer layers[2 ];
@@ -1218,6 +1232,8 @@ static int igen6_register_mci(int mc, u64 mchbar, struct pci_dev *pdev) mci->edac_cap =EDAC_FLAG_SECDED ; mci->mod_name =EDAC_MOD_STR ; mci->dev_name =pci_name (pdev); +if (edac_op_state ==EDAC_OPSTATE_POLL ) + mci->edac_check = igen6_check; mci->pvt_info = &igen6_pvt->imc[mc]; imc = mci->pvt_info;
@@ -1357,8 +1373,18 @@ static void unregister_err_handler(void)unregister_nmi_handler (NMI_SERR ,IGEN6_NMI_NAME ); } -static void opstate_set (struct res_config *cfg) +static void opstate_set (struct res_config *cfg,const struct pci_device_id *ent) { +/* +* Quirk: Certain SoCs' error reporting interrupts don't work. +* Force polling mode for them to ensure that memory error +* events can be handled. +*/ +if (ent->device ==DID_ADL_N_SKU4 ) { + edac_op_state =EDAC_OPSTATE_POLL ; +return ; + } +/* Set the mode according to the configuration data. */ if (cfg->machine_check) edac_op_state =EDAC_OPSTATE_INT ;
@@ -1383,7 +1409,7 @@ static int igen6_probe(struct pci_dev *pdev, const struct pci_device_id *ent)if (rc) goto fail; -opstate_set (res_cfg); +opstate_set (res_cfg, ent);for (i =0 ; i < res_cfg->num_imc; i++) { rc =igen6_register_mci (i, mchbar, pdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 537/869 EDAC/igen6: Skip absent memory controllers
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiuxu Zhuo <[email protected]>
[ Upstream commit 20e190b1c1fd88b21cc5106c12cfe6def5ab849d ]
Some BIOS versions may fuse off certain memory controllers and set the registers of these absent memory controllers to ~0. The current igen6_edac mistakenly enumerates these absent memory controllers and registers them with the EDAC core.
Skip the absent memory controllers to avoid mistakenly enumerating them.
Stable-dep-of: ab1f9d466c7d ("EDAC/igen6: Fix call trace due to missing release()")
--- drivers/edac/igen6_edac.c | 78 +++++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 16 deletions(-)
drivers/edac/igen6_edac.c +62 -16
@@ -127,6 +127,7 @@ static struct res_config { bool machine_check; + /* The number of present memory controllers. */ int num_imc; u32 imc_base; u32 cmf_base;
@@ -1191,23 +1192,21 @@ static void igen6_check(struct mem_ctl_info *mci)irq_work_queue (&ecclog_irq_work); } -static int igen6_register_mci (int mc,u64 mchbar,struct pci_dev *pdev) +/* Check whether the memory controller is absent. */ +static bool igen6_imc_absent (void __iomem *window) +{ +return readl (window +MAD_INTER_CHANNEL_OFFSET ) == ~0 ; +} + +static int igen6_register_mci (int mc,void __iomem *window,struct pci_dev *pdev) {struct edac_mc_layer layers[2 ];struct mem_ctl_info *mci;struct igen6_imc *imc; -void __iomem *window;int rc;edac_dbg (2 ,"\n" ); - mchbar += mc *MCHBAR_SIZE ; - window =ioremap (mchbar,MCHBAR_SIZE ); -if (!window) { -igen6_printk (KERN_ERR ,"Failed to ioremap 0x%llx\n" , mchbar); -return -ENODEV ; - } - layers[0 ].type =EDAC_MC_LAYER_CHANNEL ; layers[0 ].size =NUM_CHANNELS ; layers[0 ].is_virt_csrow = false;
@@ -1273,7 +1272,6 @@ static int igen6_register_mci(int mc, u64 mchbar, struct pci_dev *pdev) fail2:edac_mc_free (mci); fail: -iounmap (window);return rc; }
@@ -1299,6 +1297,56 @@ static void igen6_unregister_mcis(void) } } +static int igen6_register_mcis (struct pci_dev *pdev,u64 mchbar) +{ +void __iomem *window; +int lmc, pmc, rc; +u64 base; + +for (lmc =0 , pmc =0 ; pmc <NUM_IMC ; pmc++) { + base = mchbar + pmc *MCHBAR_SIZE ; + window =ioremap (base,MCHBAR_SIZE ); +if (!window) { +igen6_printk (KERN_ERR ,"Failed to ioremap 0x%llx for mc%d\n" , base, pmc); + rc = -ENOMEM ; + goto out_unregister_mcis; + } + +if (igen6_imc_absent (window)) { +iounmap (window); +edac_dbg (2 ,"Skip absent mc%d\n" , pmc); +continue ; + } + + rc =igen6_register_mci (lmc, window, pdev); +if (rc) + goto out_iounmap; + +/* Done, if all present MCs are detected and registered. */ +if (++lmc >= res_cfg->num_imc) +break ; + } + +if (!lmc) { +igen6_printk (KERN_ERR ,"No mc found.\n" ); +return -ENODEV ; + } + +if (lmc < res_cfg->num_imc) +igen6_printk (KERN_WARNING ,"Expected %d mcs, but only %d detected." , + res_cfg->num_imc, lmc); + +return 0 ; + +out_iounmap: +iounmap (window); + +out_unregister_mcis: +igen6_unregister_mcis (); + +return rc; +} +static int igen6_mem_slice_setup (u64 mchbar) {struct igen6_imc *imc = &igen6_pvt->imc[0 ];
@@ -1395,7 +1443,7 @@ static void opstate_set(struct res_config *cfg, const struct pci_device_id *ent)static int igen6_probe (struct pci_dev *pdev,const struct pci_device_id *ent) {u64 mchbar; -int i, rc; +int rc;edac_dbg (2 ,"\n" );
@@ -1411,11 +1459,9 @@ static int igen6_probe(struct pci_dev *pdev, const struct pci_device_id *ent)opstate_set (res_cfg, ent); -for (i =0 ; i < res_cfg->num_imc; i++) { - rc =igen6_register_mci (i, mchbar, pdev); -if (rc) - goto fail2; - } + rc =igen6_register_mcis (pdev, mchbar); +if (rc) + goto fail;if (res_cfg->num_imc >1 ) { rc =igen6_mem_slice_setup (mchbar);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 538/869 EDAC/igen6: Fix call trace due to missing release()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiuxu Zhuo <[email protected]>
[ Upstream commit ab1f9d466c7d83ab0d2a529e07984e53b5960dcd ]
When unloading the igen6_edac driver, there is a call trace:
Device '(null)' does not have a release() function, it is broken and must be fixed. See Documentation/core-api/kobject.rst.
WARNING: drivers/base/core.c:2567 at device_release+0x84/0x90, CPU#5: rmmod/127209 ... RIP: 0010:device_release+0x84/0x90 Call Trace: <TASK> kobject_put+0x8c/0x220 put_device+0x17/0x30 igen6_unregister_mcis+0xa2/0xe0 [igen6_edac] igen6_remove+0x82/0xb0 [igen6_edac] ...
Fix the call trace by providing empty release() functions for the memory controller devices.
--- drivers/edac/igen6_edac.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/edac/igen6_edac.c +6 -0
@@ -1198,6 +1198,11 @@ static bool igen6_imc_absent(void __iomem *window)return readl (window +MAD_INTER_CHANNEL_OFFSET ) == ~0 ; } +static void imc_release (struct device *dev) +{ +/* Nothing to do, the 'imc' owns the 'dev' and will also release it. */ +} +static int igen6_register_mci (int mc,void __iomem *window,struct pci_dev *pdev) {struct edac_mc_layer layers[2 ];
@@ -1236,6 +1241,7 @@ static int igen6_register_mci(int mc, void __iomem *window, struct pci_dev *pdev mci->pvt_info = &igen6_pvt->imc[mc]; imc = mci->pvt_info; + imc->dev.release = imc_release;device_initialize (&imc->dev);/* * EDAC core uses mci->pdev(pointer of structure device) as
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 539/869 scsi: hisi_sas: Add slave_destroy interface for v3 hw
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yihang Li <[email protected]>
[ Upstream commit 67b85a88265df19f049241d8c00571a5408f4eeb ]
WARNING is triggered when executing link reset of remote PHY and rmmod SAS driver simultaneously. Following is the WARNING log:
WARNING: CPU: 61 PID: 21818 at drivers/base/core.c:1347 __device_links_no_driver+0xb4/0xc0 Call trace: __device_links_no_driver+0xb4/0xc0 device_links_driver_cleanup+0xb0/0xfc __device_release_driver+0x198/0x23c device_release_driver+0x38/0x50 bus_remove_device+0x130/0x140 device_del+0x184/0x434 __scsi_remove_device+0x118/0x150 scsi_remove_target+0x1bc/0x240 sas_rphy_remove+0x90/0x94 sas_rphy_delete+0x24/0x3c sas_destruct_devices+0x64/0xa0 [libsas] sas_revalidate_domain+0xe4/0x150 [libsas] process_one_work+0x1e0/0x46c worker_thread+0x15c/0x464 kthread+0x160/0x170 ret_from_fork+0x10/0x20 ---[ end trace 71e059eb58f85d4a ]---
During SAS phy up, link->status is set to DL_STATE_AVAILABLE in device_links_driver_bound, then this setting influences __device_links_no_driver() before driver rmmod and caused WARNING.
Add the slave_destroy interface to make sure link is removed after flush workque.
--- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +11 -1
@@ -2978,7 +2978,7 @@ static int device_configure_v3_hw(struct scsi_device *sdev,return 0 ;if (!device_link_add (&sdev->sdev_gendev, dev, -DL_FLAG_PM_RUNTIME |DL_FLAG_RPM_ACTIVE )) { +DL_FLAG_STATELESS |DL_FLAG_PM_RUNTIME |DL_FLAG_RPM_ACTIVE )) {if (pm_runtime_enabled (dev)) {dev_info (dev,"add device link failed, disable runtime PM for the host\n" );pm_runtime_disable (dev);
@@ -2988,6 +2988,15 @@ static int device_configure_v3_hw(struct scsi_device *sdev,return 0 ; } +static void hisi_sas_sdev_destroy (struct scsi_device *sdev) +{ +struct Scsi_Host *shost =dev_to_shost (&sdev->sdev_gendev); +struct hisi_hba *hisi_hba =shost_priv (shost); +struct device *dev = hisi_hba->dev; + +device_link_remove (&sdev->sdev_gendev, dev); +} +static struct attribute *host_v3_hw_attrs[] = { &dev_attr_phy_event_threshold.attr, &dev_attr_intr_conv_v3_hw.attr,
@@ -3402,6 +3411,7 @@ static const struct scsi_host_template sht_v3_hw = { .sg_tablesize = HISI_SAS_SGE_PAGE_CNT, .sg_prot_tablesize = HISI_SAS_SGE_PAGE_CNT, .slave_alloc = hisi_sas_slave_alloc, + .slave_destroy = hisi_sas_sdev_destroy, .shost_groups = host_v3_hw_groups, .sdev_groups = sdev_groups_v3_hw, .tag_alloc_policy = BLK_TAG_ALLOC_RR,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 540/869 soc: xilinx: Fix race condition in event registration
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Prasanna Kumar T S M <[email protected]>
[ Upstream commit fb445935338405110baca8f541a2df3b4cb8d712 ]
The zynqmp_power driver registers handlers for suspend and subsystem restart events using register_event(). However, the work structures (zynqmp_pm_init_suspend_work and zynqmp_pm_init_restart_work) used by these handlers were allocated and initialized after the registration call.
This created a race window where, if the firmware triggered an event immediately after registration but before allocation, the callback (suspend_event_callback or subsystem_restart_event_callback) would dereference a NULL pointer in work_pending(), leading to a crash.
Fix this by allocating and initializing the work structures before registering the events.
--- drivers/soc/xilinx/zynqmp_power.c | 43 ++++++++++++------------------- 1 file changed, 17 insertions(+), 26 deletions(-)
drivers/soc/xilinx/zynqmp_power.c +17 -26
@@ -303,18 +303,18 @@ static int zynqmp_pm_probe(struct platform_device *pdev)* is not available to use) or -ENODEV(Xilinx Event Manager not compiled), * then use ipi-mailbox or interrupt method. */ + zynqmp_pm_init_suspend_work =devm_kzalloc (&pdev->dev, +sizeof (struct zynqmp_pm_work_struct ), +GFP_KERNEL ); +if (!zynqmp_pm_init_suspend_work) +return -ENOMEM ; + +INIT_WORK (&zynqmp_pm_init_suspend_work->callback_work, + zynqmp_pm_init_suspend_work_fn); + ret =register_event (&pdev->dev,PM_INIT_SUSPEND_CB ,0 ,0 , false, suspend_event_callback);if (!ret) { - zynqmp_pm_init_suspend_work =devm_kzalloc (&pdev->dev, -sizeof (struct zynqmp_pm_work_struct ), -GFP_KERNEL ); -if (!zynqmp_pm_init_suspend_work) -return -ENOMEM ; - -INIT_WORK (&zynqmp_pm_init_suspend_work->callback_work, - zynqmp_pm_init_suspend_work_fn); - ret =zynqmp_pm_get_family_info (&pm_family_code, &pm_sub_family_code);if (ret <0 )return ret;
@@ -324,14 +324,6 @@ static int zynqmp_pm_probe(struct platform_device *pdev)else node_id =PM_DEV_ACPU_0 ; - ret =register_event (&pdev->dev,PM_NOTIFY_CB , node_id,EVENT_SUBSYSTEM_RESTART , - false, subsystem_restart_event_callback); -if (ret) { -dev_err (&pdev->dev,"Failed to Register with Xilinx Event manager %d\n" , - ret); -return ret; - } - zynqmp_pm_init_restart_work =devm_kzalloc (&pdev->dev,sizeof (struct zynqmp_pm_work_struct ),GFP_KERNEL );
@@ -340,19 +332,18 @@ static int zynqmp_pm_probe(struct platform_device *pdev)INIT_WORK (&zynqmp_pm_init_restart_work->callback_work, zynqmp_pm_subsystem_restart_work_fn); + + ret =register_event (&pdev->dev,PM_NOTIFY_CB , node_id,EVENT_SUBSYSTEM_RESTART , + false, subsystem_restart_event_callback); +if (ret) { +dev_err (&pdev->dev,"Failed to Register with Xilinx Event manager %d\n" , + ret); +return ret; + } }else if (ret != -EACCES && ret != -ENODEV ) {dev_err (&pdev->dev,"Failed to Register with Xilinx Event manager %d\n" , ret);return ret; }else if (of_property_present (pdev->dev.of_node,"mboxes" )) { - zynqmp_pm_init_suspend_work = -devm_kzalloc (&pdev->dev, -sizeof (struct zynqmp_pm_work_struct ), -GFP_KERNEL ); -if (!zynqmp_pm_init_suspend_work) -return -ENOMEM ; - -INIT_WORK (&zynqmp_pm_init_suspend_work->callback_work, - zynqmp_pm_init_suspend_work_fn); client =devm_kzalloc (&pdev->dev,sizeof (*client),GFP_KERNEL );if (!client)return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 541/869 cxl: Fix CXL_HEADERLOG_SIZE to match RAS Capability size
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Terry Bowman <[email protected]>
[ Upstream commit c268f949e219f9e179558e836f457f6c5fbec416 ]
The CXL r4.0 8.2.4.17.7 RAS Capability Structure has total length 0x58 bytes (CXL_RAS_CAPABILITY_LENGTH); the Header Log occupies the trailing 64 bytes at offset 0x18. CXL_HEADERLOG_SIZE was defined as SZ_512, eight times the actual on-device size.
header_log_copy() reads CXL_HEADERLOG_SIZE_U32 (128) dwords from the RAS capability iomap, overrunning the 88-byte mapping by 448 bytes. The cxl_aer_uncorrectable_error trace event memcpy()s CXL_HEADERLOG_SIZE
(512) bytes from its source. For the CPER caller the source is struct cxl_ras_capability_regs::header_log[16] (64 bytes) embedded in a stack-local cxl_cper_prot_err_work_data, so the memcpy reads 448 bytes of kernel stack into the trace event ring buffer where userspace can read it via tracefs.
Set CXL_HEADERLOG_SIZE to 64 and derive CXL_HEADERLOG_SIZE_U32 from it, bringing all iomap readers into agreement on 16 dwords. Userspace tools such as rasdaemon have grown a dependency on the buggy 512-byte (128 u32) header_log layout in the cxl_aer_uncorrectable_error trace event. Add CXL_HEADERLOG_TRACE_SIZE_U32 = 128 and use it for the trace event __array and its memcpy to preserve that ABI. Both callers now pass a zero-filled u32[CXL_HEADERLOG_TRACE_SIZE_U32] staging buffer with only the first CXL_HEADERLOG_SIZE_U32 (16) entries populated from hardware; the remaining 112 u32s are zero-padded, keeping the 512-byte trace ring buffer layout intact.
[ dj: Replaced 64 with SZ_64 per RichardC ]
--- drivers/cxl/core/ras.c | 10 +++++++--- drivers/cxl/core/trace.h | 12 ++++++++---- drivers/cxl/cxl.h | 14 ++++++++++++-- 3 files changed, 27 insertions(+), 9 deletions(-)
drivers/cxl/core/ras.c +7 -3
@@ -7,6 +7,10 @@#include "core.h" #include "trace.h" +/* Check that UCE header definition is maintained to keep ABI intact */ +static_assert (CXL_HEADERLOG_TRACE_SIZE_U32 ==128 , +"rasdaemon ABI requires exactly 128 u32s" ); +void cxl_handle_cor_ras (struct cxl_dev_state *cxlds,void __iomem *ras_base) {void __iomem *addr;
@@ -28,12 +32,12 @@ static void header_log_copy(void __iomem *ras_base, u32 *log) {void __iomem *addr;u32 *log_addr; -int i, log_u32_size =CXL_HEADERLOG_SIZE /sizeof (u32); +int i; addr = ras_base +CXL_RAS_HEADER_LOG_OFFSET ; log_addr = log; -for (i =0 ; i < log_u32_size; i++) { +for (i =0 ; i <CXL_HEADERLOG_SIZE_U32 ; i++) { *log_addr =readl (addr); log_addr++; addr +=sizeof (u32);
@@ -46,7 +50,7 @@ static void header_log_copy(void __iomem *ras_base, u32 *log)*/ bool cxl_handle_ras (struct cxl_dev_state *cxlds,void __iomem *ras_base) { -u32 hl[CXL_HEADERLOG_SIZE_U32 ]; +u32 hl[CXL_HEADERLOG_TRACE_SIZE_U32 ] = {};void __iomem *addr;u32 status;u32 fe;
drivers/cxl/core/trace.h +8 -4
@@ -57,7 +57,7 @@ TRACE_EVENT(cxl_aer_uncorrectable_error, __field(u64, serial) __field(u32, status) __field(u32, first_error) -__array (u32, header_log,CXL_HEADERLOG_SIZE_U32 ) +__array (u32, header_log,CXL_HEADERLOG_TRACE_SIZE_U32 ) ),TP_fast_assign ( __assign_str(memdev);
@@ -66,10 +66,14 @@ TRACE_EVENT(cxl_aer_uncorrectable_error, __entry->status = status; __entry->first_error = fe;/* -* Embed the 512B headerlog data for user app retrieval and -* parsing, but no need to print this in the trace buffer. +* Embed headerlog data for user app retrieval and parsing, +* but no need to print in the trace buffer. Only +* CXL_HEADERLOG_SIZE_U32 (16) dwords are hardware data; +* the remaining entries preserve the 512-byte ABI layout +* rasdaemon depends on and are zero-filled by the caller. */ -memcpy (__entry->header_log, hl,CXL_HEADERLOG_SIZE ); +memcpy (__entry->header_log, hl, +CXL_HEADERLOG_TRACE_SIZE_U32 *sizeof (u32)); ), TP_printk("memdev=%s host=%s serial=%lld: status: '%s' first_error: '%s'", __get_str(memdev), __get_str(host), __entry->serial,
drivers/cxl/cxl.h +12 -2
@@ -147,8 +147,18 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw)#define CXL_RAS_CAP_CONTROL_FE_MASK GENMASK(5, 0)#define CXL_RAS_HEADER_LOG_OFFSET 0x18#define CXL_RAS_CAPABILITY_LENGTH 0x58 -#define CXL_HEADERLOG_SIZE SZ_512 -#define CXL_HEADERLOG_SIZE_U32 SZ_512 / sizeof(u32) +#define CXL_HEADERLOG_SIZE SZ_64 +#define CXL_HEADERLOG_SIZE_U32 (CXL_HEADERLOG_SIZE / sizeof(u32)) + +/* +* The RAS UCE trace event header array was originally sized at SZ_512/sizeof(u32) +* = 128 u32s due to a bug. Userspace tools (rasdaemon) have grown a dependency +* on that 512-byte layout. Keep the trace array at 128 u32s to preserve the +* ABI; only CXL_HEADERLOG_SIZE_U32 (16) dwords are valid hardware data, the +* remainder are zero-filled. +*/ +#define CXL_HEADERLOG_TRACE_SIZE SZ_512 +#define CXL_HEADERLOG_TRACE_SIZE_U32 (CXL_HEADERLOG_TRACE_SIZE / sizeof(u32))/* CXL 2.0 8.2.8.1 Device Capabilities Array Register */ #define CXLDEV_CAP_ARRAY_OFFSET 0x0
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 542/869 netfilter: nf_conntrack_expect: use conntrack GC to reap expectations
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit b8b09dc2bf35a00d4e0556b5d6308c7b917ebda2 ]
This patch replaces the timer API by GC worker approach for expectations, as it already happened in many other subsystems.
Use the existing conntrack GC worker to iterate over the local list of expectations in the master conntrack to reap expired expectations. Check IPS_HELPER_BIT to run GC for expectations, set it on for nft_ct expectation which nevers sets it. Hold the expectation spinlock while iterating over the master conntrack expectation list to synchronize with nf_ct_remove_expectations(). This also performs runtime packet path garbage collection through the expectation insertion and lookup functions while walking over one of the chains of the global expectation hashtables. Unconfirmed conntrack entries are skipped since ct->ext can be reallocated and dying are skipped since those will be gone soon. Set on IPS_HELPER_BIT if the helper ct extension is added, then the new GC worker does not need to bump the ct refcount to check if the ct->ext helper is available.
This removes the extra bump on the refcount for expectation timers, this allows to remove several nf_ct_expect_put() calls after the unlink, after this update only refcount remains at 1 while on the expectation hashes.
This patch implicitly addresses a race with the existing timer API allowing an expectation to access a stale exp->master pointer which has been already released when expectation removal loses races with an expiring timer, ie. timer_del() reporting false.
Add a new NF_CT_EXPECT_DEAD flag to reap this expectation via GC. This is needed by nf_conntrack_unexpect_related() which is called in error paths to invalidate newly created expectations that has been added into the hashes. These expectactions cannot be inmediately released as GC or nf_ct_remove_expectations() could race to make it. On expectation insert, the runtime GC reaps stale expectations before checking the expectation limit set by policy.
Set current timestamp in nf_ct_expect_alloc(), then add the expectation policy timeout (or custom timeout specified added on top of this) to specify the expectation lifetime.
--- include/net/netfilter/nf_conntrack_expect.h | 16 +- .../linux/netfilter/nf_conntrack_common.h | 1 + net/netfilter/nf_conntrack_core.c | 33 +++- net/netfilter/nf_conntrack_expect.c | 148 +++++++++--------- net/netfilter/nf_conntrack_h323_main.c | 4 +- net/netfilter/nf_conntrack_helper.c | 10 +- net/netfilter/nf_conntrack_netlink.c | 22 ++- net/netfilter/nf_conntrack_sip.c | 13 +- net/netfilter/nft_ct.c | 3 +- 9 files changed, 140 insertions(+), 110 deletions(-)
include/net/netfilter/nf_conntrack_expect.h +13 -3
@@ -54,8 +54,8 @@ struct nf_conntrack_expect {/* The conntrack of the master connection */ struct nf_conn *master; -/* Timer function; deletes the expectation. */ -struct timer_list timeout; +/* jiffies32 when this expectation expires */ +u32 timeout;#if IS_ENABLED (CONFIG_NF_NAT )union nf_inet_addr saved_addr;
@@ -69,6 +69,14 @@ struct nf_conntrack_expect {struct rcu_head rcu; }; +static inline bool nf_ct_exp_is_expired (const struct nf_conntrack_expect *exp) +{ +if (READ_ONCE (exp->flags) &NF_CT_EXPECT_DEAD ) +return true; + +return (__s32)(READ_ONCE (exp->timeout) - nfct_time_stamp) <=0 ; +} +static inline struct net *nf_ct_exp_net (struct nf_conntrack_expect *exp) {return read_pnet (&exp->net);
@@ -130,7 +138,6 @@ static inline void nf_ct_unlink_expect(struct nf_conntrack_expect *exp)void nf_ct_remove_expectations (struct nf_conn *ct);void nf_ct_unexpect_related (struct nf_conntrack_expect *exp); -bool nf_ct_remove_expect (struct nf_conntrack_expect *exp);void nf_ct_expect_iterate_destroy (bool (*iter)(struct nf_conntrack_expect *e,void *data),void *data); void nf_ct_expect_iterate_net(struct net *net,
@@ -153,5 +160,8 @@ static inline int nf_ct_expect_related(struct nf_conntrack_expect *expect, return nf_ct_expect_related_report(expect, 0, 0, flags); } +struct nf_conn_help ; +void nf_ct_expectation_gc (struct nf_conn_help *master_help); +#endif /*_NF_CONNTRACK_EXPECT_H*/
include/uapi/linux/netfilter/nf_conntrack_common.h +1 -0
@@ -160,6 +160,7 @@ enum ip_conntrack_expect_events {#define NF_CT_EXPECT_USERSPACE 0x4#ifdef __KERNEL__ +#define NF_CT_EXPECT_DEAD 0x8#define NF_CT_EXPECT_MASK (NF_CT_EXPECT_PERMANENT | NF_CT_EXPECT_INACTIVE | \ NF_CT_EXPECT_USERSPACE)#endif
net/netfilter/nf_conntrack_core.c +32 -1
@@ -1467,6 +1467,31 @@ static bool gc_worker_can_early_drop(const struct nf_conn *ct)return false; } +static void nf_ct_help_gc (struct nf_conn *ct) +{ +struct nf_conn_help *help; + +if (!refcount_inc_not_zero (&ct->ct_general.use)) +return ; + +/* load ->status after refcount increase */ +smp_acquire__after_ctrl_dep (); + +if (!nf_ct_is_confirmed (ct) ||nf_ct_is_dying (ct)) { +nf_ct_put (ct); +return ; + } + +/* re-check helper due to SLAB_TYPESAFE_BY_RCU */ +if (test_bit (IPS_HELPER_BIT , &ct->status)) { + help =nfct_help (ct); +if (help) +nf_ct_expectation_gc (help); + } + +nf_ct_put (ct); +} +static void gc_worker (struct work_struct *work) {unsigned int i, hashsz, nf_conntrack_max95 =0 ;
@@ -1539,7 +1564,13 @@ static void gc_worker(struct work_struct *work) expires = (expires - (long )next_run) / ++count; next_run += expires; -if (nf_conntrack_max95 ==0 ||gc_worker_skip_ct (tmp)) +if (gc_worker_skip_ct (tmp)) +continue ; + +if (test_bit (IPS_HELPER_BIT , &tmp->status)) +nf_ct_help_gc (tmp); + +if (nf_conntrack_max95 ==0 )continue ; net =nf_ct_net (tmp);
net/netfilter/nf_conntrack_expect.c +73 -75
295 lines not on this page · raw message
net/netfilter/nf_conntrack_h323_main.c +2 -2
@@ -1396,8 +1396,8 @@ static int process_rcf(struct sk_buff *skb, struct nf_conn *ct,"timeout to %u seconds for" , info->timeout);nf_ct_dump_tuple (&exp->tuple); -mod_timer_pending (&exp->timeout, - jiffies + info->timeout *HZ ); +WRITE_ONCE (exp->timeout, + nfct_time_stamp + (info->timeout *HZ )); }spin_unlock_bh (&nf_conntrack_expect_lock); }
net/netfilter/nf_conntrack_helper.c +4 -6
@@ -180,10 +180,10 @@ nf_ct_helper_ext_add(struct nf_conn *ct, gfp_t gfp)struct nf_conn_help *help; help =nf_ct_ext_add (ct,NF_CT_EXT_HELPER , gfp); -if (help) +if (help) { +__set_bit (IPS_HELPER_BIT , &ct->status);INIT_HLIST_HEAD (&help->expectations); -else -pr_debug ("failed to add helper extension area" ); + }return help; }EXPORT_SYMBOL_GPL (nf_ct_helper_ext_add);
@@ -202,10 +202,8 @@ int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl,return 0 ; help =nfct_help (tmpl); -if (help !=NULL ) { +if (help) helper =rcu_dereference (help->helper); -set_bit (IPS_HELPER_BIT , &ct->status); - } help =nfct_help (ct);
net/netfilter/nf_conntrack_netlink.c +9 -13
@@ -3001,8 +3001,8 @@ static int ctnetlink_exp_dump_expect(struct sk_buff *skb, const struct nf_conntrack_expect *exp) { + __s32 timeout = (__s32)(READ_ONCE(exp->timeout) - nfct_time_stamp) / HZ;struct nf_conn *master = exp->master; -long timeout = ((long )exp->timeout.expires - (long )jiffies) /HZ ;struct nf_conntrack_helper *helper;#if IS_ENABLED (CONFIG_NF_NAT )struct nlattr *nest_parms;
@@ -3165,6 +3165,9 @@ ctnetlink_exp_dump_table(struct sk_buff *skb, struct netlink_callback *cb) restart:hlist_for_each_entry_rcu (exp, &nf_ct_expect_hash[cb->args[0 ]], hnode) { +if (nf_ct_exp_is_expired (exp)) +continue ; +if (l3proto && exp->tuple.src.l3num != l3proto)continue ;
@@ -3444,11 +3447,8 @@ static int ctnetlink_del_expect(struct sk_buff *skb, }/* after list removal, usage count == 1 */ -if (del_timer (&exp->timeout)) { -nf_ct_unlink_expect_report (exp,NETLINK_CB (skb).portid, -nlmsg_report (info->nlh)); -nf_ct_expect_put (exp); - } +nf_ct_unlink_expect_report (exp,NETLINK_CB (skb).portid, +nlmsg_report (info->nlh));spin_unlock_bh (&nf_conntrack_expect_lock);/* have to put what we 'get' above. * after this line usage count == 0 */
@@ -3472,14 +3472,10 @@ static int ctnetlink_change_expect(struct nf_conntrack_expect *x, const struct nlattr * const cda[]) { - if (cda[CTA_EXPECT_TIMEOUT]) { - if (!del_timer(&x->timeout)) - return -ETIME; + if (cda[CTA_EXPECT_TIMEOUT]) + WRITE_ONCE(x->timeout, nfct_time_stamp + + ntohl(nla_get_be32(cda[CTA_EXPECT_TIMEOUT])) * HZ); - x->timeout.expires = jiffies + -ntohl (nla_get_be32 (cda[CTA_EXPECT_TIMEOUT ])) *HZ ; -add_timer (&x->timeout); - }return 0 ; }
net/netfilter/nf_conntrack_sip.c +5 -8
@@ -894,11 +894,10 @@ static int refresh_signalling_expectation(struct nf_conn *ct, exp->tuple.dst.protonum != proto || exp->tuple.dst.u.udp.port != port) continue; -if (mod_timer_pending (&exp->timeout, jiffies + expires *HZ )) { - exp->flags &= ~NF_CT_EXPECT_INACTIVE ; - found =1 ; -break ; - } +WRITE_ONCE (exp->timeout, nfct_time_stamp + (expires *HZ )); +WRITE_ONCE (exp->flags, exp->flags & ~NF_CT_EXPECT_INACTIVE ); + found =1 ; +break ; }spin_unlock_bh (&nf_conntrack_expect_lock);return found;
@@ -914,8 +913,7 @@ static void flush_expectations(struct nf_conn *ct, bool media)hlist_for_each_entry_safe (exp, next, &help->expectations, lnode) {if ((exp->class !=SIP_EXPECT_SIGNALLING ) ^ media)continue ; -if (!nf_ct_remove_expect (exp)) -continue ; +nf_ct_unlink_expect (exp);if (!media)break ; }
@@ -1385,7 +1383,6 @@ static int process_register_request(struct sk_buff *skb, unsigned int protoff,nf_ct_expect_init (exp,SIP_EXPECT_SIGNALLING ,nf_ct_l3num (ct), saddr, &daddr, proto,NULL , &port); - exp->timeout.expires = sip_timeout *HZ ;rcu_assign_pointer (exp->assign_helper, helper); exp->flags =NF_CT_EXPECT_PERMANENT |NF_CT_EXPECT_INACTIVE ;
net/netfilter/nft_ct.c +1 -2
@@ -1128,7 +1128,6 @@ static void nft_ct_helper_obj_eval(struct nft_object *obj, help =nf_ct_helper_ext_add (ct,GFP_ATOMIC );if (help) {rcu_assign_pointer (help->helper, to_assign); -set_bit (IPS_HELPER_BIT , &ct->status);if ((ct->status &IPS_NAT_MASK ) && !nfct_seqadj (ct))if (!nfct_seqadj_ext_add (ct))
@@ -1310,7 +1309,7 @@ static void nft_ct_expect_obj_eval(struct nft_object *obj, &ct->tuplehash[!dir].tuple.src.u3, &ct->tuplehash[!dir].tuple.dst.u3, priv->l4proto, NULL, &priv->dport); - exp->timeout.expires = jiffies + priv->timeout *HZ ; + exp->timeout += priv->timeout *HZ ;if (nf_ct_expect_related (exp,0 ) !=0 ) regs->verdict.code =NF_DROP ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 543/869 perf tools: Use perf_env__get_cpu_topology() in machine__resolve()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 5484b43a0ec8231c36fba6ead654cb72dbba8b8f ]
machine__resolve() accesses env->cpu[al->cpu].socket_id after checking al->cpu >= 0 and env->cpu != NULL, but without validating al->cpu against env->nr_cpus_avail. Since al->cpu comes from the untrusted perf.data sample, a crafted file with a large CPU index causes an out-of-bounds heap read.
Use perf_env__get_cpu_topology() which validates both NULL and bounds. Also bounds-check al->cpu before the cast to struct perf_cpu (int16_t):
without this, values like 65536 silently truncate to 0, bypassing the accessor's internal check and returning CPU 0's topology.
--- tools/perf/util/event.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
tools/perf/util/event.c +13 -2
@@ -12,6 +12,7 @@#include <linux/zalloc.h> #include "cpumap.h" #include "dso.h" +#include "env.h" #include "event.h" #include "debug.h" #include "hist.h"
@@ -763,8 +764,18 @@ int machine__resolve(struct machine *machine, struct addr_location *al,if (al->cpu >=0 ) {struct perf_env *env = machine->env; -if (env && env->cpu) - al->socket = env->cpu[al->cpu].socket_id; +/* +* Bounds-check al->cpu (s32) before casting to struct perf_cpu +* (int16_t): without this, e.g. 65536 truncates to 0 and silently +* returns CPU 0's topology. Can go once perf_cpu.cpu is widened. +*/ +if (env && al->cpu < env->nr_cpus_avail) { +struct cpu_topology_map *topo; + + topo =perf_env__get_cpu_topology (env, (struct perf_cpu ){ al->cpu }); +if (topo) + al->socket = topo->socket_id; + } }if (al->map) {
Signature · 1 line
2.53.0
Re: [PATCH 6.12 543/869] perf tools: Use perf_env__get_cpu_topology() in machine__resolve()
Hi,
please drop this patch for 6.12.y or add some dependency.
because of the build error:util/event.c:775:32: error: implicit declaration of function ‘perf_env__get_cpu_topology’; did you mean ‘perf_env__read_cpu_topology_map’? [-Wimplicit-function-declaration]
Best Regards
Wang Yugui ([email protected])
2026/10/18
Quoted 70 lines
6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit
5484b43a0ec8231c36fba6ead654cb72dbba8b8f]
machine__resolve()accesses env->cpu[al->cpu].socket_id after checkingal->cpu>= 0 andenv->cpu!= NULL, but without validatingal->cpuagainstenv->nr_cpus_avail. Sinceal->cpucomes from the untrusted perf.data sample, a crafted file with a large CPU index causes an out-of-bounds heap read.Use
perf_env__get_cpu_topology()which validates both NULL and bounds. Also bounds-checkal->cpubefore the cast to structperf_cpu(int16_t):
without this, values like 65536 silently truncate to 0, bypassing the accessor's internal check and returning CPU 0's topology.Fixes 0c4c4debb0adda4c ("perf tools: Add processor socket info to hist_entry and addr_location")Reported-by sashiko-bot <[email protected]>Reviewed-by Ian Rogers <[email protected]>Cc Kan Liang <[email protected]>Cc Ian Rogers <[email protected]>Assisted-by Claude:claude-opus-4.6Signed-off-by Arnaldo Carvalho de Melo <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- tools/perf/util/event.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)tools/perf/util/event.c +13
-2@@ -12,6 +12,7 @@#include <linux/zalloc.h> #include "cpumap.h" #include "dso.h" +#include "env.h" #include "event.h" #include "debug.h" #include "hist.h" @@ -763,8 +764,18 @@ int machine__resolve(struct machine *machine, struct addr_location *al,if (al->cpu >=0 ) {struct perf_env *env = machine->env; -if (env && env->cpu) - al->socket = env->cpu[al->cpu].socket_id; +/* +* Bounds-check al->cpu (s32) before casting to struct perf_cpu +* (int16_t): without this, e.g. 65536 truncates to 0 and silently +* returns CPU 0's topology. Can go once perf_cpu.cpu is widened. +*/ +if (env && al->cpu < env->nr_cpus_avail) { +struct cpu_topology_map *topo; + + topo =perf_env__get_cpu_topology (env, (struct perf_cpu ){ al->cpu }); +if (topo) + al->socket = topo->socket_id; + } }if (al->map) {Signature · 1 line
2.53.0
Sasha Levin
maintainerRe: [PATCH 6.12 543/869] perf tools: Use perf_env__get_cpu_topology() in machine__resolve()
Quoted 4 lines · Wang Yugui
please drop this patch for 6.12.y or add some dependency.
because of the build error:
util/event.c:775:32: error: implicit declaration of function ‘perf_env__get_cpu_topology’; did you mean ‘perf_env__read_cpu_topology_map’? [-Wimplicit-function-declaration]
Dropped 5484b43a0ec8 ("perf tools: Use perf_env__get_cpu_topology() in machine__resolve()") from the 6.12 queue. It is also dropped from 6.6 and 6.1, where the same perf_env__get_cpu_topology() helper is missing.
Thanks for the report.
Signature · 2 lines
Thanks, Sasha
Greg Kroah-Hartman
maintainerPATCH 544/869 Bluetooth: hci_sync: hold conn in hci_connect_acl/le_sync() callbacks
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pauli Virtanen <[email protected]>
[ Upstream commit 2f5d635ad5906b0235bc0c870e8beba3116e1e98 ]
There is theoretical UAF if the conn is freed while the hci_sync task is running.
Hold refcount to avoid that.
--- net/bluetooth/hci_sync.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-)
net/bluetooth/hci_sync.c +24 -8
@@ -7149,12 +7149,23 @@ static int hci_acl_create_conn_sync(struct hci_dev *hdev, void *data)return err; } +static void hci_acl_create_conn_sync_complete (struct hci_dev *hdev,void *data, +int err) +{ +struct hci_conn *conn = data; + +hci_conn_put (conn); +} +int hci_connect_acl_sync (struct hci_dev *hdev,struct hci_conn *conn) {int err; - err =hci_cmd_sync_queue_once (hdev, hci_acl_create_conn_sync, conn, -NULL ); + err =hci_cmd_sync_queue_once (hdev, hci_acl_create_conn_sync, +hci_conn_get (conn), + hci_acl_create_conn_sync_complete); +if (err) +hci_conn_put (conn);return (err == -EEXIST ) ?0 : err; }
@@ -7165,36 +7176,41 @@ static void create_le_conn_complete(struct hci_dev *hdev, void *data, int err)bt_dev_dbg (hdev,"err %d" , err);if (err == -ECANCELED ) -return ; + goto done;hci_dev_lock (hdev);if (!hci_conn_valid (hdev, conn)) - goto done; + goto unlock;if (!err) {hci_connect_le_scan_cleanup (conn,0x00 ); - goto done; + goto unlock; }/* Check if connection is still pending */ if (conn !=hci_lookup_le_connect (hdev)) - goto done; + goto unlock;/* Flush to make sure we send create conn cancel command if needed */ flush_delayed_work (&conn->le_conn_timeout);hci_conn_failed (conn,bt_status (err)); -done: +unlock:hci_dev_unlock (hdev); +done: +hci_conn_put (conn); }int hci_connect_le_sync (struct hci_dev *hdev,struct hci_conn *conn) {int err; - err =hci_cmd_sync_queue_once (hdev, hci_le_create_conn_sync, conn, + err =hci_cmd_sync_queue_once (hdev, hci_le_create_conn_sync, +hci_conn_get (conn), create_le_conn_complete); +if (err) +hci_conn_put (conn);return (err == -EEXIST ) ?0 : err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 545/869 idpf: bound interrupt-vector register fill to the allocated array
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
[ Upstream commit 9f7007ee9858c99aa43101bc8352c672fee85644 ]
idpf_get_reg_intr_vecs() fills the caller-allocated reg_vals[] array from the VIRTCHNL2_OP_ALLOC_VECTORS reply in adapter->req_vec_chunks, bounding its inner loop only by the per-chunk num_vectors. The array is sized
separately: idpf_intr_reg_init() allocates kzalloc_objs(struct idpf_vec_regs, total_vecs) from caps.num_allocated_vectors and only checks the returned count after the fill. The sum of per-chunk num_vectors is never reconciled against total_vecs, so a reply with a small num_allocated_vectors but chunks summing higher writes past the end of reg_vals[].
Impact: a control plane (a PF or hypervisor device model) that returns a VIRTCHNL2_OP_ALLOC_VECTORS reply whose per-chunk num_vectors sum exceeds num_allocated_vectors writes struct idpf_vec_regs entries past the end of the reg_vals kmalloc allocation (KASAN slab-out-of-bounds write).
Bound the fill loop to the array capacity passed in by the callers, mirroring the sibling idpf_vport_get_q_reg(). The existing num_regs < num_vecs check then rejects an undersized reply without the out-of-bounds write happening first.
--- drivers/net/ethernet/intel/idpf/idpf_dev.c | 2 +- drivers/net/ethernet/intel/idpf/idpf_vf_dev.c | 2 +- drivers/net/ethernet/intel/idpf/idpf_virtchnl.c | 5 +++-- drivers/net/ethernet/intel/idpf/idpf_virtchnl.h | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_dev.c +1 -1
@@ -84,7 +84,7 @@ static int idpf_intr_reg_init(struct idpf_vport *vport,if (!reg_vals)return -ENOMEM ; - num_regs =idpf_get_reg_intr_vecs (vport, reg_vals); + num_regs =idpf_get_reg_intr_vecs (vport, reg_vals, total_vecs);if (num_regs < num_vecs) { err = -EINVAL ; goto free_reg_vals;
drivers/net/ethernet/intel/idpf/idpf_vf_dev.c +1 -1
@@ -84,7 +84,7 @@ static int idpf_vf_intr_reg_init(struct idpf_vport *vport,if (!reg_vals)return -ENOMEM ; - num_regs =idpf_get_reg_intr_vecs (vport, reg_vals); + num_regs =idpf_get_reg_intr_vecs (vport, reg_vals, total_vecs);if (num_regs < num_vecs) { err = -EINVAL ; goto free_reg_vals;
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +3 -2
@@ -1004,11 +1004,12 @@ static void idpf_init_avail_queues(struct idpf_adapter *adapter)* idpf_get_reg_intr_vecs - Get vector queue register offset * @vport: virtual port structure * @reg_vals: Register offsets to store in +* @num_vecs: number of entries the @reg_vals array can hold * * Returns number of registers that got populated */ int idpf_get_reg_intr_vecs (struct idpf_vport *vport, -struct idpf_vec_regs *reg_vals) +struct idpf_vec_regs *reg_vals,int num_vecs) {struct virtchnl2_vector_chunks *chunks;struct idpf_vec_regs reg_val;
@@ -1032,7 +1033,7 @@ int idpf_get_reg_intr_vecs(struct idpf_vport *vport, dynctl_reg_spacing =le32_to_cpu (chunk->dynctl_reg_spacing); itrn_reg_spacing =le32_to_cpu (chunk->itrn_reg_spacing); -for (i =0 ; i < num_vec; i++) { +for (i =0 ; i < num_vec && num_regs < num_vecs; i++) { reg_vals[num_regs].dyn_ctl_reg = reg_val.dyn_ctl_reg; reg_vals[num_regs].itrn_reg = reg_val.itrn_reg; reg_vals[num_regs].itrn_index_spacing =
drivers/net/ethernet/intel/idpf/idpf_virtchnl.h +1 -1
@@ -17,7 +17,7 @@ int idpf_vc_core_init(struct idpf_adapter *adapter);void idpf_vc_core_deinit (struct idpf_adapter *adapter);int idpf_get_reg_intr_vecs (struct idpf_vport *vport, -struct idpf_vec_regs *reg_vals); +struct idpf_vec_regs *reg_vals,int num_vecs);int idpf_queue_reg_init (struct idpf_vport *vport);int idpf_vport_queue_ids_init (struct idpf_vport *vport);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 546/869 dmaengine: idxd: fix double free of wq, engine, and group structs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuho Choi <[email protected]>
[ Upstream commit ec2d428b2e32dd157de8f86a86dd85c5b2c8f45c ]
The release callbacks for wq, engine, and group devices (idxd_conf_wq_release, idxd_conf_engine_release, idxd_conf_group_release) each call kfree() on the enclosing struct. The setup error paths and cleanup functions also call kfree() explicitly after put_device(), producing a double free whenever put_device() drops the reference count to zero and fires the release.
In the setup functions, device_initialize() is called before device_add(), so the reference count is exactly 1 at the error sites. put_device() unconditionally fires the release, which frees the struct; the subsequent explicit kfree() then operates on freed memory.
For idxd_setup_wqs(), the wq release callback also owns opcap_bmap and wqcfg. The error unwind additionally freed those fields explicitly before calling put_device(), causing further double frees on both.
Remove the redundant explicit kfree() calls from all setup error paths and cleanup functions for wq, engine, and group structs, delegating sole ownership of those allocations to the release callbacks.
--- drivers/dma/idxd/init.c | 36 +++++------------------------------- 1 file changed, 5 insertions(+), 31 deletions(-)
drivers/dma/idxd/init.c +5 -31
@@ -155,18 +155,12 @@ static void idxd_cleanup_interrupts(struct idxd_device *idxd)static void idxd_clean_wqs (struct idxd_device *idxd) { -struct idxd_wq *wq;struct device *conf_dev;int i;for (i =0 ; i < idxd->max_wqs; i++) { - wq = idxd->wqs[i]; -if (idxd->hw.wq_cap.op_config) -bitmap_free (wq->opcap_bmap); -kfree (wq->wqcfg); - conf_dev =wq_confdev (wq); + conf_dev =wq_confdev (idxd->wqs[i]);put_device (conf_dev); -kfree (wq); }bitmap_free (idxd->wq_enable_map);kfree (idxd->wqs);
@@ -208,7 +202,6 @@ static int idxd_setup_wqs(struct idxd_device *idxd) rc =dev_set_name (conf_dev,"wq%d.%d" , idxd->id, wq->id);if (rc <0 ) {put_device (conf_dev); -kfree (wq); goto err_unwind; }
@@ -222,7 +215,6 @@ static int idxd_setup_wqs(struct idxd_device *idxd) wq->wqcfg =kzalloc_node (idxd->wqcfg_size,GFP_KERNEL ,dev_to_node (dev));if (!wq->wqcfg) {put_device (conf_dev); -kfree (wq); rc = -ENOMEM ; goto err_unwind; }
@@ -230,9 +222,7 @@ static int idxd_setup_wqs(struct idxd_device *idxd)if (idxd->hw.wq_cap.op_config) { wq->opcap_bmap =bitmap_zalloc (IDXD_MAX_OPCAP_BITS ,GFP_KERNEL );if (!wq->opcap_bmap) { -kfree (wq->wqcfg);put_device (conf_dev); -kfree (wq); rc = -ENOMEM ; goto err_unwind; }
@@ -247,13 +237,8 @@ static int idxd_setup_wqs(struct idxd_device *idxd) err_unwind:while (--i >=0 ) { - wq = idxd->wqs[i]; -if (idxd->hw.wq_cap.op_config) -bitmap_free (wq->opcap_bmap); -kfree (wq->wqcfg); - conf_dev =wq_confdev (wq); + conf_dev =wq_confdev (idxd->wqs[i]);put_device (conf_dev); -kfree (wq); }bitmap_free (idxd->wq_enable_map);
@@ -265,15 +250,12 @@ static int idxd_setup_wqs(struct idxd_device *idxd)static void idxd_clean_engines (struct idxd_device *idxd) { -struct idxd_engine *engine;struct device *conf_dev;int i;for (i =0 ; i < idxd->max_engines; i++) { - engine = idxd->engines[i]; - conf_dev =engine_confdev (engine); + conf_dev =engine_confdev (idxd->engines[i]);put_device (conf_dev); -kfree (engine); }kfree (idxd->engines); }
@@ -308,7 +290,6 @@ static int idxd_setup_engines(struct idxd_device *idxd) rc =dev_set_name (conf_dev,"engine%d.%d" , idxd->id, engine->id);if (rc <0 ) {put_device (conf_dev); -kfree (engine); goto err; }
@@ -319,10 +300,8 @@ static int idxd_setup_engines(struct idxd_device *idxd) err:while (--i >=0 ) { - engine = idxd->engines[i]; - conf_dev =engine_confdev (engine); + conf_dev =engine_confdev (idxd->engines[i]);put_device (conf_dev); -kfree (engine); }kfree (idxd->engines);
@@ -331,13 +310,10 @@ static int idxd_setup_engines(struct idxd_device *idxd)static void idxd_clean_groups (struct idxd_device *idxd) { -struct idxd_group *group;int i;for (i =0 ; i < idxd->max_groups; i++) { - group = idxd->groups[i]; -put_device (group_confdev (group)); -kfree (group); +put_device (group_confdev (idxd->groups[i])); }kfree (idxd->groups); }
@@ -372,7 +348,6 @@ static int idxd_setup_groups(struct idxd_device *idxd) rc =dev_set_name (conf_dev,"group%d.%d" , idxd->id, group->id);if (rc <0 ) {put_device (conf_dev); -kfree (group); goto err; }
@@ -397,7 +372,6 @@ static int idxd_setup_groups(struct idxd_device *idxd)while (--i >=0 ) { group = idxd->groups[i];put_device (group_confdev (group)); -kfree (group); }kfree (idxd->groups);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 547/869 drm/amd/display: check if dml21_add_phantom_plane() is successful
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Deucher <[email protected]>
[ Upstream commit 000acb4ce7fb9feba3072ce468ad681f6585cd5d ]
Verify that the phantom plane was allocated to avoid a later segfault.
--- .../drm/amd/display/dc/dml2/dml21/dml21_utils.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/display/dc/dml2/dml21/dml21_utils.c +7 -8
@@ -457,14 +457,13 @@ void dml21_handle_phantom_streams_planes(const struct dc *dc, struct dc_state *c main_plane = main_stream_status->plane_states[dc_plane_index];/* create phantom planes for subvp enabled plane */ -dml21_add_phantom_plane (dml_ctx, - dc, - context, - phantom_stream, - main_plane, - &dml_ctx->v21.mode_programming.programming->plane_programming[dml_plane_index]); - - phantoms_added = true; +if (dml21_add_phantom_plane (dml_ctx, + dc, + context, + phantom_stream, + main_plane, + &dml_ctx->v21.mode_programming.programming->plane_programming[dml_plane_index])) + phantoms_added = true; } } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 548/869 btrfs: initialize inode mapping flags for cached inodes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
[ Upstream commit 0ef349734a93227b45f65fc50a3311d1cc5f03e9 ]
[BUG]
When running generic/795 with 8K block size, 4K page size, the test always fails, triggering some ASSERT()s related to folio size:
795 (241074): drop_caches: 3
assertion failed: IS_ALIGNED(start, blocksize) && IS_ALIGNED(end + 1, blocksize), in extent_io.c:1404 (blocksize=8192 root=262 ino=258 start=16826368 end=16830463 mapping min order=0)
------------[ cut here ]------------ kernel BUG at extent_io.c:1404! Oops: invalid opcode: 0000 [#1] SMP CPU: 8 UID: 0 PID: 241105 Comm: fsstress Tainted: G OE 7.2.0-rc5-custom+ #442 PREEMPT(full) f4bfb352566f3949f29c233ce6f735050a03b245 Tainted: [O]=OOT_MODULE, [E]=UNSIGNED_MODULE Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS unknown 02/02/2022 RIP: 0010:assert_folio_range.cold+0x3d/0x3f [btrfs] Call Trace: <TASK> btrfs_read_folio+0x9e/0x170 [btrfs 4cd1dd93b341b8ef766643f9512f4a86259567a3] prepare_one_folio.constprop.0+0x104/0x2a0 [btrfs 4cd1dd93b341b8ef766643f9512f4a86259567a3] btrfs_buffered_write+0x285/0xa50 [btrfs 4cd1dd93b341b8ef766643f9512f4a86259567a3] btrfs_do_write_iter+0x1aa/0x210 [btrfs 4cd1dd93b341b8ef766643f9512f4a86259567a3] iter_file_splice_write+0x31a/0x540 direct_splice_actor+0x53/0x170 splice_direct_to_actor+0xe9/0x240 do_splice_direct+0x76/0xb0 vfs_copy_file_range+0x1fd/0x630 __x64_sys_copy_file_range+0xf9/0x220 do_syscall_64+0xe1/0x790 entry_SYSCALL_64_after_hwframe+0x4b/0x53 </TASK> ---[ end trace 0000000000000000 ]---
The ASSERT() itself is added by a later patch.
The crash is triggered with that new debug patch, and without this fix.
[CAUSE]
In the above case, the start 16826368 is properly 8K aligned, but the end (16830463 + 1) is not 8K aligned.
Furthermore the mapping's minimal folio order is 0, not the expected 1 for 8K block size with 4K page size.
So this means some inodes do not have btrfs_set_inode_mapping_order() called on it.
The missing btrfs_set_inode_mapping_order() call happens for cached inodes, through the following events:
- btrfs_create_new_inode() called for inode X Which properly sets minimal folio order for the VFS inode.
- btrfs_update_inode() called for inode X
Which calls btrfs_delayed_update_inode() to create a delayed_node into root->delayed_nodes xarray.
- Drop cache/memory pressure, evicting in-memory inode X Which evicted the inode X, but delayed_node is still in root->delayed_nodes for future reuse.
- btrfs_iget() for inode X called again
btrfs_iget()
|- btrfs_iget_locked()
| |- iget5_locked_rcu()
| Which creates a new vfs_inode for btrfs, whose mapping still
| has the minimal order as 0.
|
|- btrfs_read_locked_inode()
|- btrfs_fill_inode()
| |- btrfs_get_delayed_node()
| Which found out the previous node, and use that delayed
| node to initialize the new inode.
|
|- filled = true;
|- if (filled) goto cache_index; Which skips the btrfs_update_inode_mapping_flags() and btrfs_set_inode_mapping_order() calls.
So the inode still has minimal folio order set as 0, not the required 1.
Thus later page cache read will get a folio whose size is smaller than block size, as the mapping has its minimal folio order set as 0 not 1, then trigger the ASSERT().
[FIX]
Move the btrfs_update_inode_mapping_flags() and btrfs_set_inode_mapping_order() calls under cache_index label, so that the mapping flags and minimal folio order is always set no matter if we have a cached inode.
--- fs/btrfs/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/inode.c +2 -1
@@ -3854,12 +3854,13 @@ static int btrfs_read_locked_inode(struct inode *inode,btrfs_inode_split_flags (btrfs_inode_flags (leaf, inode_item), &BTRFS_I (inode)->flags, &BTRFS_I (inode)->ro_flags); + +cache_index:if (BTRFS_I (inode)->flags &BTRFS_INODE_NODATASUM )mapping_clear_stable_writes (inode->i_mapping);else mapping_set_stable_writes (inode->i_mapping); -cache_index:/* * If we were modified in the current generation and evicted from memory * and then re-read we need to do a full sync since we don't have any
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 549/869 bpf: Check sk_state before sk_protocol in bpf_tcp_*_syncookie
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luxiao Xu <[email protected]>
[ Upstream commit 31a420a822ff92e2090bd5d65efe8e34e2d6d9b8 ]
bpf_tcp_gen_syncookie and bpf_tcp_check_syncookie accept a socket pointer 'sk' with argument type ARG_PTR_TO_BTF_ID_SOCK_COMMON. However, they access sk->sk_protocol without validating whether 'sk' represents a full socket.
Fix this issue by checking sk->sk_state != TCP_LISTEN before inspecting sk->sk_protocol in both bpf_tcp_gen_syncookie and bpf_tcp_check_syncookie. Since mini-sockets are never in the TCP_LISTEN state, the condition short-circuits and prevents dereferencing fullsock-specific fields.
--- net/core/filter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/filter.c +2 -2
@@ -7475,7 +7475,7 @@ BPF_CALL_5(bpf_tcp_check_syncookie, struct sock *, sk, void *, iph, u32, iph_lenreturn -EINVAL ;/* sk_listener() allows TCP_NEW_SYN_RECV, which makes no sense here. */ -if (sk->sk_protocol !=IPPROTO_TCP || sk->sk_state !=TCP_LISTEN ) +if (sk->sk_state !=TCP_LISTEN || sk->sk_protocol !=IPPROTO_TCP )return -EINVAL ;if (!READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_syncookies))
@@ -7548,7 +7548,7 @@ BPF_CALL_5(bpf_tcp_gen_syncookie, struct sock *, sk, void *, iph, u32, iph_len,if (unlikely (!sk || th_len <sizeof (*th) || th_len != th->doff *4 ))return -EINVAL ; -if (sk->sk_protocol !=IPPROTO_TCP || sk->sk_state !=TCP_LISTEN ) +if (sk->sk_state !=TCP_LISTEN || sk->sk_protocol !=IPPROTO_TCP )return -EINVAL ;if (!READ_ONCE (sock_net (sk)->ipv4.sysctl_tcp_syncookies))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 550/869 drm/amdkfd: Fix infinite loop parsing CRAT with zero subtype length
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yongqiang Sun <[email protected]>
[ Upstream commit 961323c26ad4c895e3b0ea1711fc41dfd6368c12 ]
Malformed ACPI CRAT tables can advertise a zero or undersized subtype length. The parser then fails to advance the cursor and loops forever while the remaining image still looks large enough for a generic header.
Validate sub_type_hdr->length on each iteration before parsing or advancing. Return -EINVAL and warn when length is zero or smaller than the generic subtype header.
Stable-dep-of: 6e7566ba4739 ("drm/amdkfd: Add bounds check for CRAT subtype length")
--- drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +8 -0
@@ -1403,6 +1403,14 @@ int kfd_parse_crat_table(void *crat_image, struct list_head *device_list, sub_type_hdr = (struct crat_subtype_generic *)(crat_table+1 );while ((char *)sub_type_hdr +sizeof (struct crat_subtype_generic ) < ((char *)crat_image) + image_len) { +if (!sub_type_hdr->length || + sub_type_hdr->length <sizeof (struct crat_subtype_generic )) { +pr_warn ("Invalid CRAT subtype length %u\n" , + sub_type_hdr->length); + ret = -EINVAL ; +break ; + } +if (sub_type_hdr->flags &CRAT_SUBTYPE_FLAGS_ENABLED ) { ret =kfd_parse_subtype (sub_type_hdr, device_list);if (ret)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 551/869 drm/amdkfd: Add bounds check for CRAT subtype length
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: William Palacek <[email protected]>
[ Upstream commit 6e7566ba4739dd573c331adde1c96690f7a567bd ]
The CRAT parser validates that the subtype header fits within the image, but does not verify that the advertised subtype length fits. A malformed CRAT table with an oversized length field causes out-of-bounds reads when kfd_parse_subtype() casts the header to specific subtype structures.
Add validation that sub_type_hdr + length does not exceed the image boundary before parsing the subtype contents.
--- drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +9 -0
@@ -1411,6 +1411,15 @@ int kfd_parse_crat_table(void *crat_image, struct list_head *device_list,break ; } +/* Validate subtype fits within remaining image */ +if ((char *)sub_type_hdr + sub_type_hdr->length > + (char *)crat_image + image_len) { +pr_warn ("CRAT subtype length %u exceeds image bounds\n" , + sub_type_hdr->length); + ret = -EINVAL ; +break ; + } +if (sub_type_hdr->flags &CRAT_SUBTYPE_FLAGS_ENABLED ) { ret =kfd_parse_subtype (sub_type_hdr, device_list);if (ret)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 552/869 Bluetooth: ISO: zero the sockaddr before returning it in getname
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ali Ahmet Memis <[email protected]>
[ Upstream commit 884cf2cc957da7ac178a0e6c6c69ddfec0481cc8 ]
iso_sock_getname() fills a struct sockaddr_iso in place and returns its size without clearing it first, so bytes it does not write are copied to user space from the kernel stack. The getsockname(2) and getpeername(2) paths both run through do_getsockname(), which hands getname() an uninitialized sockaddr_storage on the stack and copies back up to the number of bytes getname() returns, so the driver has to initialize every byte it accounts for.
Two ranges are left uninitialized:
- struct sockaddr_iso is 10 bytes but only 9 are written (family, iso_bdaddr, iso_bdaddr_type), leaking the trailing pad byte on every call.
- for a broadcast peer (BIS_LINK or PA_LINK) the returned length grows by sizeof(struct sockaddr_iso_bc), but only bc_sid, bc_num_bis and bc_bis are filled; bc_bdaddr and bc_bdaddr_type, the first 7 bytes of that structure, are never written.
An unprivileged process can open a BTPROTO_ISO socket and reach the pad leak with getsockname(); the broadcast leak needs an established BIS/PA connection. l2cap and rfcomm already memset their sockaddr in getname for the same reason; do the same here.
--- net/bluetooth/iso.c | 1 + 1 file changed, 1 insertion(+)
net/bluetooth/iso.c +1 -0
@@ -1397,6 +1397,7 @@ static int iso_sock_getname(struct socket *sock, struct sockaddr *addr,BT_DBG ("sock %p, sk %p" , sock, sk); +memset (sa,0 ,sizeof (struct sockaddr_iso )); addr->sa_family =AF_BLUETOOTH ;if (peer) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 553/869 fbdev: Wrap user-invoked calls to fb_set_var() in helper
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Zimmermann <[email protected]>
[ Upstream commit 6f611e5e5f3327cf2e2daabe6ee5acac58cc784e ]
Handle fbcon during display updates in fb_set_var_from_user(). Check with fbcon if the mode change is possible, update hardware state and finally update fbcon. Update all callers.
Only the FBIOPUT_VSCREENINFO ioctl currently does all steps. Other mode-changes callers in sysfs and driver code are missing fbcon-related steps.
With the new helper, ps3fb and sh_mobile_lcdcfb no longer maintain fbcon state themselves.
--- drivers/video/fbdev/core/fb_chrdev.c | 6 +----- drivers/video/fbdev/core/fbcon.c | 2 -- drivers/video/fbdev/core/fbmem.c | 13 +++++++++++++ drivers/video/fbdev/core/fbsysfs.c | 4 +--- drivers/video/fbdev/ps3fb.c | 5 +---- drivers/video/fbdev/sh_mobile_lcdcfb.c | 5 +---- include/linux/fb.h | 2 ++ 7 files changed, 19 insertions(+), 18 deletions(-)
drivers/video/fbdev/core/fb_chrdev.c +1 -5
@@ -85,11 +85,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd, var.activate &= ~FB_ACTIVATE_KD_TEXT ;console_lock ();lock_fb_info (info); - ret =fbcon_modechange_possible (info, &var); -if (!ret) - ret =fb_set_var (info, &var); -if (!ret) -fbcon_update_vcs (info, var.activate &FB_ACTIVATE_ALL ); + ret =fb_set_var_from_user (info, &var);unlock_fb_info (info);console_unlock ();if (!ret &©_to_user (argp, &var,sizeof (var)))
drivers/video/fbdev/core/fbcon.c +0 -2
@@ -2754,7 +2754,6 @@ void fbcon_update_vcs(struct fb_info *info, bool all)else fbcon_modechanged (info); } -EXPORT_SYMBOL (fbcon_update_vcs);/* let fbcon check if it supports a new screen resolution */ int fbcon_modechange_possible (struct fb_info *info,struct fb_var_screeninfo *var)
@@ -2782,7 +2781,6 @@ int fbcon_modechange_possible(struct fb_info *info, struct fb_var_screeninfo *vareturn 0 ; } -EXPORT_SYMBOL_GPL (fbcon_modechange_possible);int fbcon_mode_deleted (struct fb_info *info,struct fb_videomode *mode)
drivers/video/fbdev/core/fbmem.c +13 -0
@@ -341,6 +341,19 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var) }EXPORT_SYMBOL (fb_set_var); +int fb_set_var_from_user (struct fb_info *info,struct fb_var_screeninfo *var) +{ +int ret =fbcon_modechange_possible (info, var); + +if (!ret) + ret =fb_set_var (info, var); +if (!ret) +fbcon_update_vcs (info, var->activate &FB_ACTIVATE_ALL ); + +return ret; +} +EXPORT_SYMBOL (fb_set_var_from_user); +int fb_blank (struct fb_info *info,int blank) {
drivers/video/fbdev/core/fbsysfs.c +1 -3
@@ -22,9 +22,7 @@ static int activate(struct fb_info *fb_info, struct fb_var_screeninfo *var) var->activate |=FB_ACTIVATE_FORCE ;console_lock ();lock_fb_info (fb_info); - err =fb_set_var (fb_info, var); -if (!err) -fbcon_update_vcs (fb_info, var->activate &FB_ACTIVATE_ALL ); + err =fb_set_var_from_user (fb_info, var);unlock_fb_info (fb_info);console_unlock ();if (err)
drivers/video/fbdev/ps3fb.c +1 -4
@@ -29,7 +29,6 @@#include <linux/freezer.h> #include <linux/uaccess.h> #include <linux/fb.h> -#include <linux/fbcon.h> #include <linux/init.h> #include <asm/cell-regs.h>
@@ -830,9 +829,7 @@ static int ps3fb_ioctl(struct fb_info *info, unsigned int cmd,/* Force, in case only special bits changed */ var.activate |=FB_ACTIVATE_FORCE ; par->new_mode_id = val; - retval =fb_set_var (info, &var); -if (!retval) -fbcon_update_vcs (info, var.activate &FB_ACTIVATE_ALL ); + retval =fb_set_var_from_user (info, &var);console_unlock (); }break ;
drivers/video/fbdev/sh_mobile_lcdcfb.c +1 -4
@@ -15,7 +15,6 @@#include <linux/ctype.h> #include <linux/dma-mapping.h> #include <linux/delay.h> -#include <linux/fbcon.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/ioctl.h>
@@ -1769,11 +1768,9 @@ static void sh_mobile_fb_reconfig(struct fb_info *info) var.height = ch->display.height; var.activate =FB_ACTIVATE_NOW ; -if (fb_set_var (info, &var) <0 ) +if (fb_set_var_from_user (info, &var) <0 )/* Couldn't reconfigure, hopefully, can continue as before */ return ; - -fbcon_update_vcs (info, true); }/*
include/linux/fb.h +2 -0
@@ -537,6 +537,8 @@ extern int fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var);extern int fb_pan_display (struct fb_info *info,struct fb_var_screeninfo *var);extern int fb_blank (struct fb_info *info,int blank); +int fb_set_var_from_user (struct fb_info *info,struct fb_var_screeninfo *var); +/* * Helpers for framebuffers in I/O memory */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 554/869 tipc: avoid busy looping in tipc_exit_net()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit c1481c94e74c955e0448ddf46b8615a44d840c1e ]
Blamed commit introduced a busy-wait loop in tipc_exit_net() to wait for pending UDP bearer cleanup works to complete:
while (atomic_read(&tn->wq_count))
cond_resched();This loop can busy-wait for a long time if cond_resched() is a NOP. This typically happens if the netns exit is executed by a high priority task, or under kernels configured without preemption (CONFIG_PREEMPT_NONE). In such cases, it wastes CPU cycles and can lead to soft lockups.
Fix this by replacing the busy loop with wait_var_event(), allowing the thread to sleep properly until the work queue count reaches zero.
Accordingly, update cleanup_bearer() to use atomic_dec_and_test() and wake_up_var() to wake up the waiter when the count drops to zero.
This uses the global wait queue hash table, avoiding the need to bloat struct tipc_net with a wait_queue_head_t. The atomic_dec_and_test() provides the necessary memory barrier to ensure the wakeup is not missed.
--- net/tipc/core.c | 4 ++-- net/tipc/udp_media.c | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-)
net/tipc/core.c +2 -2
@@ -45,6 +45,7 @@#include "crypto.h" #include <linux/module.h> +#include <linux/wait_bit.h> /* configurable TIPC parameters */ unsigned int tipc_net_id__read_mostly ;
@@ -118,8 +119,7 @@ static void __net_exit tipc_exit_net(struct net *net)#ifdef CONFIG_TIPC_CRYPTO tipc_crypto_stop (&tipc_net (net)->crypto_tx);#endif -while (atomic_read (&tn->wq_count)) -cond_resched (); +wait_var_event (&tn->wq_count,atomic_read (&tn->wq_count) ==0 ); } static void __net_exit tipc_pernet_pre_exit(struct net *net)
net/tipc/udp_media.c +3 -1
@@ -40,6 +40,7 @@#include <linux/igmp.h> #include <linux/kernel.h> #include <linux/workqueue.h> +#include <linux/wait_bit.h> #include <linux/list.h> #include <net/sock.h> #include <net/ip.h>
@@ -827,7 +828,8 @@ static void cleanup_bearer(struct work_struct *work)synchronize_net ();dst_cache_destroy (&ub->rcast.dst_cache); -atomic_dec (&tn->wq_count); +if (atomic_dec_and_test (&tn->wq_count)) +wake_up_var (&tn->wq_count);kfree (ub); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 555/869 NTB: core: Add .get_dma_dev() callback to ntb_dev_ops
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
[ Upstream commit 362a4549f2acfb03390ddfcd91041e65a11a739f ]
Some NTB implementations are backed by a PCI function that is not the right struct device to use with DMA API helpers (e.g. due to IOMMU topology, or because the NTB device is virtual).
Add an optional .get_dma_dev() callback to struct ntb_dev_ops and provide a helper, ntb_get_dma_dev(), so NTB clients can use the appropriate struct device for DMA allocations and mappings.
If the callback is not implemented, ntb_get_dma_dev() returns the current default (ntb->dev.parent). Drivers that implement .get_dma_dev() must return a non-NULL device.
Stable-dep-of: da6d997ac556 ("ntb: Store original DMA address for future release")
--- include/linux/ntb.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
include/linux/ntb.h +24 -0
@@ -256,6 +256,7 @@ static inline int ntb_ctx_ops_is_valid(const struct ntb_ctx_ops *ops)* @msg_clear_mask: See ntb_msg_clear_mask(). * @msg_read: See ntb_msg_read(). * @peer_msg_write: See ntb_peer_msg_write(). +* @get_dma_dev: See ntb_get_dma_dev(). */ struct ntb_dev_ops {int (*port_number)(struct ntb_dev *ntb);
@@ -329,6 +330,7 @@ struct ntb_dev_ops {int (*msg_clear_mask)(struct ntb_dev *ntb,u64 mask_bits);u32 (*msg_read)(struct ntb_dev *ntb,int *pidx,int midx);int (*peer_msg_write)(struct ntb_dev *ntb,int pidx,int midx,u32 msg); +struct device *(*get_dma_dev)(struct ntb_dev *ntb); };static inline int ntb_dev_ops_is_valid (const struct ntb_dev_ops *ops)
@@ -391,6 +393,8 @@ static inline int ntb_dev_ops_is_valid(const struct ntb_dev_ops *ops)/* !ops->msg_clear_mask == !ops->msg_count && */ !ops->msg_read == !ops->msg_count && !ops->peer_msg_write == !ops->msg_count && + +/* ops->get_dma_dev is optional */ 1 ; }
@@ -1563,6 +1567,26 @@ static inline int ntb_peer_msg_write(struct ntb_dev *ntb, int pidx, int midx,return ntb->ops->peer_msg_write (ntb, pidx, midx, msg); } +/** +* ntb_get_dma_dev() - get the device to use for DMA allocations/mappings +* @ntb: NTB device context. +* +* Return a struct device suitable for DMA API allocations and mappings. +* This is typically the parent of the NTB device, but may be overridden by a +* driver by implementing .get_dma_dev(). +* +* Drivers that implement .get_dma_dev() must return a non-NULL pointer. +* +* Return: device pointer to use for DMA operations. +*/ +static inline struct device *ntb_get_dma_dev (struct ntb_dev *ntb) +{ +if (!ntb->ops->get_dma_dev) +return ntb->dev.parent; + +return ntb->ops->get_dma_dev (ntb); +} +/** * ntb_peer_resource_idx() - get a resource index for a given peer idx * @ntb: NTB device context.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 556/869 NTB: ntb_transport: Use ntb_get_dma_dev() for DMA buffers
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
[ Upstream commit 852b94ff92cbe26a0dbb15eed9474f5493767f3b ]
ntb_transport currently uses ndev->pdev->dev for coherent allocations and frees.
Switch the coherent buffer allocation/free paths to use ntb_get_dma_dev(), so ntb_transport can work with NTB implementations where the NTB PCI function is not the right device to use for DMA mappings.
Stable-dep-of: da6d997ac556 ("ntb: Store original DMA address for future release")
--- drivers/ntb/ntb_transport.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/ntb/ntb_transport.c +7 -7
@@ -793,13 +793,13 @@ static void ntb_transport_msi_desc_changed(void *data)static void ntb_free_mw (struct ntb_transport_ctx *nt,int num_mw) {struct ntb_transport_mw *mw = &nt->mw_vec[num_mw]; -struct pci_dev *pdev = nt->ndev->pdev; +struct device *dma_dev =ntb_get_dma_dev (nt->ndev);if (!mw->virt_addr)return ;ntb_mw_clear_trans (nt->ndev,PIDX , num_mw); -dma_free_coherent (&pdev->dev, mw->alloc_size, +dma_free_coherent (dma_dev, mw->alloc_size, mw->alloc_addr, mw->dma_addr); mw->xlat_size =0 ; mw->buff_size =0 ;
@@ -869,7 +869,7 @@ static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw, resource_size_t size) {struct ntb_transport_mw *mw = &nt->mw_vec[num_mw]; -struct pci_dev *pdev = nt->ndev->pdev; +struct device *dma_dev =ntb_get_dma_dev (nt->ndev);size_t xlat_size, buff_size;resource_size_t xlat_align;resource_size_t xlat_align_size;
@@ -898,12 +898,12 @@ static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw, mw->buff_size = buff_size; mw->alloc_size = buff_size; - rc =ntb_alloc_mw_buffer (mw, &pdev->dev, xlat_align); + rc =ntb_alloc_mw_buffer (mw, dma_dev, xlat_align);if (rc) { mw->alloc_size *=2 ; - rc =ntb_alloc_mw_buffer (mw, &pdev->dev, xlat_align); + rc =ntb_alloc_mw_buffer (mw, dma_dev, xlat_align);if (rc) { -dev_err (&pdev->dev, +dev_err (dma_dev,"Unable to alloc aligned MW buff\n" ); mw->xlat_size =0 ; mw->buff_size =0 ;
@@ -916,7 +916,7 @@ static int ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw, rc =ntb_mw_set_trans (nt->ndev,PIDX , num_mw, mw->dma_addr, mw->xlat_size);if (rc) { -dev_err (&pdev->dev,"Unable to set mw%d translation" , num_mw); +dev_err (dma_dev,"Unable to set mw%d translation" , num_mw);ntb_free_mw (nt, num_mw);return -EIO ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 557/869 ntb: Store original DMA address for future release
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leon Romanovsky <[email protected]>
[ Upstream commit da6d997ac556479c112554ab5d95cbd04683eb11 ]
The DMA API requires that dma_free_attrs receive the exact dma_handle originally returned by the allocation function. Do not modify it.
--- drivers/ntb/ntb_transport.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/ntb/ntb_transport.c +3 -1
@@ -211,6 +211,7 @@ struct ntb_transport_mw {void *alloc_addr;void *virt_addr;dma_addr_t dma_addr; +dma_addr_t original_dma_addr; };struct ntb_transport_client_dev {
@@ -800,7 +801,7 @@ static void ntb_free_mw(struct ntb_transport_ctx *nt, int num_mw)ntb_mw_clear_trans (nt->ndev,PIDX , num_mw);dma_free_coherent (dma_dev, mw->alloc_size, - mw->alloc_addr, mw->dma_addr); + mw->alloc_addr, mw->original_dma_addr); mw->xlat_size =0 ; mw->buff_size =0 ; mw->alloc_size =0 ;
@@ -836,6 +837,7 @@ static int ntb_alloc_mw_buffer(struct ntb_transport_mw *mw,return -ENOMEM ; } virt_addr = alloc_addr; + mw->original_dma_addr = dma_addr;/* * we must ensure that the memory address allocated is BAR size
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 558/869 tap: Keep hdr_len in tap_get_user()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Akihiko Odaki <[email protected]>
[ Upstream commit 74212f20f366db41dd3148b951284ac38ef9bb10 ]
hdr_len is repeatedly used so keep it in a local variable.
Stable-dep-of: cbb35cbe8db2 ("net: tap: fix wrong transport_header when sending VLAN-tagged frame")
--- drivers/net/tap.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-)
drivers/net/tap.c +10 -18
@@ -645,6 +645,7 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,int err;struct virtio_net_hdr vnet_hdr = {0 };int vnet_hdr_len =0 ; +int hdr_len =0 ;int copylen =0 ;int depth;bool zerocopy = false;
@@ -663,13 +664,13 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,if (!copy_from_iter_full (&vnet_hdr,sizeof (vnet_hdr), from)) goto err;iov_iter_advance (from, vnet_hdr_len -sizeof (vnet_hdr)); -if ((vnet_hdr.flags &VIRTIO_NET_HDR_F_NEEDS_CSUM ) && -tap16_to_cpu (q, vnet_hdr.csum_start) + -tap16_to_cpu (q, vnet_hdr.csum_offset) +2 > -tap16_to_cpu (q, vnet_hdr.hdr_len)) - vnet_hdr.hdr_len =cpu_to_tap16 (q, -tap16_to_cpu (q, vnet_hdr.csum_start) + -tap16_to_cpu (q, vnet_hdr.csum_offset) +2 ); + hdr_len =tap16_to_cpu (q, vnet_hdr.hdr_len); +if (vnet_hdr.flags &VIRTIO_NET_HDR_F_NEEDS_CSUM ) { + hdr_len =max (tap16_to_cpu (q, vnet_hdr.csum_start) + +tap16_to_cpu (q, vnet_hdr.csum_offset) +2 , + hdr_len); + vnet_hdr.hdr_len =cpu_to_tap16 (q, hdr_len); + } err = -EINVAL ;if (tap16_to_cpu (q, vnet_hdr.hdr_len) > len) goto err;
@@ -682,12 +683,7 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,if (msg_control &&sock_flag (&q->sk,SOCK_ZEROCOPY )) {struct iov_iter i; - copylen = vnet_hdr.hdr_len ? -tap16_to_cpu (q, vnet_hdr.hdr_len) :GOODCOPY_LEN ; -if (copylen > good_linear) - copylen = good_linear; -else if (copylen <ETH_HLEN ) - copylen =ETH_HLEN ; + copylen =clamp (hdr_len ?:GOODCOPY_LEN ,ETH_HLEN , good_linear); linear = copylen; i = *from;iov_iter_advance (&i, copylen);
@@ -697,11 +693,7 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,if (!zerocopy) { copylen = len; - linear =tap16_to_cpu (q, vnet_hdr.hdr_len); -if (linear > good_linear) - linear = good_linear; -else if (linear <ETH_HLEN ) - linear =ETH_HLEN ; + linear =clamp (hdr_len,ETH_HLEN , good_linear); } skb = tap_alloc_skb(&q->sk, TAP_RESERVE, copylen,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 559/869 net: tap: fix wrong transport_header when sending VLAN-tagged frame
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wei Fang <[email protected]>
[ Upstream commit cbb35cbe8db268fefe34c23df15348cf99025298 ]
In tap_get_user_xdp(), when processing a VLAN-tagged frame (e.g. ETH_P_8021Q), skb_set_network_header() is called first to advance network_header past the VLAN tag to the inner protocol header. skb_probe_transport_header() is then called with skb->protocol still set to ETH_P_8021Q, while nhoff (derived from skb_network_offset()) already points past the VLAN tag to the inner protocol header.
In __skb_flow_dissect(), proto is initialized to ETH_P_8021Q and nhoff points past the VLAN tag. When the dissector hits case ETH_P_8021Q, it reads a struct vlan_hdr at the current nhoff via __skb_header_pointer(), but that offset contains the inner protocol header (e.g. an IP header). The bytes are misinterpreted as a VLAN header, yielding a garbage encapsulated EtherType that matches no known protocol. The dissector returns false, so skb_probe_transport_header() never calls skb_set_transport_header(), leaving transport_header at its uninitialized sentinel value (~0U).
Move skb_set_network_header() to after skb_probe_transport_header(). At the time skb_probe_transport_header() is called, network_header still points to the VLAN header (offset ETH_HLEN), so nhoff is correct and the flow dissector can parse the VLAN header, extract the inner EtherType, and advance nhoff to the inner protocol header, allowing transport_header to be set correctly.
--- drivers/net/tap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/tap.c +2 -1
@@ -1208,12 +1208,13 @@ static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp) } } +skb_probe_transport_header (skb); +/* Move network header to the right position for VLAN tagged packets */ if (eth_type_vlan (skb->protocol) &&vlan_get_protocol_and_depth (skb, skb->protocol, &depth) !=0 )skb_set_network_header (skb, depth); -skb_probe_transport_header (skb);dev_queue_xmit (skb);rcu_read_unlock ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 560/869 io_uring: defer eventfd signaling when queued from a wakeup handler
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jens Axboe <[email protected]>
[ Upstream commit cd305ee3633a45fcf5f3a5d83f99f3cb77d87b6e ]
io_req_local_work_add() signals the CQ ring eventfd inline when it is the one to push the first entry onto ->work_list. For DEFER_TASKRUN rings that add is frequently done from a waitqueue wakeup handler, where an arbitrary waitqueue lock is held.
eventfd_signal_mask() only refuses to recurse when current->in_eventfd is set, but that bit is set by eventfd_signal_mask() itself. If the wake chain starts somewhere else, signal goes out inline and can feed back into epoll.
Add IOU_F_TWQ_IN_WAKE, set it on the task_work add done from the three waitqueue callbacks, and use it to force io_eventfd_signal() down the existing call_rcu_hurry() deferral instead of signaling inline.
--- include/linux/io_uring_types.h | 8 ++++++++ io_uring/eventfd.c | 6 +++--- io_uring/eventfd.h | 2 +- io_uring/futex.c | 4 ++-- io_uring/io_uring.c | 2 +- io_uring/poll.c | 23 ++++++++++++----------- io_uring/waitid.c | 2 +- 7 files changed, 28 insertions(+), 19 deletions(-)
include/linux/io_uring_types.h +8 -0
@@ -17,6 +17,14 @@ enum {* It's also ignored unless IORING_SETUP_DEFER_TASKRUN is set. */ IOU_F_TWQ_LAZY_WAKE =1 , + +/* +* Set when task_work is queued from a waitqueue wakeup handler, where +* an arbitrary provider waitqueue lock is held. Signaling the CQ ring +* eventfd inline from there can recurse back into that lock through +* epoll, so the eventfd signal must be deferred. +*/ + IOU_F_TWQ_IN_WAKE = 2, }; enum io_uring_cmd_flags {
io_uring/eventfd.c +3 -3
@@ -41,7 +41,7 @@ static void io_eventfd_do_signal(struct rcu_head *rcu)call_rcu (&ev_fd->rcu, io_eventfd_free); } -void io_eventfd_signal (struct io_ring_ctx *ctx) +void io_eventfd_signal (struct io_ring_ctx *ctx,bool defer) {struct io_ev_fd *ev_fd =NULL ;
@@ -68,7 +68,7 @@ void io_eventfd_signal(struct io_ring_ctx *ctx)if (ev_fd->eventfd_async && !io_wq_current_is_worker ()) goto out; -if (likely (eventfd_signal_allowed ())) { +if (likely (!defer &&eventfd_signal_allowed ())) {eventfd_signal_mask (ev_fd->cq_ev_fd,EPOLL_URING_WAKE ); }else {if (!atomic_fetch_or (BIT (IO_EVENTFD_OP_SIGNAL_BIT ), &ev_fd->ops)) {
@@ -101,7 +101,7 @@ void io_eventfd_flush_signal(struct io_ring_ctx *ctx)if (skip)return ; -io_eventfd_signal (ctx); +io_eventfd_signal (ctx, false); } int io_eventfd_register(struct io_ring_ctx *ctx, void __user *arg,
io_uring/eventfd.h +1 -1
@@ -5,4 +5,4 @@ int io_eventfd_register(struct io_ring_ctx *ctx, void __user *arg,int io_eventfd_unregister (struct io_ring_ctx *ctx);void io_eventfd_flush_signal (struct io_ring_ctx *ctx); -void io_eventfd_signal (struct io_ring_ctx *ctx); +void io_eventfd_signal (struct io_ring_ctx *ctx,bool defer);
io_uring/futex.c +2 -2
@@ -201,7 +201,7 @@ static void io_futex_wakev_fn(struct wake_q_head *wake_q, struct futex_q *q)io_req_set_res (req,0 ,0 ); req->io_task_work.func = io_futexv_complete; -io_req_task_work_add (req); +__io_req_task_work_add (req,IOU_F_TWQ_IN_WAKE ); }int io_futexv_prep (struct io_kiocb *req,const struct io_uring_sqe *sqe)
@@ -248,7 +248,7 @@ static void io_futex_wake_fn(struct wake_q_head *wake_q, struct futex_q *q)io_req_set_res (req,0 ,0 ); req->io_task_work.func = io_futex_complete; -io_req_task_work_add (req); +__io_req_task_work_add (req,IOU_F_TWQ_IN_WAKE ); }static struct io_futex_data *io_alloc_ifd (struct io_ring_ctx *ctx)
io_uring/io_uring.c +1 -1
@@ -1201,7 +1201,7 @@ static inline void io_req_local_work_add(struct io_kiocb *req,if (ctx->flags &IORING_SETUP_TASKRUN_FLAG )atomic_or (IORING_SQ_TASKRUN , &ctx->rings->sq_flags);if (ctx->has_evfd) -io_eventfd_signal (ctx); +io_eventfd_signal (ctx, flags &IOU_F_TWQ_IN_WAKE ); } nr_wait =atomic_read (&ctx->cq_wait_nr);
io_uring/poll.c +12 -11
@@ -231,9 +231,9 @@ enum { IOU_POLL_REQUEUE = 4, }; -static void __io_poll_execute (struct io_kiocb *req,int mask) +static void __io_poll_execute (struct io_kiocb *req,int mask,unsigned tw_flags) { -unsigned flags =0 ; +unsigned flags = tw_flags;io_req_set_res (req, mask,0 ); req->io_task_work.func = io_poll_task_func;
@@ -241,14 +241,15 @@ static void __io_poll_execute(struct io_kiocb *req, int mask)trace_io_uring_task_add (req, mask);if (!(req->flags &REQ_F_POLL_NO_LAZY )) - flags =IOU_F_TWQ_LAZY_WAKE ; + flags |=IOU_F_TWQ_LAZY_WAKE ;__io_req_task_work_add (req, flags); } -static inline void io_poll_execute (struct io_kiocb *req,int res) +static inline void io_poll_execute (struct io_kiocb *req,int res, +unsigned tw_flags) {if (io_poll_get_ownership (req)) -__io_poll_execute (req, res); +__io_poll_execute (req, res, tw_flags); }/*
@@ -363,7 +364,7 @@ void io_poll_task_func(struct io_kiocb *req, struct io_tw_state *ts)if (ret ==IOU_POLL_NO_ACTION ) {return ; }else if (ret ==IOU_POLL_REQUEUE ) { -__io_poll_execute (req,0 ); +__io_poll_execute (req,0 ,0 );return ; }io_poll_remove_entries (req);
@@ -401,7 +402,7 @@ static void io_poll_cancel_req(struct io_kiocb *req) {io_poll_mark_cancelled (req);/* kick tw, which should complete the request */ -io_poll_execute (req,0 ); +io_poll_execute (req,0 ,0 ); }#define IO_ASYNC_POLL_COMMON (EPOLLONESHOT | EPOLLPRI)
@@ -410,7 +411,7 @@ static __cold int io_pollfree_wake(struct io_kiocb *req, struct io_poll *poll) {io_poll_mark_cancelled (req);/* we have to kick tw in case it's not already */ -io_poll_execute (req,0 ); +io_poll_execute (req,0 ,IOU_F_TWQ_IN_WAKE );/* * If the waitqueue is being freed early but someone is already
@@ -465,7 +466,7 @@ static int io_poll_wake(struct wait_queue_entry *wait, unsigned mode, int sync,else req->flags &= ~REQ_F_SINGLE_POLL ; } -__io_poll_execute (req, mask); +__io_poll_execute (req, mask,IOU_F_TWQ_IN_WAKE ); }return 1 ; }
@@ -657,7 +658,7 @@ static int __io_arm_poll_handler(struct io_kiocb *req,if (mask && (poll->events &EPOLLET ) &&io_poll_can_finish_inline (req, ipt)) { -__io_poll_execute (req, mask); +__io_poll_execute (req, mask,0 );return 0 ; }io_napi_add (req);
@@ -668,7 +669,7 @@ static int __io_arm_poll_handler(struct io_kiocb *req,* poll was waken up, queue up a tw, it'll deal with it. */ if (atomic_cmpxchg (&req->poll_refs,1 ,0 ) !=1 ) -__io_poll_execute (req,0 ); +__io_poll_execute (req,0 ,0 ); }return 0 ; }
io_uring/waitid.c +1 -1
@@ -298,7 +298,7 @@ static int io_waitid_wait(struct wait_queue_entry *wait, unsigned mode,return 1 ; req->io_task_work.func = io_waitid_cb; -io_req_task_work_add (req); +__io_req_task_work_add (req,IOU_F_TWQ_IN_WAKE );return 1 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 561/869 wifi: iwlwifi: dvm: pair transport op-mode enter/leave
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Berg <[email protected]>
[ Upstream commit 6b340a694cee9e7a24b2be827c738b5b6cb13c84 ]
If there's a failure and the op-mode didn't actually fully initialize, it should leave the transport again. Fix that.
Stable-dep-of: 67105abd6195 ("wifi: iwlwifi: dvm: fix memory leak in iwl_op_mode_dvm_start()")
--- drivers/net/wireless/intel/iwlwifi/dvm/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/wireless/intel/iwlwifi/dvm/main.c +4 -2
@@ -1386,14 +1386,14 @@ static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans, err =iwl_trans_start_hw (priv->trans);if (err) - goto out_free_hw; + goto out_leave_trans;/* Read the EEPROM */ err =iwl_read_eeprom (priv->trans, &priv->eeprom_blob, &priv->eeprom_blob_size);if (err) {IWL_ERR (priv,"Unable to init EEPROM\n" ); - goto out_free_hw; + goto out_leave_trans; }/* Reset chip to save power until we load uCode during "up". */
@@ -1516,6 +1516,8 @@ static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,kfree (priv->eeprom_blob); out_free_eeprom:kfree (priv->nvm_data); +out_leave_trans: +iwl_trans_op_mode_leave (priv->trans); out_free_hw:ieee80211_free_hw (priv->hw); out:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 562/869 wifi: iwlwifi: dvm: fix memory leak in iwl_op_mode_dvm_start()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dawei Feng <[email protected]>
[ Upstream commit 67105abd6195a685a84dcb8a5daf54a1f4bfdb60 ]
In iwl_op_mode_dvm_start(), jumping to out_free_eeprom currently bypasses the out_free_eeprom_blob label. Consequently, error paths triggered after successfully parsing the EEPROM free priv->nvm_data but leak priv->eeprom_blob.
Fix this memory leak by reordering the error handling labels so that out_free_eeprom falls through to out_free_eeprom_blob.
The bug was first flagged by an experimental analysis tool we are developing for kernel memory-management bugs while analyzing v6.13-rc1. The tool is still under development and is not yet publicly available. Manual inspection confirms that the bug is still present in v7.1-rc6.
An x86_64 allyesconfig build showed no new warnings. As we do not have supported Intel DVM wireless hardware and firmware to test with, no runtime testing was able to be performed.
--- drivers/net/wireless/intel/iwlwifi/dvm/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/intel/iwlwifi/dvm/main.c +2 -2
@@ -1512,10 +1512,10 @@ static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans, priv->workqueue =NULL ; out_uninit_drv:iwl_uninit_drv (priv); -out_free_eeprom_blob: -kfree (priv->eeprom_blob); out_free_eeprom:kfree (priv->nvm_data); +out_free_eeprom_blob: +kfree (priv->eeprom_blob); out_leave_trans:iwl_trans_op_mode_leave (priv->trans); out_free_hw:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 563/869 svcrdma: Reject Read lists that exceed the page budget
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 0ca487abb3bdf581851664b5db21f364caf57682 ]
Individual Read segment lengths are validated at decode time, but nothing prevents a requester from sending multiple segments whose cumulative length exceeds the rq_pages array budget. When one segment fills the page array exactly, the runtime guard in svc_rdma_build_read_segment() is bypassed because len reaches zero. A subsequent segment then accesses the NULL sentinel slot at rq_pages[rq_maxpages], resulting in a NULL pointer dereference during DMA mapping.
Accumulate pages across all Read segments and reject the message at decode time when the total would overflow the page budget.
--- net/sunrpc/xprtrdma/svc_rdma_recvfrom.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c +11 -2
@@ -430,11 +430,14 @@ static void svc_rdma_build_arg_xdr(struct svc_rqst *rqstp,* to the first byte past the Read list. rc_read_pcl and * rc_call_pcl cl_count fields are set to the number of * Read segments in the list. -* %false: Read list is corrupt. @rctxt's xdr_stream is left in an -* unknown state. +* %false: Read list is corrupt or exceeds the page budget. @rctxt's +* xdr_stream is left in an unknown state. */ static bool xdr_count_read_segments (struct svc_rdma_recv_ctxt *rctxt,__be32 *p) { +unsigned int maxlen = (rctxt->rc_maxpages -2 ) <<PAGE_SHIFT ; +unsigned int total_len =0 ; + rctxt->rc_call_pcl.cl_count =0 ; rctxt->rc_read_pcl.cl_count =0 ;while (xdr_item_is_present (p)) {
@@ -448,6 +451,12 @@ static bool xdr_count_read_segments(struct svc_rdma_recv_ctxt *rctxt, __be32 *p)xdr_decode_read_segment (p, &position, &handle, &length, &offset); +if (length > maxlen) +return false; + total_len += length; +if (PAGE_ALIGN (total_len + rctxt->rc_byte_len - +xdr_stream_pos (&rctxt->rc_stream)) > maxlen) +return false;if (position) {if (position &3 )return false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 564/869 svcrdma: Add Write chunk WRs to the RPCs Send WR chain
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit d16f060f3ee297424c0aba047b1d49208adb9318 ]
Previously, Write chunk RDMA Writes were posted via a separate ib_post_send() call with their own completion handler. Each Write chunk incurred a doorbell and generated a completion event.
Link Write chunk WRs onto the RPC Reply's Send WR chain so that a single ib_post_send() call posts both the RDMA Writes and the Send WR. A single completion event signals that all operations have finished. This reduces both doorbell rate and completion rate, as well as eliminating the latency of a round-trip between the Write chunk completion and the subsequent Send WR posting.
The lifecycle of Write chunk resources changes: previously, the svc_rdma_write_done() completion handler released Write chunk resources when RDMA Writes completed. With WR chaining, resources remain live until the Send completion. A new sc_write_info_list tracks Write chunk metadata attached to each Send context, and svc_rdma_write_chunk_release() frees these resources when the Send context is released.
The svc_rdma_write_done() handler now handles only error cases. On success it returns immediately since the Send completion handles resource release. On failure (WR flush), it closes the connection to signal to the client that the RPC Reply is incomplete.
Stable-dep-of: 01500306e1d5 ("svcrdma: Clear sc_cm_id when ADDR_CHANGE replacement fails")
--- include/linux/sunrpc/svc_rdma.h | 13 +++- net/sunrpc/xprtrdma/svc_rdma_rw.c | 94 ++++++++++++++++++++------- net/sunrpc/xprtrdma/svc_rdma_sendto.c | 10 ++- 3 files changed, 91 insertions(+), 26 deletions(-)
include/linux/sunrpc/svc_rdma.h +10 -3
@@ -213,6 +213,7 @@ struct svc_rdma_recv_ctxt {*/ struct svc_rdma_write_info {struct svcxprt_rdma *wi_rdma; +struct list_head wi_list;const struct svc_rdma_chunk *wi_chunk;
@@ -241,7 +242,10 @@ struct svc_rdma_send_ctxt {struct ib_cqe sc_cqe;struct xdr_buf sc_hdrbuf;struct xdr_stream sc_stream; + +struct list_head sc_write_info_list;struct svc_rdma_write_info sc_reply_info; +void *sc_xprt_buf;int sc_page_count;int sc_cur_sge_no;
@@ -273,11 +277,14 @@ extern void svc_rdma_cc_init(struct svcxprt_rdma *rdma,extern void svc_rdma_cc_release (struct svcxprt_rdma *rdma,struct svc_rdma_chunk_ctxt *cc,enum dma_data_direction dir); +extern void svc_rdma_write_chunk_release (struct svcxprt_rdma *rdma, +struct svc_rdma_send_ctxt *ctxt);extern void svc_rdma_reply_chunk_release (struct svcxprt_rdma *rdma,struct svc_rdma_send_ctxt *ctxt); -extern int svc_rdma_send_write_list (struct svcxprt_rdma *rdma, -const struct svc_rdma_recv_ctxt *rctxt, -const struct xdr_buf *xdr); +extern int svc_rdma_prepare_write_list (struct svcxprt_rdma *rdma, +const struct svc_rdma_recv_ctxt *rctxt, +struct svc_rdma_send_ctxt *sctxt, +const struct xdr_buf *xdr); extern int svc_rdma_prepare_reply_chunk(struct svcxprt_rdma *rdma, const struct svc_rdma_pcl *write_pcl, const struct svc_rdma_pcl *reply_pcl,
net/sunrpc/xprtrdma/svc_rdma_rw.c +72 -22
150 lines not on this page · raw message
net/sunrpc/xprtrdma/svc_rdma_sendto.c +9 -1
@@ -142,6 +142,7 @@ svc_rdma_send_ctxt_alloc(struct svcxprt_rdma *rdma) ctxt->sc_send_wr.sg_list = ctxt->sc_sges; ctxt->sc_send_wr.send_flags =IB_SEND_SIGNALED ; ctxt->sc_cqe.done = svc_rdma_wc_send; +INIT_LIST_HEAD (&ctxt->sc_write_info_list); ctxt->sc_xprt_buf = buffer;xdr_buf_init (&ctxt->sc_hdrbuf, ctxt->sc_xprt_buf, rdma->sc_max_req_size);
@@ -227,6 +228,7 @@ static void svc_rdma_send_ctxt_release(struct svcxprt_rdma *rdma,struct ib_device *device = rdma->sc_cm_id->device;unsigned int i; +svc_rdma_write_chunk_release (rdma, ctxt);svc_rdma_reply_chunk_release (rdma, ctxt);if (ctxt->sc_page_count)
@@ -983,6 +985,12 @@ void svc_rdma_send_error_msg(struct svcxprt_rdma *rdma, sctxt->sc_send_wr.num_sge =1 ; sctxt->sc_send_wr.opcode =IB_WR_SEND ; sctxt->sc_sges[0 ].length = sctxt->sc_hdrbuf.len; + +/* Ensure only the error message is posted, not any previously +* prepared Write chunk WRs. +*/ + sctxt->sc_wr_chain = &sctxt->sc_send_wr; + sctxt->sc_sqecount =1 ;if (svc_rdma_post_send (rdma, sctxt)) goto put_ctxt;return ;
@@ -1030,7 +1038,7 @@ int svc_rdma_sendto(struct svc_rqst *rqstp)if (!p) goto put_ctxt; - ret =svc_rdma_send_write_list (rdma, rctxt, &rqstp->rq_res); + ret =svc_rdma_prepare_write_list (rdma, rctxt, sctxt, &rqstp->rq_res);if (ret <0 ) goto put_ctxt;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 565/869 svcrdma: wake sq waiters when the transport closes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit e5248a7426030db1e126363f72afdb3b71339a5c ]
Threads parked in svc_rdma_sq_wait() on sc_sq_ticket_wait or sc_send_wait can hang indefinitely in TASK_UNINTERRUPTIBLE state across transport teardown, pinning svc_xprt references and blocking svc_rdma_free().
The close path sets XPT_CLOSE before invoking xpo_detach and both wait_event predicates include an XPT_CLOSE term, but the predicates are re-evaluated only on wakeup. sc_sq_ticket_wait has no completion-driven wake path; it is advanced solely by the chained ticket handoff inside svc_rdma_sq_wait() itself. Without an explicit wake at close, parked threads never observe XPT_CLOSE, hold their svc_xprt_get reference forever, and svc_rdma_free() blocks on xpt_ref dropping to zero.
Two close entry points reach this transport. Local teardown runs svc_rdma_detach() from svc_handle_xprt() -> svc_delete_xprt() -> xpo_detach() on a worker thread. A remote disconnect arrives at svc_rdma_cma_handler(), which calls svc_xprt_deferred_close():
that sets XPT_CLOSE and enqueues the transport but does not access either RDMA waitqueue, so a worker already parked in svc_rdma_sq_wait() never re-evaluates its predicate. With every worker parked on this transport, no thread is available to run the local teardown either, and the wake site there is unreachable.
Introduce svc_rdma_xprt_deferred_close(), a thin svcrdma wrapper that calls svc_xprt_deferred_close() and then wakes both sc_sq_ticket_wait and sc_send_wait. Convert the svcrdma producers that called svc_xprt_deferred_close() directly:svc_rdma_cma_handler(), qp_event_handler(), svc_rdma_post_send_err(), svc_rdma_wc_send(), the sendto drop path, the rw completion error paths, and the recvfrom flush and read-list error paths.
Wake both waitqueues from svc_rdma_detach() as well. The synchronous svc_xprt_close() path (backchannel ENOTCONN, device removal via svc_rdma_xprt_done) reaches detach without flowing through svc_xprt_deferred_close() and therefore does not invoke the new helper.
[ Adapted: this tree has no ticket-based SQ wait, so only sc_send_wait is
woken, and the XPT_CLOSE predicate and svc_rdma_sq_wait() changes are omitted. The detach comment is kept to carry context for follow-up patches. ]
Stable-dep-of: 01500306e1d5 ("svcrdma: Clear sc_cm_id when ADDR_CHANGE replacement fails")
--- include/linux/sunrpc/svc_rdma.h | 1 + net/sunrpc/xprtrdma/svc_rdma_recvfrom.c | 4 ++-- net/sunrpc/xprtrdma/svc_rdma_rw.c | 8 ++++---- net/sunrpc/xprtrdma/svc_rdma_sendto.c | 6 +++--- net/sunrpc/xprtrdma/svc_rdma_transport.c | 26 ++++++++++++++++++++++-- 5 files changed, 34 insertions(+), 11 deletions(-)
include/linux/sunrpc/svc_rdma.h +1 -0
@@ -317,6 +317,7 @@ extern int svc_rdma_result_payload(struct svc_rqst *rqstp, unsigned int offset, unsigned int length);/* svc_rdma_transport.c */ +extern void svc_rdma_xprt_deferred_close (struct svcxprt_rdma *rdma);extern struct svc_xprt_class svc_rdma_class;#ifdef CONFIG_SUNRPC_BACKCHANNEL extern struct svc_xprt_class svc_rdma_bc_class;
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c +2 -2
@@ -376,7 +376,7 @@ static void svc_rdma_wc_receive(struct ib_cq *cq, struct ib_wc *wc)trace_svcrdma_wc_recv_err (wc, &ctxt->rc_cid); dropped:svc_rdma_recv_ctxt_put (rdma, ctxt); -svc_xprt_deferred_close (&rdma->sc_xprt); +svc_rdma_xprt_deferred_close (rdma); }/**
@@ -1019,7 +1019,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)if (ret == -EINVAL )svc_rdma_send_error (rdma_xprt, ctxt, ret);svc_rdma_recv_ctxt_put (rdma_xprt, ctxt); -svc_xprt_deferred_close (xprt); +svc_rdma_xprt_deferred_close (rdma_xprt);return ret; }return 0 ;
net/sunrpc/xprtrdma/svc_rdma_rw.c +4 -4
@@ -292,7 +292,7 @@ static void svc_rdma_reply_done(struct ib_cq *cq, struct ib_wc *wc)trace_svcrdma_wc_reply_err (wc, &cc->cc_cid); } -svc_xprt_deferred_close (&rdma->sc_xprt); +svc_rdma_xprt_deferred_close (rdma); }/**
@@ -324,7 +324,7 @@ static void svc_rdma_write_done(struct ib_cq *cq, struct ib_wc *wc)* some of the outgoing RPC message. Signal the loss * to the client by closing the connection. */ -svc_xprt_deferred_close (&rdma->sc_xprt); +svc_rdma_xprt_deferred_close (rdma); }/**
@@ -369,7 +369,7 @@ static void svc_rdma_wc_read_done(struct ib_cq *cq, struct ib_wc *wc)*/ svc_rdma_cc_release (rdma, cc,DMA_FROM_DEVICE );svc_rdma_recv_ctxt_put (rdma, ctxt); -svc_xprt_deferred_close (&rdma->sc_xprt); +svc_rdma_xprt_deferred_close (rdma); }/*
@@ -422,7 +422,7 @@ static int svc_rdma_post_chunk_ctxt(struct svcxprt_rdma *rdma, }while (1 );trace_svcrdma_sq_post_err (rdma, &cc->cc_cid, ret); -svc_xprt_deferred_close (&rdma->sc_xprt); +svc_rdma_xprt_deferred_close (rdma);/* If even one was posted, there will be a completion. */ if (bad_wr != first_wr)
net/sunrpc/xprtrdma/svc_rdma_sendto.c +3 -3
@@ -316,7 +316,7 @@ static void svc_rdma_wc_send(struct ib_cq *cq, struct ib_wc *wc)else trace_svcrdma_wc_send_flush (wc, &ctxt->sc_cid);svc_rdma_send_ctxt_put (rdma, ctxt); -svc_xprt_deferred_close (&rdma->sc_xprt); +svc_rdma_xprt_deferred_close (rdma); }/**
@@ -377,7 +377,7 @@ int svc_rdma_post_send(struct svcxprt_rdma *rdma, ret =ib_post_send (rdma->sc_qp, first_wr, &bad_wr);if (ret) {trace_svcrdma_sq_post_err (rdma, &cid, ret); -svc_xprt_deferred_close (&rdma->sc_xprt); +svc_rdma_xprt_deferred_close (rdma);/* If even one WR was posted, there will be a * Send completion that bumps sc_sq_avail.
@@ -1087,7 +1087,7 @@ int svc_rdma_sendto(struct svc_rqst *rqstp)svc_rdma_send_ctxt_put (rdma, sctxt); drop_connection:trace_svcrdma_send_err (rqstp, ret); -svc_xprt_deferred_close (&rdma->sc_xprt); +svc_rdma_xprt_deferred_close (rdma);return -ENOTCONN ; }
net/sunrpc/xprtrdma/svc_rdma_transport.c +24 -2
@@ -99,10 +99,24 @@ struct svc_xprt_class svc_rdma_class = { .xcl_ident = XPRT_TRANSPORT_RDMA, }; +/** +* svc_rdma_xprt_deferred_close - Close an RDMA transport (deferred) +* @rdma: transport to close +*/ +void svc_rdma_xprt_deferred_close (struct svcxprt_rdma *rdma) +{ +svc_xprt_deferred_close (&rdma->sc_xprt); + +/* Release threads parked on sc_send_wait. */ +wake_up_all (&rdma->sc_send_wait); +} +/* QP event handler */ static void qp_event_handler (struct ib_event *event,void *context) {struct svc_xprt *xprt = context; +struct svcxprt_rdma *rdma = + container_of(xprt, struct svcxprt_rdma, sc_xprt);trace_svcrdma_qp_error (event, (struct sockaddr *)&xprt->xpt_remote);switch (event->event) {
@@ -120,7 +134,7 @@ static void qp_event_handler(struct ib_event *event, void *context)case IB_EVENT_QP_ACCESS_ERR :case IB_EVENT_DEVICE_FATAL :default : -svc_xprt_deferred_close (xprt); +svc_rdma_xprt_deferred_close (rdma);break ; } }
@@ -344,7 +358,7 @@ static int svc_rdma_cma_handler(struct rdma_cm_id *cma_id,svc_xprt_enqueue (xprt);break ;case RDMA_CM_EVENT_DISCONNECTED : -svc_xprt_deferred_close (xprt); +svc_rdma_xprt_deferred_close (rdma);break ;default :break ;
@@ -617,6 +631,14 @@ static void svc_rdma_detach(struct svc_xprt *xprt) container_of(xprt, struct svcxprt_rdma, sc_xprt);rdma_disconnect (rdma->sc_cm_id); + +/* +* Most close paths go through svc_rdma_xprt_deferred_close(), +* which wakes the SQ waitqueue. svc_xprt_close() reaches +* detach without that helper, so wake any threads parked on +* sc_send_wait here as well. +*/ +wake_up_all (&rdma->sc_send_wait); }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 566/869 svcrdma: Clear sc_cm_id when ADDR_CHANGE replacement fails
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 01500306e1d50de7ca7a2cdcdfa28ac0523eb747 ]
When svc_rdma_listen_handler() handles RDMA_CM_EVENT_ADDR_CHANGE, it creates a replacement listener cm_id and returns 1, telling the CM core to destroy the old one. If the replacement allocation fails, sc_cm_id still points at the old cm_id that the CM core is about to destroy. Any subsequent dereference of sc_cm_id -- such as svc_rdma_detach()'s rdma_disconnect() call -- is a use-after-free.
NULL sc_cm_id on the failure path and guard svc_rdma_detach()'s rdma_disconnect() call against NULL so that the listener can be torn down safely when the server shuts down.
--- net/sunrpc/xprtrdma/svc_rdma_transport.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/sunrpc/xprtrdma/svc_rdma_transport.c +3 -1
@@ -325,6 +325,7 @@ static int svc_rdma_listen_handler(struct rdma_cm_id *cma_id,if (IS_ERR (listen_id)) {pr_err ("Listener dead, address change failed for device %s\n" , cma_id->device->name); + cma_xprt->sc_cm_id =NULL ; }else cma_xprt->sc_cm_id = listen_id;return 1 ;
@@ -630,7 +631,8 @@ static void svc_rdma_detach(struct svc_xprt *xprt)struct svcxprt_rdma *rdma = container_of(xprt, struct svcxprt_rdma, sc_xprt); -rdma_disconnect (rdma->sc_cm_id); +if (rdma->sc_cm_id) +rdma_disconnect (rdma->sc_cm_id);/* * Most close paths go through svc_rdma_xprt_deferred_close(),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 567/869 SUNRPC: Reject short RFC 4121 MIC tokens in gss_krb5_verify_mic_v2
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit b94f6719dcd9f7a609bc5f459f85795900e77d25 ]
gss_krb5_verify_mic_v2() reads the token ID at ptr[0..1], the flags byte at ptr[2], and padding at ptr[3..7], then passes
ptr + GSS_KRB5_TOK_HDR_LEN and cksum_len to gss_krb5_mic_build_sg(). None of these accesses check read_token->len first.
The minimum safe token size is GSS_KRB5_TOK_HDR_LEN (16) plus ctx->krb5e->cksum_len (12-24, depending on the enctype). All callers accept shorter tokens from the wire:
- gss_unwrap_resp_integ() enforces only an upper bound (offset + len <= rcv_buf->len) before allocating mic.data = kmalloc(len) and passing it to gss_verify_mic(). A malicious NFS server can therefore supply a short checksum opaque, producing a small slab allocation that the Kerberos MIC verifier reads past.
- gss_validate() enforces only len <= RPC_MAX_AUTH_SIZE (400) before passing the wire-supplied length to gss_validate_seqno_mic(), which constructs a mic xdr_netobj and calls gss_verify_mic().
- svcauth_gss_verify_header() enforces only checksum.len >= XDR_UNIT (4 bytes) before dispatching to gss_verify_mic().
- svcauth_gss_unwrap_integ() checks only that the checksum fits in gsd->gsd_scratch.
Add a length guard at the top of gss_krb5_verify_mic_v2(), before any ptr[] access or scatterlist construction. Well-formed MIC tokens from gss_krb5_get_mic_v2() already have exactly GSS_KRB5_TOK_HDR_LEN + cksum_len bytes, so valid traffic is unaffected.
--- net/sunrpc/auth_gss/gss_krb5_unseal.c | 3 +++ 1 file changed, 3 insertions(+)
net/sunrpc/auth_gss/gss_krb5_unseal.c +3 -0
@@ -86,6 +86,9 @@ gss_krb5_verify_mic_v2(struct krb5_ctx *ctx, struct xdr_buf *message_buffer,dprintk ("RPC: %s\n" , __func__); +if (read_token->len <GSS_KRB5_TOK_HDR_LEN + ctx->gk5e->cksumlength) +return GSS_S_DEFECTIVE_TOKEN ; +memcpy (&be16_ptr, (char *) ptr,2 );if (be16_to_cpu (be16_ptr) !=KG2_TOK_MIC )return GSS_S_DEFECTIVE_TOKEN ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 568/869 ext2: Fix lost inode updates for IS_SYNC inodes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jan Kara <[email protected]>
[ Upstream commit 356984d1a5c32e94810cbb6c8dc7d8ff2d4d919a ]
ext2_setsize() and ext2_xattr_set2() had a construct like:
if (IS_SYNC(inode)) {
sync_inode_metadata(inode, 1);
} else {
mark_inode_dirty(inode);
}which leads to lost inode updates for IS_SYNC inodes because sync_inode_metadata() does anything only if the inode is already dirty and hence inode updates may be simply lost. Fix the problem by unconditionally marking the inode dirty and *then* call sync_inode_metadata().
--- fs/ext2/inode.c | 3 +-- fs/ext2/xattr.c | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-)
fs/ext2/inode.c +1 -2
@@ -1300,11 +1300,10 @@ static int ext2_setsize(struct inode *inode, loff_t newsize)filemap_invalidate_unlock (inode->i_mapping);inode_set_mtime_to_ts (inode,inode_set_ctime_current (inode)); +mark_inode_dirty (inode);if (inode_needs_sync (inode)) {sync_mapping_buffers (inode->i_mapping);sync_inode_metadata (inode,1 ); - }else { -mark_inode_dirty (inode); }return 0 ;
fs/ext2/xattr.c +2 -2
@@ -777,6 +777,7 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,/* Update the inode. */ EXT2_I (inode)->i_file_acl = new_bh ? new_bh->b_blocknr :0 ;inode_set_ctime_current (inode); +mark_inode_dirty (inode);if (IS_SYNC (inode)) { error =sync_inode_metadata (inode,1 );/* In case sync failed due to ENOSPC the inode was actually
@@ -789,8 +790,7 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh, } goto cleanup; } - }else -mark_inode_dirty (inode); + } error =0 ;if (old_bh && old_bh != new_bh) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 569/869 smb: client: reject a tree connect response whose byte count is too small
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
[ Upstream commit 65deb18359341141d37dc86fc7853511be3c87a7 ]
CIFSTCon() bounds its strnlen() over the byte area with the server's ByteCount minus two, which for ByteCount 0 or 1 goes negative as an int and converts to a huge size_t. The later subtraction wraps the __u16 bytes_left, and that is what bounds cifs_strndup_from_utf16(): a bound of up to 65535 against a ~16 KB cifs_req_poolp object runs off the end of the slab object, and the bytes reach userspace through tcon->nativeFileSystem in /proc/fs/cifs/DebugData.
Reject a byte area too small for what the parser consumes. Two bytes is the least it can consume, and no conformant response carries fewer. The new trace point is the 129th smb_eio_trace entry, which __mode(byte) cannot represent, so the attribute goes with it.
--- fs/smb/client/connect.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/smb/client/connect.c +5 -0
@@ -3895,6 +3895,10 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses, tcon->tid = smb_buffer_response->Tid; bcc_ptr =pByteArea (smb_buffer_response); bytes_left =get_bcc (smb_buffer_response); +if (bytes_left <2 ) { + rc = -EIO ; + goto out; + } length =strnlen (bcc_ptr, bytes_left -2 );if (smb_buffer->Flags2 &SMBFLG2_UNICODE ) is_unicode = true;
@@ -3950,6 +3954,7 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses,reset_cifs_unix_caps (xid, tcon,NULL ,NULL ); } } +out:cifs_buf_release (smb_buffer);return rc; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 570/869 cifs: call pagecache_isize_extended() in cifs_setsize() when extending
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
[ Upstream commit c510edb9734af1c274d18f4f31a471a166bbc7e8 ]
cifs_setsize() calls truncate_pagecache() but skips pagecache_isize_extended() on extension. truncate_setsize() shows the correct pattern:
i_size_write(inode, newsize);
if (newsize > oldsize)
pagecache_isize_extended(inode, oldsize, newsize);
truncate_pagecache(inode, newsize);pagecache_isize_extended() zeroes the tail of the page straddling old EOF. Without it, dirty bytes in that region can be written back to the server, exposing stale data in the newly extended range.
--- fs/smb/client/inode.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/smb/client/inode.c +4 -0
@@ -2959,13 +2959,17 @@ int cifs_truncate_page(struct address_space *mapping, loff_t from)void cifs_setsize (struct inode *inode,loff_t offset) {struct cifsInodeInfo *cifs_i =CIFS_I (inode); +loff_t old_size;spin_lock (&inode->i_lock); + old_size =i_size_read (inode);i_size_write (inode, offset);spin_unlock (&inode->i_lock);/* Cached inode must be refreshed on truncate */ cifs_i->time =0 ; +if (offset > old_size) +pagecache_isize_extended (inode, old_size, offset);truncate_pagecache (inode, offset);netfs_wait_for_outstanding_io (inode);fscache_resize_cookie (cifs_inode_cookie (inode), offset);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 571/869 ceph: cap delegated inode count in ceph_parse_deleg_inos()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Bommarito <[email protected]>
[ Upstream commit 4bd3158bd62466d57ed72a3f7bc5f205fedd6919 ]
ceph_parse_deleg_inos() decodes interval sets of delegated inode numbers from an MDS create-with-delegation reply. For each set it reads a 64-bit start and a 64-bit len with ceph_decode_64_safe(), which only validates that the eight bytes are present in the message, not the value, and then loops over len while inserting entries into s_delegated_inos.
len is fully attacker controlled. A malicious or compromised MDS can send one huge interval, many intervals in one reply, duplicate intervals, or repeated replies that accumulate delegated inodes on the same session. The original code bounded none of these and could spin the insert loop or grow the xarray without limit.
Bound both dimensions with a single enforcement point. Track the number of delegated inodes held by each MDS session in an atomic counter and grow it only in ceph_insert_deleg_ino(), which uses atomic_add_unless() to refuse to push the count past CEPH_MAX_DELEG_INOS. Because that helper is the only place the counter grows, the per-session population can never exceed the cap, so no separate per-session pre-check is needed. The counter is decremented when async create consumes a delegated inode or when an insert fails, incremented when a delegated inode is restored, initialized with the session xarray, and reset when reconnect destroys the xarray.
A per-session cap alone still lets one reply spin the insert loop on duplicate ranges without growing the counter, so also cap the aggregate interval length accepted from a single reply. Together these bound both the loop trip count per reply and the xarray population across replies.
The cap is a fixed, client-chosen constant rather than a value derived from the MDS. mds_client_prealloc_inos is a userspace MDS configuration option; it is never sent to the kernel client on the wire, and a server-supplied bound could not be trusted for a defensive limit in any case. The constant is set well above that option's documented default of 1000 (a generous multiple), so legitimate refill behavior is unaffected while the CPU and xarray memory a malformed delegation stream can consume stays bounded.
Impact: a malicious or compromised Ceph MDS can no longer make a client spin through an unbounded delegated-inode interval or grow one session's delegated-inode xarray without limit.
--- fs/ceph/mds_client.c | 59 +++++++++++++++++++++++++++++++++++++++----- fs/ceph/mds_client.h | 1 + fs/ceph/super.h | 9 +++++++ 3 files changed, 63 insertions(+), 6 deletions(-)
fs/ceph/mds_client.c +53 -6
@@ -574,10 +574,36 @@ static int parse_reply_info_filelock(void **p, void *end,#define DELEGATED_INO_AVAILABLE xa_mk_value(1) +static int ceph_insert_deleg_ino (struct ceph_mds_session *s,u64 ino) +{ +struct ceph_client *cl = s->s_mdsc->fsc->client; +int err; + +/* +* Cap how many delegated inodes a single session may hold. This is +* the only place that grows the count, so atomic_add_unless() bounds +* it at exactly CEPH_MAX_DELEG_INOS; s_num_deleg_inos can never exceed +* that. +*/ +if (!atomic_add_unless (&s->s_num_deleg_inos,1 ,CEPH_MAX_DELEG_INOS )) { +pr_warn_ratelimited_client (cl, +"MDS session already holds %d delegated inodes\n" , +CEPH_MAX_DELEG_INOS ); +return -EOVERFLOW ; + } + + err =xa_insert (&s->s_delegated_inos, ino,DELEGATED_INO_AVAILABLE , +GFP_KERNEL ); +if (err) +atomic_dec (&s->s_num_deleg_inos); +return err; +} +static int ceph_parse_deleg_inos (void **p,void *end,struct ceph_mds_session *s) {struct ceph_client *cl = s->s_mdsc->fsc->client; +u64 msg_deleg_inos =0 ;u32 sets;ceph_decode_32_safe (p, end, sets, bad);
@@ -595,16 +621,34 @@ static int ceph_parse_deleg_inos(void **p, void *end, start, len);continue ; } + +/* +* Bound the number of inodes one reply may delegate. +* ceph_insert_deleg_ino() separately caps the per-session +* population, so this only has to stop one reply from spinning +* the insert loop under an attacker-controlled len. +*/ +if (len > (u64 )CEPH_MAX_DELEG_INOS || + msg_deleg_inos > (u64 )CEPH_MAX_DELEG_INOS - len) { +pr_warn_ratelimited_client (cl, +"MDS reply delegates too many inodes (have %llu, +%llu, max %d)\n" , + msg_deleg_inos, len,CEPH_MAX_DELEG_INOS ); +return -EIO ; + } + msg_deleg_inos += len; +while (len--) { -int err =xa_insert (&s->s_delegated_inos, start++, -DELEGATED_INO_AVAILABLE , -GFP_KERNEL ); +int err =ceph_insert_deleg_ino (s, start++); +if (!err) {doutc (cl,"added delegated inode 0x%llx\n" , start -1 ); }else if (err == -EBUSY ) {pr_warn_client (cl,"MDS delegated inode 0x%llx more than once.\n" , start -1 ); + }else if (err == -EOVERFLOW ) { +/* ceph_insert_deleg_ino() already warned. */ +return -EIO ; }else {return err; }
@@ -622,16 +666,17 @@ u64 ceph_get_deleg_ino(struct ceph_mds_session *s)xa_for_each (&s->s_delegated_inos, ino, val) { val =xa_erase (&s->s_delegated_inos, ino); -if (val ==DELEGATED_INO_AVAILABLE ) +if (val ==DELEGATED_INO_AVAILABLE ) { +atomic_dec (&s->s_num_deleg_inos);return ino; + } } return 0; }int ceph_restore_deleg_ino (struct ceph_mds_session *s,u64 ino) { -return xa_insert (&s->s_delegated_inos, ino,DELEGATED_INO_AVAILABLE , -GFP_KERNEL ); +return ceph_insert_deleg_ino (s, ino); }#else /* BITS_PER_LONG == 64 */ /*
@@ -1015,6 +1060,7 @@ static struct ceph_mds_session *register_session(struct ceph_mds_client *mdsc,INIT_LIST_HEAD (&s->s_waiting);INIT_LIST_HEAD (&s->s_unsafe);xa_init (&s->s_delegated_inos); +atomic_set (&s->s_num_deleg_inos,0 );INIT_LIST_HEAD (&s->s_cap_releases);INIT_WORK (&s->s_cap_release_work, ceph_cap_release_work);
@@ -4923,6 +4969,7 @@ static int send_mds_reconnect(struct ceph_mds_client *mdsc,/* Serialized by s_mutex against concurrent ceph_get_deleg_ino(). */ xa_destroy (&session->s_delegated_inos); +atomic_set (&session->s_num_deleg_inos,0 );if (session->s_state ==CEPH_MDS_SESSION_CLOSED || session->s_state ==CEPH_MDS_SESSION_REJECTED ) { pr_info_client(cl, "mds%d skipping reconnect, session %s\n",
fs/ceph/mds_client.h +1 -0
@@ -252,6 +252,7 @@ struct ceph_mds_session {struct list_head s_waiting;/* waiting requests */ struct list_head s_unsafe;/* unsafe requests */ struct xarray s_delegated_inos; +atomic_t s_num_deleg_inos; };/*
fs/ceph/super.h +9 -0
@@ -623,6 +623,15 @@ static inline int ceph_ino_compare(struct inode *inode, void *data)#define CEPH_MDS_INO_LOG_OFFSET (2 * CEPH_MAX_MDS)#define CEPH_INO_SYSTEM_BASE ((6*CEPH_MAX_MDS) + (CEPH_MAX_MDS * CEPH_NUM_STRAY)) +/* +* Upper bound on the number of delegated inodes a single MDS session may +* hold. The MDS normally hands out a small preallocation window (the +* userspace mds_client_prealloc_inos option defaults to 1000) and refills +* it as the client consumes entries. This leaves generous headroom while +* bounding the CPU and memory a malformed delegation interval can consume. +*/ +#define CEPH_MAX_DELEG_INOS 8192 +static inline bool ceph_vino_is_reserved (const struct ceph_vino vino) { if (vino.ino >= CEPH_INO_SYSTEM_BASE ||
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 572/869 ceph: fix UAF in check_new_map() on session freed during unlock
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiubo Li <[email protected]>
[ Upstream commit ee611a7509554c4ca1f54f6aefe592fb1df7ea70 ]
check_new_map() iterates mdsc->sessions[] and for each active session drops mdsc->mutex to perform per-session operations. The forced-close path (rank removed from map) correctly takes a reference on s via ceph_get_mds_session() before releasing mdsc->mutex, but three other paths do not:
Path A (address changed): mutex_unlock → mutex_lock(&s->s_mutex)
Path B (reconnect): mutex_unlock → send_mds_reconnect(mdsc, s)
Path C (active transition): mutex_unlock → mutex_lock(&s->s_mutex)
Without the extra reference, another thread can acquire mdsc->mutex during the unlock window, call __unregister_session() which drops the last reference on s, and free it. The original thread then accesses freed memory via s->s_mutex.
Fix by adding ceph_get_mds_session(s) before each mutex_unlock and ceph_put_mds_session(s) after the corresponding mutex_lock, matching the pattern already used in the forced-close path.
Race timeline (Path A):
Thread A (check_new_map) Thread B (another map update
holds mdsc->mutex or session teardown)
-------------------------- --------------------------
s = mdsc->sessions[i]
(refcount == 1, held only by
sessions[] array)
mutex_unlock(&mdsc->mutex)
---> acquires mdsc->mutex
__unregister_session(mdsc, s)
sessions[i] = NULL
ceph_put_mds_session(s)
refcount: 1 -> 0
kfree(s) <--- freed! mutex_lock(&s->s_mutex)
UAF on freed s->s_mutex
--- fs/ceph/mds_client.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/ceph/mds_client.c +6 -0
@@ -5219,9 +5219,11 @@ static void check_new_map(struct ceph_mds_client *mdsc, ceph_mdsmap_get_addr(newmap, i), sizeof(struct ceph_entity_addr))) {/* just close it */ +ceph_get_mds_session (s);mutex_unlock (&mdsc->mutex);mutex_lock (&s->s_mutex);mutex_lock (&mdsc->mutex); +ceph_put_mds_session (s);ceph_con_close (&s->s_con);mutex_unlock (&s->s_mutex); s->s_state =CEPH_MDS_SESSION_RESTARTING ;
@@ -5236,6 +5238,7 @@ static void check_new_map(struct ceph_mds_client *mdsc, newstate >= CEPH_MDS_STATE_RECONNECT) {int rc; +ceph_get_mds_session (s);mutex_unlock (&mdsc->mutex);clear_bit (i, targets); rc =send_mds_reconnect (mdsc, s);
@@ -5244,6 +5247,7 @@ static void check_new_map(struct ceph_mds_client *mdsc,"mds%d reconnect failed: %d\n" , i, rc);mutex_lock (&mdsc->mutex); +ceph_put_mds_session (s); }/*
@@ -5256,9 +5260,11 @@ static void check_new_map(struct ceph_mds_client *mdsc,pr_info_client (cl,"mds%d recovery completed\n" , s->s_mds);kick_requests (mdsc, i); +ceph_get_mds_session (s);mutex_unlock (&mdsc->mutex);mutex_lock (&s->s_mutex);mutex_lock (&mdsc->mutex); +ceph_put_mds_session (s);ceph_kick_flushing_caps (mdsc, s);mutex_unlock (&s->s_mutex);wake_up_session_caps (s,RECONNECT );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 573/869 nfsd: fix fcache_disposal UAF by inlining dispose state into nfsd_net
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Layton <[email protected]>
[ Upstream commit bbf13732f74351d21c5e0e8dd9bd8e1c48dc35d4 ]
nfsd_file_dispose_list_delayed() defers fput() to nfsd service threads via a per-net freeme queue, preventing the shrinker and GC worker from bearing the cost of closing files (see ffb402596147). However, the queue lives in a separately-allocated struct nfsd_fcache_disposal that is freed by nfsd_free_fcache_disposal_net() during per-net teardown. The global shrinker, laundrette, and fsnotify callbacks can still be inside nfsd_file_dispose_list_delayed() dereferencing that pointer, causing a use-after-free.
Inline the spinlock and freeme list directly into struct nfsd_net (as fcache_dispose_lock and fcache_dispose_list), eliminating the separately allocated struct nfsd_fcache_disposal entirely. These fields now have the same lifetime as the net namespace itself, so there is no dangling pointer to chase.
nfsd_file_cache_start_net() now just initializes the inline fields and cannot fail due to allocation. nfsd_file_cache_shutdown_net() drains the inline list directly instead of freeing a separate struct. The alloc/free helpers are removed.
--- fs/nfsd/filecache.c | 75 +++++++++++++-------------------------------- fs/nfsd/netns.h | 3 +- 2 files changed, 23 insertions(+), 55 deletions(-)
fs/nfsd/filecache.c +21 -54
@@ -67,11 +67,6 @@ static DEFINE_PER_CPU(unsigned long, nfsd_file_releases); static DEFINE_PER_CPU(unsigned long, nfsd_file_total_age); static DEFINE_PER_CPU(unsigned long, nfsd_file_evictions); -struct nfsd_fcache_disposal { -spinlock_t lock; -struct list_head freeme; -}; -static struct kmem_cache *nfsd_file_slab;static struct kmem_cache *nfsd_file_mark_slab;static struct list_lru nfsd_file_lru;
@@ -437,11 +432,12 @@ nfsd_file_dispose_list(struct list_head *dispose) }/** -* nfsd_file_dispose_list_delayed - move list of dead files to net's freeme list +* nfsd_file_dispose_list_delayed - queue dead files for nfsd thread disposal * @dispose: list of nfsd_files to be disposed * -* Transfers each file to the "freeme" list for its nfsd_net, to eventually -* be disposed of by the per-net garbage collector. +* Transfers each file to the dispose list in its nfsd_net and wakes an nfsd +* thread to do the actual close. This keeps the cost of fput() in the nfsd +* threads rather than in the shrinker or GC worker. * * All callers must hold nfsd_gc_lock, so that nfsd_file_cache_shutdown_net() * can synchronize against them before draining the per-net dispose list.
@@ -456,12 +452,11 @@ nfsd_file_dispose_list_delayed(struct list_head *dispose)struct nfsd_file *nf =list_first_entry (dispose, struct nfsd_file, nf_gc);struct nfsd_net *nn =net_generic (nf->nf_net, nfsd_net_id); -struct nfsd_fcache_disposal *l = nn->fcache_disposal;struct svc_serv *serv; -spin_lock (&l->lock); -list_move_tail (&nf->nf_gc, &l->freeme); -spin_unlock (&l->lock); +spin_lock (&nn->fcache_dispose_lock); +list_move_tail (&nf->nf_gc, &nn->fcache_dispose_list); +spin_unlock (&nn->fcache_dispose_lock);/* * The filecache laundrette is shut down after the
@@ -485,17 +480,15 @@ nfsd_file_dispose_list_delayed(struct list_head *dispose)*/ void nfsd_file_net_dispose (struct nfsd_net *nn) { -struct nfsd_fcache_disposal *l = nn->fcache_disposal; - -if (!list_empty (&l->freeme)) { +if (!list_empty (&nn->fcache_dispose_list)) {LIST_HEAD (dispose);int i; -spin_lock (&l->lock); -for (i =0 ; i <8 && !list_empty (&l->freeme); i++) -list_move (l->freeme.next, &dispose); -spin_unlock (&l->lock); -if (!list_empty (&l->freeme)) { +spin_lock (&nn->fcache_dispose_lock); +for (i =0 ; i <8 && !list_empty (&nn->fcache_dispose_list); i++) +list_move (nn->fcache_dispose_list.next, &dispose); +spin_unlock (&nn->fcache_dispose_lock); +if (!list_empty (&nn->fcache_dispose_list)) {/* * Wake up another thread to share the work * *before* doing any actual disposing.
@@ -685,11 +678,11 @@ nfsd_file_queue_for_close(struct inode *inode, struct list_head *dispose) }/** -* nfsd_file_close_inode - attempt a delayed close of a nfsd_file +* nfsd_file_close_inode - attempt a deferred close of a nfsd_file * @inode: inode of the file to attempt to remove * * Close out any open nfsd_files that can be reaped for @inode. The -* actual freeing is deferred to the dispose_list_delayed infrastructure. +* actual freeing is deferred to the nfsd service threads. * * This is used by the fsnotify callbacks and setlease notifier. */
@@ -892,42 +885,14 @@ __nfsd_file_cache_purge(struct net *net)nfsd_file_dispose_list (&dispose); } -static struct nfsd_fcache_disposal * -nfsd_alloc_fcache_disposal (void ) -{ -struct nfsd_fcache_disposal *l; - - l =kmalloc (sizeof (*l),GFP_KERNEL ); -if (!l) -return NULL ; -spin_lock_init (&l->lock); -INIT_LIST_HEAD (&l->freeme); -return l; -} - -static void -nfsd_free_fcache_disposal (struct nfsd_fcache_disposal *l) -{ -nfsd_file_dispose_list (&l->freeme); -kfree (l); -} - -static void -nfsd_free_fcache_disposal_net (struct net *net) -{ -struct nfsd_net *nn =net_generic (net, nfsd_net_id); -struct nfsd_fcache_disposal *l = nn->fcache_disposal; - -nfsd_free_fcache_disposal (l); -} -int nfsd_file_cache_start_net (struct net *net) {struct nfsd_net *nn =net_generic (net, nfsd_net_id); - nn->fcache_disposal =nfsd_alloc_fcache_disposal (); -return nn->fcache_disposal ?0 : -ENOMEM ; +spin_lock_init (&nn->fcache_dispose_lock); +INIT_LIST_HEAD (&nn->fcache_dispose_list); +return 0 ; }/**
@@ -946,6 +911,8 @@ nfsd_file_cache_purge(struct net *net)void nfsd_file_cache_shutdown_net (struct net *net) { +struct nfsd_net *nn =net_generic (net, nfsd_net_id); +nfsd_file_cache_purge (net);/* * Ensure any in-progress shrinker, GC, or fsnotify/lease callback
@@ -955,7 +922,7 @@ nfsd_file_cache_shutdown_net(struct net *net)*/ spin_lock (&nfsd_gc_lock);spin_unlock (&nfsd_gc_lock); -nfsd_free_fcache_disposal_net (net); +nfsd_file_dispose_list (&nn->fcache_dispose_list); }void
fs/nfsd/netns.h +2 -1
@@ -216,7 +216,8 @@ struct nfsd_net {/* utsname taken from the process that starts the server */ char nfsd_name[UNX_MAXNODENAME +1 ]; -struct nfsd_fcache_disposal *fcache_disposal; +spinlock_t fcache_dispose_lock; +struct list_head fcache_dispose_list;siphash_key_t siphash_key;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 574/869 nfsd: restore rq_status_counter to even on all nfsd_dispatch() exit paths
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Layton <[email protected]>
[ Upstream commit f6045886fe3f14f269f683d64021b004a50d0efa ]
nfsd_dispatch() sets rq_status_counter to an odd value once a request has been decoded, and back to an even value once it has been fully processed, forming a seq-lock like protocol with the lockless reader in nfsd_nl_rpc_status_get_dumpit().
Only the fully successful path restored the counter to even. The cache-hit (RC_REPLY), drop (RC_DROPIT / RQ_DROPME) and encode-error paths all return after the odd-valued store without ever bringing the counter back to even. Once one of those paths is taken, rq_status_counter is left odd: the next request's decode ORs in 1 (still odd) and only a subsequent successful encode restores even. While stuck odd, the dumpit reader treats the rqstp fields as stable and its retry check compares against the same unchanging odd value, so it never detects concurrent mutation. This exposes actively mutating fields (e.g. args->ops / args->opcnt during compound decode and release) to the lockless reader, which can read past the end of the 8-element inline ops array.
Add a helper that advances the counter to the next even value and call it on every return path that follows the odd-valued store. The decode-error path is left untouched as it is reached before the counter is set odd.
--- fs/nfsd/nfssvc.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
fs/nfsd/nfssvc.c +17 -6
@@ -974,6 +974,20 @@ nfsd(void *vrqstp)return 0 ; } +/* +* Set rq_status_counter back to an even value, indicating that the rqstp +* fields are no longer meaningful to a lockless reader. This pairs with the +* odd-valued store made once the request has been decoded, and must run on +* every return path that follows it so that the seq-lock like protocol used +* by nfsd_nl_rpc_status_get_dumpit() is not left permanently odd. The store +* also advances the counter so a concurrent reader detects the transition. +*/ +static void nfsd_status_counter_set_idle (struct svc_rqst *rqstp) +{ +smp_store_release (&rqstp->rq_status_counter, + (rqstp->rq_status_counter |1 ) +1 ); +} +/** * nfsd_dispatch - Process an NFS or NFSACL or LOCALIO Request * @rqstp: incoming request
@@ -1035,14 +1049,9 @@ int nfsd_dispatch(struct svc_rqst *rqstp)if (!proc->pc_encode (rqstp, &rqstp->rq_res_stream)) goto out_encode_err; -/* -* Release rq_status_counter setting it to an even value after the rpc -* request has been properly processed. -*/ -smp_store_release (&rqstp->rq_status_counter, rqstp->rq_status_counter +1 ); -nfsd_cache_update (rqstp, rp, rqstp->rq_cachetype, nfs_reply); out_cached_reply: +nfsd_status_counter_set_idle (rqstp);return 1 ; out_decode_err:
@@ -1053,12 +1062,14 @@ int nfsd_dispatch(struct svc_rqst *rqstp) out_update_drop:nfsd_cache_update (rqstp, rp,RC_NOCACHE ,NULL ); out_dropit: +nfsd_status_counter_set_idle (rqstp);return 0 ; out_encode_err:trace_nfsd_cant_encode_err (rqstp);nfsd_cache_update (rqstp, rp,RC_NOCACHE ,NULL ); *statp = rpc_system_err; +nfsd_status_counter_set_idle (rqstp);return 1 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 575/869 lockd, nfsd: RCU-protect nlmsvc_ops dispatch
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Layton <[email protected]>
[ Upstream commit 641e5e20852359b8c31149be4598884e30652f60 ]
nlmsvc_ops is published by nfsd_lockd_init() and cleared by nfsd_lockd_shutdown() with plain stores, while lockd dereferences it unguarded from dispatch sites in fs/lockd/svcsubs.c. The pointer targets nfsd's .rodata and the fopen/fclose callbacks live in nfsd's .text, so a stale load after rmmod nfsd results in either a NULL deref or a module-text use-after-free.
Declare nlmsvc_ops as __rcu, publish via rcu_assign_pointer(), clear via RCU_INIT_POINTER() + synchronize_rcu(). Add a struct module *owner field to nlmsvc_binding and pin the module across indirect calls with try_module_get/module_put. When the binding is torn down, fall back to fput() to avoid leaking struct file references.
--- fs/lockd/svc.c | 4 ++-- fs/lockd/svc4proc.c | 4 ++-- fs/lockd/svcproc.c | 4 ++-- fs/lockd/svcsubs.c | 45 +++++++++++++++++++++++++++++++++----- fs/nfsd/lockd.c | 6 +++-- include/linux/lockd/bind.h | 12 +++++++--- 6 files changed, 59 insertions(+), 16 deletions(-)
fs/lockd/svc.c +2 -2
@@ -47,7 +47,7 @@static struct svc_program nlmsvc_program; -const struct nlmsvc_binding *nlmsvc_ops; +const struct nlmsvc_binding __rcu *nlmsvc_ops;EXPORT_SYMBOL_GPL (nlmsvc_ops);static DEFINE_MUTEX (nlmsvc_mutex);
@@ -142,7 +142,7 @@ lockd(void *vrqstp)nlmsvc_retry_blocked (rqstp);svc_recv (rqstp); } -if (nlmsvc_ops) +if (rcu_access_pointer (nlmsvc_ops))nlmsvc_invalidate_all ();nlm_shutdown_hosts ();cancel_delayed_work_sync (&ln->grace_period_end);
fs/lockd/svc4proc.c +2 -2
@@ -29,7 +29,7 @@ nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,__be32 error =0 ;/* nfsd callbacks must have been installed for this procedure */ -if (!nlmsvc_ops) +if (!rcu_access_pointer (nlmsvc_ops))return nlm_lck_denied_nolocks; if (lock->lock_start > OFFSET_MAX ||
@@ -487,7 +487,7 @@ nlm4svc_proc_granted_res(struct svc_rqst *rqstp) {struct nlm_res *argp = rqstp->rq_argp; -if (!nlmsvc_ops) +if (!rcu_access_pointer (nlmsvc_ops))return rpc_success;dprintk ("lockd: GRANTED_RES called\n" );
fs/lockd/svcproc.c +2 -2
@@ -59,7 +59,7 @@ nlmsvc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,__be32 error =0 ;/* nfsd callbacks must have been installed for this procedure */ -if (!nlmsvc_ops) +if (!rcu_access_pointer (nlmsvc_ops))return nlm_lck_denied_nolocks;/* Obtain host handle */
@@ -521,7 +521,7 @@ nlmsvc_proc_granted_res(struct svc_rqst *rqstp) {struct nlm_res *argp = rqstp->rq_argp; -if (!nlmsvc_ops) +if (!rcu_access_pointer (nlmsvc_ops))return rpc_success;dprintk ("lockd: GRANTED_RES called\n" );
fs/lockd/svcsubs.c +40 -5
68 lines not on this page · raw message
fs/nfsd/lockd.c +4 -2
@@ -88,6 +88,7 @@ nlm_fclose(struct file *filp) }static const struct nlmsvc_binding nfsd_nlm_ops = { + .owner =THIS_MODULE , .fopen = nlm_fopen,/* open file for locking */ .fclose = nlm_fclose,/* close file */ };
@@ -96,11 +97,12 @@ voidnfsd_lockd_init (void) {dprintk ("nfsd: initializing lockd\n" ); - nlmsvc_ops = &nfsd_nlm_ops; +rcu_assign_pointer (nlmsvc_ops, &nfsd_nlm_ops); }void nfsd_lockd_shutdown (void ) { - nlmsvc_ops =NULL ; +RCU_INIT_POINTER (nlmsvc_ops,NULL ); +synchronize_rcu (); }
include/linux/lockd/bind.h +9 -3
@@ -21,11 +21,17 @@struct svc_rqst ;struct rpc_task ;struct rpc_clnt ; +struct module ; -/* -* This is the set of functions for lockd->nfsd communication +/** +* struct nlmsvc_binding - lockd -> nfsd callback table +* @owner: module that provides this binding. +* @fopen: open a file by NFS file handle on behalf of an NLM request. +* @fclose: close a file that was previously opened via @fopen. +* Implementations MUST be semantically equivalent to fput(). */ struct nlmsvc_binding { +struct module *owner; __be32 (*fopen)(struct svc_rqst *, struct nfs_fh *, struct file **,
@@ -33,7 +39,7 @@ struct nlmsvc_binding {void (*fclose)(struct file *); }; -extern const struct nlmsvc_binding *nlmsvc_ops; +extern const struct nlmsvc_binding __rcu *nlmsvc_ops;/* * Similar to nfs_client_initdata, but without the NFS-specific
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 576/869 mm/mglru: reset page lru tier bits when activating
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wei Xu <[email protected]>
[ Upstream commit f1001f3d3b6868998cab73d10fda1a5c99ddf963 ]
When a folio is activated, lru_gen_add_folio() moves the folio to the youngest generation. But unlike folio_update_gen()/folio_inc_gen(), lru_gen_add_folio() doesn't reset the folio lru tier bits (LRU_REFS_MASK | LRU_REFS_FLAGS). This inconsistency can affect how pages are aged via folio_mark_accessed() (e.g. fd accesses), though no user visible impact related to this has been detected yet.
Note that lru_gen_add_folio() cannot clear PG_workingset if the activation is due to workingset refault, otherwise PSI accounting will be skipped. So fix lru_gen_add_folio() to clear the lru tier bits other than PG_workingset when activating a folio, and also clear all the lru tier bits when a folio is activated via folio_activate() in lru_gen_look_around().
Stable-dep-of: f7e698e326b2 ("mm/mglru: fix and remove redundant unevictable folio handling")
--- include/linux/mm_inline.h | 15 ++++++++++++++- include/linux/mmzone.h | 2 ++ mm/vmscan.c | 8 ++++---- 3 files changed, 20 insertions(+), 5 deletions(-)
include/linux/mm_inline.h +14 -1
@@ -155,6 +155,11 @@ static inline int folio_lru_refs(struct folio *folio)return ((flags &LRU_REFS_MASK ) >>LRU_REFS_PGOFF ) + workingset; } +static inline void folio_clear_lru_refs (struct folio *folio) +{ +set_mask_bits (&folio->flags,LRU_REFS_MASK |LRU_REFS_FLAGS ,0 ); +} +static inline int folio_lru_gen (struct folio *folio) {unsigned long flags =READ_ONCE (folio->flags);
@@ -222,6 +227,7 @@ static inline bool lru_gen_add_folio(struct lruvec *lruvec, struct folio *folio, {unsigned long seq;unsigned long flags; +unsigned long mask;int gen =folio_lru_gen (folio);int type =folio_is_file_lru (folio);int zone =folio_zonenum (folio);
@@ -257,7 +263,14 @@ static inline bool lru_gen_add_folio(struct lruvec *lruvec, struct folio *folio, gen =lru_gen_from_seq (seq); flags = (gen +1UL ) <<LRU_GEN_PGOFF ;/* see the comment on MIN_NR_GENS about PG_active */ -set_mask_bits (&folio->flags,LRU_GEN_MASK |BIT (PG_active), flags); + mask =LRU_GEN_MASK ; +/* +* Don't clear PG_workingset here because it can affect PSI accounting +* if the activation is due to workingset refault. +*/ +if (folio_test_active (folio)) + mask |=LRU_REFS_MASK |BIT (PG_referenced) |BIT (PG_active); +set_mask_bits (&folio->flags, mask, flags);lru_gen_update_size (lruvec, folio,-1 , gen);/* for folio_rotate_reclaimable() */
include/linux/mmzone.h +2 -0
@@ -403,6 +403,8 @@ enum { NR_LRU_GEN_CAPS }; +#define LRU_REFS_FLAGS (BIT(PG_referenced) | BIT(PG_workingset)) +#define MIN_LRU_BATCH BITS_PER_LONG#define MAX_LRU_BATCH (MIN_LRU_BATCH * 64)
mm/vmscan.c +4 -4
@@ -2625,8 +2625,6 @@ static bool should_clear_pmd_young(void)* shorthand helpers ******************************************************************************/ -#define LRU_REFS_FLAGS (BIT(PG_referenced) | BIT(PG_workingset)) -#define DEFINE_MAX_SEQ (lruvec) \ unsigned long max_seq = READ_ONCE((lruvec)->lrugen.max_seq)
@@ -4157,8 +4155,10 @@ bool lru_gen_look_around(struct page_vma_mapped_walk *pvmw) old_gen =folio_lru_gen (folio);if (old_gen <0 )folio_set_referenced (folio); -else if (old_gen != new_gen) +else if (old_gen != new_gen) { +folio_clear_lru_refs (folio);folio_activate (folio); + } }arch_leave_lazy_mmu_mode ();
@@ -4400,7 +4400,7 @@ static bool isolate_folio(struct lruvec *lruvec, struct folio *folio, struct sca/* see the comment on MAX_NR_TIERS */ if (!folio_test_referenced (folio)) -set_mask_bits (&folio->flags,LRU_REFS_MASK |LRU_REFS_FLAGS ,0 ); +folio_clear_lru_refs (folio);/* for shrink_folio_list() */ folio_clear_reclaim (folio);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 577/869 mm/mglru: use the common routine for dirty/writeback reactivation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kairui Song <[email protected]>
[ Upstream commit 75d4c3f5fb980de1b620adede47e43dff4d6a5f3 ]
Currently MGLRU will move the dirty writeback folios to the second oldest gen instead of reactivate them like the classical LRU. This might help to reduce the LRU contention as it skipped the isolation. But as a result we will see these folios at the LRU tail more frequently leading to inefficient reclaim.
Besides, the dirty / writeback check after isolation in shrink_folio_list is more accurate and covers more cases. So instead, just drop the special handling for dirty writeback, use the common routine and re-activate it like the classical LRU.
This should in theory improve the scan efficiency. These folios will be rotated back to LRU tail once writeback is done so there is no risk of hotness inversion. And now each reclaim loop will have a higher success rate. This also prepares for unifying the writeback and throttling mechanism with classical LRU, we keep these folios far from tail so detecting the tail batch will have a similar pattern with classical LRU.
The micro optimization that avoids LRU contention by skipping the isolation is gone, which should be fine. Compared to IO and writeback cost, the isolation overhead is trivial.
And using the common routine also keeps the folio's referenced bits (tier bits), which could improve metrics in the long term. Also no more need to clean reclaim bit as the common routine will make use of it.
Note the common routine updates a few throttling and writeback counters, which are not used, and never have been for the MGLRU case. We will start making use of these in later commits.
Stable-dep-of: f7e698e326b2 ("mm/mglru: fix and remove redundant unevictable folio handling")
--- mm/vmscan.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-)
mm/vmscan.c +1 -19
@@ -4313,7 +4313,6 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, struct scan_c int tier_idx) {bool success; -bool dirty, writeback;int gen =folio_lru_gen (folio);int type =folio_is_file_lru (folio);int zone =folio_zonenum (folio);
@@ -4359,22 +4358,6 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, struct scan_creturn true; } - dirty =folio_test_dirty (folio); - writeback =folio_test_writeback (folio); -if (type ==LRU_GEN_FILE && dirty) { - sc->nr.file_taken += delta; -if (!writeback) - sc->nr.unqueued_dirty += delta; - } - -/* waiting for writeback */ -if (folio_test_locked (folio) || writeback || - (type ==LRU_GEN_FILE && dirty)) { - gen =folio_inc_gen (lruvec, folio, true); -list_move (&folio->lru, &lrugen->folios[gen][type][zone]); -return true; - } -return false; }
@@ -4384,7 +4367,7 @@ static bool isolate_folio(struct lruvec *lruvec, struct folio *folio, struct sca/* swap constrained */ if (!(sc->gfp_mask & __GFP_IO) && - (folio_test_dirty (folio) || + ((folio_test_dirty (folio) && !folio_is_file_lru (folio)) || (folio_test_anon (folio) && !folio_test_swapcache (folio))))return false;
@@ -4403,7 +4386,6 @@ static bool isolate_folio(struct lruvec *lruvec, struct folio *folio, struct scafolio_clear_lru_refs (folio);/* for shrink_folio_list() */ -folio_clear_reclaim (folio);folio_clear_referenced (folio); success =lru_gen_del_folio (lruvec, folio, true);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 578/869 mm/mglru: fix and remove redundant unevictable folio handling
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kairui Song <[email protected]>
[ Upstream commit f7e698e326b239a91ea15844817551921209e826 ]
sort_folio() has a shortcut for moving folios that are no longer evictable but are still sitting on a generation list. However, this shortcut is buggy. It does not follow the PG_lru usage convention, and it has a more serious issue.
Unevictable folios are not threaded on lists[LRU_UNEVICTABLE], so that folio->lru can be reused to hold folio->mlock_count (see the comment in lruvec_init()). Hence lruvec_add_folio() skips the list_add() for them, and every other place that turns a folio unevictable initialises mlock_count explicitly: lru_add() sets it to 0, __mlock_folio() and __mlock_new_folio() set it to !!folio_test_mlocked(folio). sort_folio() sets nothing, and the lru_gen_del_folio() right above it may have already poisoned folio->lru via list_del(), so mlock_count ends up aliasing LIST_POISON2, which reads as 0x122, i.e. 290. The result is user visible. On munlock, __munlock_folio() decrements that bogus count, finds it still non-zero and bails out before clearing PG_mlocked, so the folio remains unevictable and the Mlocked accounting stays inflated until the folio is freed.
The shortcut also touches the LRU flags in the wrong order. It calls lru_gen_del_folio() while PG_lru is still set, so a concurrent folio_test_clear_lru() (e.g. compaction, folio_isolate_lru()) can succeed on a folio that has already been taken off the generation list, which may lead to unexpected behavior.
So fix it by isolating them as common folios and letting the generic shrink path cull them. This matches the classical LRU behavior, and there should be no visible effect on the generic eviction or isolation behavior.
There is no performance concern either, such a folio goes through this once, and then it is off the generation lists for good.
--- mm/vmscan.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-)
mm/vmscan.c +5 -14
@@ -4312,7 +4312,6 @@ void lru_gen_soft_reclaim(struct mem_cgroup *memcg, int nid)static bool sort_folio (struct lruvec *lruvec,struct folio *folio,struct scan_control *sc,int tier_idx) { -bool success;int gen =folio_lru_gen (folio);int type =folio_is_file_lru (folio);int zone =folio_zonenum (folio);
@@ -4323,15 +4322,9 @@ static bool sort_folio(struct lruvec *lruvec, struct folio *folio, struct scan_cVM_WARN_ON_ONCE_FOLIO (gen >=MAX_NR_GENS , folio); -/* unevictable */ -if (!folio_evictable (folio)) { - success =lru_gen_del_folio (lruvec, folio, true); -VM_WARN_ON_ONCE_FOLIO (!success, folio); -folio_set_unevictable (folio); -lruvec_add_folio (lruvec, folio); -__count_vm_events (UNEVICTABLE_PGCULLED , delta); -return true; - } +/* unevictable: let it through and the generic path will cull it */ +if (!folio_evictable (folio)) +return false;/* promoted */ if (gen !=lru_gen_from_seq (lrugen->min_seq[type])) {
@@ -4609,11 +4602,9 @@ static int evict_folios(struct lruvec *lruvec, struct scan_control *sc, int swap type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON);list_for_each_entry_safe_reverse (folio, next, &list, lru) { -if (!folio_evictable (folio)) { -list_del (&folio->lru); -folio_putback_lru (folio); +/* move_folios_to_lru() culls unevictable folios via folio_putback_lru() */ +if (!folio_evictable (folio))continue ; - }if (folio_test_reclaim (folio) && (folio_test_dirty (folio) ||folio_test_writeback (folio))) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 579/869 ksmbd: fix tree connection use-after-free in smb2_tree_connect()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang (Microsoft Security FORGE Labs) <[email protected]>
[ Upstream commit b5ec6c462aab1062cf5d1e667ba7c6442f737055 ]
ksmbd_tree_conn_connect() publishes a new tree connection in sess->tree_conns with a single reference and returns its pointer to smb2_tree_connect(). The handler continues to initialize the object and build the response after publication. A concurrent session logoff can erase the connection and drop that reference, freeing the object while the handler still uses it.
BUG: KASAN: slab-use-after-free in smb2_tree_connect+0xe3d/0xf90 smb2_tree_connect (fs/smb/server/smb2pdu.c:2872) handle_ksmbd_work process_one_work worker_thread kthread
After xa_store() succeeds, take a second reference before releasing tree_conns_lock. The original reference belongs to the xarray entry and the second belongs to the creating smb2_tree_connect() handler.
Keep the references balanced in every path:
- On normal exit or an error after publication, smb2_tree_connect() drops its creator reference. Error cleanup also calls ksmbd_tree_conn_disconnect(), which drops the xarray reference only if it removes the exact entry.
- SMB2 TREE_DISCONNECT uses the same helper to remove the entry and drop its xarray reference. The request's existing lookup reference remains owned by the request and is released by the existing cleanup.
- Session LOGOFF removes each entry and drops its xarray reference. If it wins the race, later cleanup sees that the entry is gone and does not drop that reference again.
To enforce this ownership, claim the disconnected state and erase the exact entry atomically under tree_conns_lock. This guarantees one drop for the xarray reference and one drop by each in-flight user, regardless of which teardown path wins. If logoff removes the entry before initialization completes, fail the connect instead of marking the detached object TREE_CONNECTED.
--- fs/smb/server/mgmt/tree_connect.c | 26 +++++++++++----------- fs/smb/server/smb2pdu.c | 36 ++++++++++++++++++------------- 2 files changed, 34 insertions(+), 28 deletions(-)
fs/smb/server/mgmt/tree_connect.c +13 -13
@@ -77,7 +77,7 @@ ksmbd_tree_conn_connect(struct ksmbd_work *work, const char *share_name) tree_conn->share_conf = sc; tree_conn->t_state =TREE_NEW ; status.tree_conn = tree_conn; -atomic_set (&tree_conn->refcount,1 ); +atomic_set (&tree_conn->refcount,2 ); ret =xa_err (xa_store (&sess->tree_conns, tree_conn->id, tree_conn,KSMBD_DEFAULT_GFP ));
@@ -99,8 +99,10 @@ ksmbd_tree_conn_connect(struct ksmbd_work *work, const char *share_name)void ksmbd_tree_connect_put (struct ksmbd_tree_connect *tcon) { -if (atomic_dec_and_test (&tcon->refcount)) +if (atomic_dec_and_test (&tcon->refcount)) { +ksmbd_share_config_put (tcon->share_conf);kfree (tcon); + } } int ksmbd_tree_conn_disconnect(struct ksmbd_session *sess,
@@ -109,14 +111,21 @@ int ksmbd_tree_conn_disconnect(struct ksmbd_session *sess,int ret;write_lock (&sess->tree_conns_lock); +if (tree_conn->t_state ==TREE_DISCONNECTED || +xa_load (&sess->tree_conns, tree_conn->id) != tree_conn) { +write_unlock (&sess->tree_conns_lock); +return -ENOENT ; + } + tree_conn->t_state =TREE_DISCONNECTED ;xa_erase (&sess->tree_conns, tree_conn->id);write_unlock (&sess->tree_conns_lock); ret =ksmbd_ipc_tree_disconnect_request (sess->id, tree_conn->id);ksmbd_release_tree_conn_id (sess, tree_conn->id); -ksmbd_share_config_put (tree_conn->share_conf); -if (atomic_dec_and_test (&tree_conn->refcount)) +if (atomic_dec_and_test (&tree_conn->refcount)) { +ksmbd_share_config_put (tree_conn->share_conf);kfree (tree_conn); + }return ret; }
@@ -148,15 +157,6 @@ int ksmbd_tree_conn_session_logoff(struct ksmbd_session *sess)return -EINVAL ;xa_for_each (&sess->tree_conns, id, tc) { -write_lock (&sess->tree_conns_lock); -if (tc->t_state ==TREE_DISCONNECTED ) { -write_unlock (&sess->tree_conns_lock); - ret = -ENOENT ; -continue ; - } - tc->t_state =TREE_DISCONNECTED ; -write_unlock (&sess->tree_conns_lock); - ret |=ksmbd_tree_conn_disconnect (sess, tc); }xa_destroy (&sess->tree_conns);
fs/smb/server/smb2pdu.c +21 -15
@@ -2001,6 +2001,7 @@ int smb2_tree_connect(struct ksmbd_work *work)struct ksmbd_session *sess = work->sess;char *treename =NULL , *name =NULL ;struct ksmbd_tree_conn_status status; +struct ksmbd_tree_connect *tree_conn =NULL ;struct ksmbd_share_config *share =NULL ;int rc = -EINVAL ;
@@ -2025,9 +2026,10 @@ int smb2_tree_connect(struct ksmbd_work *work) name, treename); status =ksmbd_tree_conn_connect (work, name); -if (status.ret ==KSMBD_TREE_CONN_STATUS_OK ) +if (status.ret ==KSMBD_TREE_CONN_STATUS_OK ) { + tree_conn = status.tree_conn; rsp->hdr.Id.SyncId.TreeId =cpu_to_le32 (status.tree_conn->id); -else + }else goto out_err1; share = status.tree_conn->share_conf;
@@ -2059,8 +2061,15 @@ int smb2_tree_connect(struct ksmbd_work *work) status.tree_conn->posix_extensions = true;write_lock (&sess->tree_conns_lock); - status.tree_conn->t_state =TREE_CONNECTED ; +if (status.tree_conn->t_state ==TREE_DISCONNECTED ) { + status.ret =KSMBD_TREE_CONN_STATUS_ERROR ; + share =NULL ; + }else { + status.tree_conn->t_state =TREE_CONNECTED ; + }write_unlock (&sess->tree_conns_lock); +if (status.ret !=KSMBD_TREE_CONN_STATUS_OK ) + goto out_err1; rsp->StructureSize =cpu_to_le16 (16 ); out_err1:/*
@@ -2073,8 +2082,13 @@ int smb2_tree_connect(struct ksmbd_work *work) rsp->ShareFlags =SMB2_SHAREFLAG_MANUAL_CACHING ; rc =ksmbd_iov_pin_rsp (work, rsp,sizeof (struct smb2_tree_connect_rsp )); -if (rc) +if (rc) { +if (status.ret ==KSMBD_TREE_CONN_STATUS_OK ) { +ksmbd_tree_conn_disconnect (sess, status.tree_conn); + status.tree_conn =NULL ; + } status.ret =KSMBD_TREE_CONN_STATUS_NOMEM ; + }if (!IS_ERR (treename))kfree (treename);
@@ -2110,6 +2124,9 @@ int smb2_tree_connect(struct ksmbd_work *work)if (status.ret !=KSMBD_TREE_CONN_STATUS_OK )smb2_set_err_rsp (work); +if (tree_conn) +ksmbd_tree_connect_put (tree_conn); +return rc; }
@@ -2213,17 +2230,6 @@ int smb2_tree_disconnect(struct ksmbd_work *work)ksmbd_close_tree_conn_fds (work); -write_lock (&sess->tree_conns_lock); -if (tcon->t_state ==TREE_DISCONNECTED ) { -write_unlock (&sess->tree_conns_lock); - rsp->hdr.Status =STATUS_NETWORK_NAME_DELETED ; - err = -ENOENT ; - goto err_out; - } - - tcon->t_state =TREE_DISCONNECTED ; -write_unlock (&sess->tree_conns_lock); - err =ksmbd_tree_conn_disconnect (sess, tcon);if (err) { rsp->hdr.Status =STATUS_NETWORK_NAME_DELETED ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 580/869 drm/amdkfd: Fix partial migrate issue
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Emily Deng <[email protected]>
[ Upstream commit b5f022fe8ec58540e29a32e328f89b7298f70313 ]
For partial migrate from ram to vram, the migrate->cpages is not equal to migrate->npages, should use migrate->npages to check all needed migrate pages which could be copied or not.
And only need to set those pages could be migrated to migrate->dst[i], or the migrate_vma_pages will migrate the wrong pages based on the migrate->dst[i].
v2:
Add mpages to break the loop earlier.
v3:
Uses MIGRATE_PFN_MIGRATE to identify whether page could be migrated.
v4:
Correct the error part.
Stable-dep-of: 520e345ffe05 ("drm/amdkfd: Fix the case that vm range is hole at svm_migrate_copy_to_vram")
--- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +14 -8
@@ -279,10 +279,11 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange, struct migrate_vma *migrate, struct dma_fence **mfence, dma_addr_t *scratch, uint64_t ttm_res_offset) { - uint64_t npages = migrate->cpages; + uint64_t npages = migrate->npages;struct amdgpu_device *adev = node->adev;struct device *dev = adev->dev;struct amdgpu_res_cursor cursor; +uint64_t mpages =0 ;dma_addr_t *src;uint64_t *dst;uint64_t i, j;
@@ -296,14 +297,16 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange,amdgpu_res_first (prange->ttm_res, ttm_res_offset, npages <<PAGE_SHIFT , &cursor); -for (i = j =0 ; i < npages; i++) { +for (i = j =0 ; (i < npages) && (mpages < migrate->cpages); i++) {struct page *spage; - dst[i] = cursor.start + (j <<PAGE_SHIFT ); - migrate->dst[i] =svm_migrate_addr_to_pfn (adev, dst[i]); -svm_migrate_get_vram_page (prange, migrate->dst[i]); - migrate->dst[i] =migrate_pfn (migrate->dst[i]); - +if (migrate->src[i] &MIGRATE_PFN_MIGRATE ) { + dst[i] = cursor.start + (j <<PAGE_SHIFT ); + migrate->dst[i] =svm_migrate_addr_to_pfn (adev, dst[i]); +svm_migrate_get_vram_page (prange, migrate->dst[i]); + migrate->dst[i] =migrate_pfn (migrate->dst[i]); + mpages++; + } spage =migrate_pfn_to_page (migrate->src[i]);if (spage && !is_zone_device_page (spage)) { src[i] = dma_map_page(dev, spage, 0, PAGE_SIZE,
@@ -354,9 +357,12 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange, out_free_vram_pages:if (r) {pr_debug ("failed %d to copy memory to vram\n" , r); -while (i--) { +for (i =0 ; i < npages && mpages; i++) { +if (!dst[i]) +continue ;svm_migrate_put_vram_page (adev, dst[i]); migrate->dst[i] =0 ; + mpages--; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 581/869 drm/amdkfd: return migration pages from copy function
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Zhu <[email protected]>
[ Upstream commit bd6093e2f1601c0c83906f5115a2efb6b93050b1 ]
dst MIGRATE_PFN_VALID bit and src MIGRATE_PFN_MIGRATE bit should always be set when migration success. cpage includes src MIGRATE_PFN_MIGRATE bit set and MIGRATE_PFN_VALID bit unset pages for both ram and vram when memory is only allocated without being populated before migration, those ram pages should be counted as migrate pages and those vram pages should not be counted as migrate pages. Here migration pages refer to how many vram pages involved.
-v2 use dst to check MIGRATE_PFN_VALID bit (suggested-by Philip) -v3 add warning when vram pages is less than migration pages
return migration pages directly from copy function
-v4 correct comments and copy function return mpage (suggested-by Felix)
Stable-dep-of: 520e345ffe05 ("drm/amdkfd: Fix the case that vm range is hole at svm_migrate_copy_to_vram")
--- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 72 ++++++++++++------------ 1 file changed, 36 insertions(+), 36 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +36 -36
@@ -261,20 +261,7 @@ static void svm_migrate_put_sys_page(unsigned long addr)put_page (page); } -static unsigned long svm_migrate_unsuccessful_pages (struct migrate_vma *migrate) -{ -unsigned long upages =0 ; -unsigned long i; - -for (i =0 ; i < migrate->npages; i++) { -if (migrate->src[i] &MIGRATE_PFN_VALID && - !(migrate->src[i] &MIGRATE_PFN_MIGRATE )) - upages++; - } -return upages; -} - -static int +static long svm_migrate_copy_to_vram (struct kfd_node *node,struct svm_range *prange,struct migrate_vma *migrate,struct dma_fence **mfence,dma_addr_t *scratch,uint64_t ttm_res_offset)
@@ -283,7 +270,7 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange,struct amdgpu_device *adev = node->adev;struct device *dev = adev->dev;struct amdgpu_res_cursor cursor; -uint64_t mpages =0 ; +long mpages;dma_addr_t *src;uint64_t *dst;uint64_t i, j;
@@ -297,6 +284,7 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange,amdgpu_res_first (prange->ttm_res, ttm_res_offset, npages <<PAGE_SHIFT , &cursor); + mpages =0 ;for (i = j =0 ; (i < npages) && (mpages < migrate->cpages); i++) {struct page *spage;
@@ -357,13 +345,14 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange, out_free_vram_pages:if (r) {pr_debug ("failed %d to copy memory to vram\n" , r); -for (i =0 ; i < npages && mpages; i++) { +while (i-- && mpages) {if (!dst[i])continue ;svm_migrate_put_vram_page (adev, dst[i]); migrate->dst[i] =0 ; mpages--; } + mpages = r; }#ifdef DEBUG_FORCE_MIXED_DOMAINS
@@ -381,7 +370,7 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange, }#endif -return r; +return mpages; } static long
@@ -396,7 +385,7 @@ svm_migrate_vma_to_vram(struct kfd_node *node, struct svm_range *prange,struct dma_fence *mfence =NULL ;struct migrate_vma migrate = {0 };unsigned long cpages =0 ; -unsigned long mpages =0 ; +long mpages =0 ;dma_addr_t *scratch;void *buf;int r = -ENOMEM ;
@@ -442,15 +431,17 @@ svm_migrate_vma_to_vram(struct kfd_node *node, struct svm_range *prange,else pr_debug ("0x%lx pages collected\n" , cpages); - r =svm_migrate_copy_to_vram (node, prange, &migrate, &mfence, scratch, ttm_res_offset); + mpages =svm_migrate_copy_to_vram (node, prange, &migrate, &mfence, scratch, ttm_res_offset);migrate_vma_pages (&migrate);svm_migrate_copy_done (adev, mfence);migrate_vma_finalize (&migrate); - mpages = cpages -svm_migrate_unsuccessful_pages (&migrate); -pr_debug ("successful/cpages/npages 0x%lx/0x%lx/0x%lx\n" , +if (mpages >=0 ) +pr_debug ("migrated/collected/requested 0x%lx/0x%lx/0x%lx\n" , mpages, cpages, migrate.npages); +else + r = mpages; kfd_smi_event_migration_end(node, p->lead_thread->pid, start >> PAGE_SHIFT, end >> PAGE_SHIFT,
@@ -461,14 +452,13 @@ svm_migrate_vma_to_vram(struct kfd_node *node, struct svm_range *prange, out_free:kvfree (buf); out: -if (!r && mpages) { +if (!r && mpages >0 ) { pdd =svm_range_get_pdd_by_node (prange, node);if (pdd)WRITE_ONCE (pdd->page_in, pdd->page_in + mpages); - -return mpages; } -return r; + +return r ? r : mpages; }/**
@@ -579,7 +569,7 @@ static void svm_migrate_page_free(struct page *page) } } -static int +static long svm_migrate_copy_to_ram (struct amdgpu_device *adev,struct svm_range *prange,struct migrate_vma *migrate,struct dma_fence **mfence,dma_addr_t *scratch,uint64_t npages)
@@ -588,6 +578,7 @@ svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange,uint64_t *src;dma_addr_t *dst;struct page *dpage; +long mpages;uint64_t i =0 , j;uint64_t addr;int r =0 ;
@@ -600,6 +591,7 @@ svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange, src = (uint64_t *)(scratch + npages); dst = scratch; + mpages =0 ;for (i =0 , j =0 ; i < npages; i++, addr +=PAGE_SIZE ) {struct page *spage;
@@ -648,6 +640,7 @@ svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange, dst[i] >> PAGE_SHIFT, page_to_pfn(dpage)); migrate->dst[i] =migrate_pfn (page_to_pfn (dpage)); + mpages++; j++; }
@@ -657,13 +650,17 @@ svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange, out_oom:if (r) {pr_debug ("failed %d copy to ram\n" , r); -while (i--) { +while (i-- && mpages) { +if (!migrate->dst[i]) +continue ;svm_migrate_put_sys_page (dst[i]); migrate->dst[i] =0 ; + mpages--; } + mpages = r; } -return r; +return mpages; }/**
@@ -690,9 +687,8 @@ svm_migrate_vma_to_ram(struct kfd_node *node, struct svm_range *prange, { struct kfd_process *p = container_of(prange->svms, struct kfd_process, svms);uint64_t npages = (end - start) >>PAGE_SHIFT ; -unsigned long upages = npages;unsigned long cpages =0 ; -unsigned long mpages =0 ; +long mpages =0 ;struct amdgpu_device *adev = node->adev;struct kfd_process_device *pdd;struct dma_fence *mfence =NULL ;
@@ -747,13 +743,15 @@ svm_migrate_vma_to_ram(struct kfd_node *node, struct svm_range *prange,else pr_debug ("0x%lx pages collected\n" , cpages); - r =svm_migrate_copy_to_ram (adev, prange, &migrate, &mfence, + mpages =svm_migrate_copy_to_ram (adev, prange, &migrate, &mfence, scratch, npages);migrate_vma_pages (&migrate); - upages =svm_migrate_unsuccessful_pages (&migrate); -pr_debug ("unsuccessful/cpages/npages 0x%lx/0x%lx/0x%lx\n" , - upages, cpages, migrate.npages); +if (mpages >=0 ) +pr_debug ("migrated/collected/requested 0x%lx/0x%lx/0x%lx\n" , + mpages, cpages, migrate.npages); +else + r = mpages;svm_migrate_copy_done (adev, mfence);migrate_vma_finalize (&migrate);
@@ -767,8 +765,7 @@ svm_migrate_vma_to_ram(struct kfd_node *node, struct svm_range *prange, out_free:kvfree (buf); out: -if (!r && cpages) { - mpages = cpages - upages; +if (!r && mpages >0 ) { pdd =svm_range_get_pdd_by_node (prange, node);if (pdd)WRITE_ONCE (pdd->page_out, pdd->page_out + mpages);
@@ -851,6 +848,9 @@ int svm_migrate_vram_to_ram(struct svm_range *prange, struct mm_struct *mm, }if (r >=0 ) { +WARN_ONCE (prange->vram_pages < mpages, +"Recorded vram pages(0x%llx) should not be less than migration pages(0x%lx)." , + prange->vram_pages, mpages); prange->vram_pages -= mpages;/* prange does not have vram page set its actual_loc to system
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 582/869 Revert "drm/amdkfd: return migration pages from copy function"
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Zhu <[email protected]>
[ Upstream commit 7ccaaf13197fddb525571d6646bc174405efb37c ]
This reverts commit bd6093e2f1601c0c83906f5115a2efb6b93050b1.
migrate_vma_pages can fail if a CPU thread faults on the same page. However, the page table is locked and only one of the new pages will be inserted. The device driver will see that the MIGRATE_PFN_MIGRATE bit is cleared if it loses the race.
Stable-dep-of: 520e345ffe05 ("drm/amdkfd: Fix the case that vm range is hole at svm_migrate_copy_to_vram")
--- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 130 +++++++++++------------ 1 file changed, 65 insertions(+), 65 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +65 -65
@@ -39,22 +39,22 @@#endif #define dev_fmt (fmt) "kfd_migrate: " fmt -static uint64_t -svm_migrate_direct_mapping_addr (struct amdgpu_device *adev,uint64_t addr) +static u64 +svm_migrate_direct_mapping_addr (struct amdgpu_device *adev,u64 addr) {return addr +amdgpu_ttm_domain_start (adev,TTM_PL_VRAM ); }static int -svm_migrate_gart_map (struct amdgpu_ring *ring,uint64_t npages, -dma_addr_t *addr,uint64_t *gart_addr,uint64_t flags) +svm_migrate_gart_map (struct amdgpu_ring *ring,u64 npages, +dma_addr_t *addr,u64 *gart_addr,u64 flags) {struct amdgpu_device *adev = ring->adev;struct amdgpu_job *job;unsigned int num_dw, num_bytes;struct dma_fence *fence; -uint64_t src_addr, dst_addr; -uint64_t pte_flags; +u64 src_addr, dst_addr; +u64 pte_flags;void *cpu_addr;int r;
@@ -123,15 +123,15 @@ svm_migrate_gart_map(struct amdgpu_ring *ring, uint64_t npages,static int svm_migrate_copy_memory_gart (struct amdgpu_device *adev,dma_addr_t *sys, -uint64_t *vram,uint64_t npages, +u64 *vram,u64 npages,enum MIGRATION_COPY_DIR direction,struct dma_fence **mfence) { -const uint64_t GTT_MAX_PAGES =AMDGPU_GTT_MAX_TRANSFER_SIZE ; +const u64 GTT_MAX_PAGES =AMDGPU_GTT_MAX_TRANSFER_SIZE ;struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring; -uint64_t gart_s, gart_d; +u64 gart_s, gart_d;struct dma_fence *next; -uint64_t size; +u64 size;int r;mutex_lock (&adev->mman.gtt_window_lock);
@@ -261,30 +261,42 @@ static void svm_migrate_put_sys_page(unsigned long addr)put_page (page); } -static long +static unsigned long svm_migrate_unsuccessful_pages (struct migrate_vma *migrate) +{ +unsigned long upages =0 ; +unsigned long i; + +for (i =0 ; i < migrate->npages; i++) { +if (migrate->src[i] &MIGRATE_PFN_VALID && + !(migrate->src[i] &MIGRATE_PFN_MIGRATE )) + upages++; + } +return upages; +} + +static int svm_migrate_copy_to_vram (struct kfd_node *node,struct svm_range *prange,struct migrate_vma *migrate,struct dma_fence **mfence, -dma_addr_t *scratch,uint64_t ttm_res_offset) +dma_addr_t *scratch,u64 ttm_res_offset) { -uint64_t npages = migrate->npages; +u64 npages = migrate->npages;struct amdgpu_device *adev = node->adev;struct device *dev = adev->dev;struct amdgpu_res_cursor cursor; -long mpages; +u64 mpages =0 ;dma_addr_t *src; -uint64_t *dst; -uint64_t i, j; +u64 *dst; +u64 i, j;int r;pr_debug ("svms 0x%p [0x%lx 0x%lx 0x%llx]\n" , prange->svms, prange->start, prange->last, ttm_res_offset); src = scratch; - dst = (uint64_t *)(scratch + npages); + dst = (u64 *)(scratch + npages);amdgpu_res_first (prange->ttm_res, ttm_res_offset, npages <<PAGE_SHIFT , &cursor); - mpages =0 ;for (i = j =0 ; (i < npages) && (mpages < migrate->cpages); i++) {struct page *spage;
@@ -345,14 +357,13 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange, out_free_vram_pages:if (r) {pr_debug ("failed %d to copy memory to vram\n" , r); -while (i-- && mpages) { +for (i =0 ; i < npages && mpages; i++) {if (!dst[i])continue ;svm_migrate_put_vram_page (adev, dst[i]); migrate->dst[i] =0 ; mpages--; } - mpages = r; }#ifdef DEBUG_FORCE_MIXED_DOMAINS
@@ -370,22 +381,22 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange, }#endif -return mpages; +return r; }static long svm_migrate_vma_to_vram (struct kfd_node *node,struct svm_range *prange, -struct vm_area_struct *vma,uint64_t start, -uint64_t end,uint32_t trigger,uint64_t ttm_res_offset) +struct vm_area_struct *vma,u64 start, +u64 end,uint32_t trigger,u64 ttm_res_offset) { struct kfd_process *p = container_of(prange->svms, struct kfd_process, svms); -uint64_t npages = (end - start) >>PAGE_SHIFT ; +u64 npages = (end - start) >>PAGE_SHIFT ;struct amdgpu_device *adev = node->adev;struct kfd_process_device *pdd;struct dma_fence *mfence =NULL ;struct migrate_vma migrate = {0 };unsigned long cpages =0 ; -long mpages =0 ; +unsigned long mpages =0 ;dma_addr_t *scratch;void *buf;int r = -ENOMEM ;
@@ -398,7 +409,7 @@ svm_migrate_vma_to_vram(struct kfd_node *node, struct svm_range *prange, migrate.pgmap_owner =SVM_ADEV_PGMAP_OWNER (adev); buf =kvcalloc (npages, -2 *sizeof (*migrate.src) +sizeof (uint64_t ) +sizeof (dma_addr_t), +2 *sizeof (*migrate.src) +sizeof (u64) +sizeof (dma_addr_t),GFP_KERNEL );if (!buf) goto out;
@@ -431,17 +442,15 @@ svm_migrate_vma_to_vram(struct kfd_node *node, struct svm_range *prange,else pr_debug ("0x%lx pages collected\n" , cpages); - mpages =svm_migrate_copy_to_vram (node, prange, &migrate, &mfence, scratch, ttm_res_offset); + r =svm_migrate_copy_to_vram (node, prange, &migrate, &mfence, scratch, ttm_res_offset);migrate_vma_pages (&migrate);svm_migrate_copy_done (adev, mfence);migrate_vma_finalize (&migrate); -if (mpages >=0 ) -pr_debug ("migrated/collected/requested 0x%lx/0x%lx/0x%lx\n" , - mpages, cpages, migrate.npages); -else - r = mpages; + mpages = cpages -svm_migrate_unsuccessful_pages (&migrate); +pr_debug ("successful/cpages/npages 0x%lx/0x%lx/0x%lx\n" , + mpages, cpages, migrate.npages); kfd_smi_event_migration_end(node, p->lead_thread->pid, start >> PAGE_SHIFT, end >> PAGE_SHIFT,
@@ -452,13 +461,14 @@ svm_migrate_vma_to_vram(struct kfd_node *node, struct svm_range *prange, out_free:kvfree (buf); out: -if (!r && mpages >0 ) { +if (!r && mpages) { pdd =svm_range_get_pdd_by_node (prange, node);if (pdd)WRITE_ONCE (pdd->page_in, pdd->page_in + mpages); - } -return r ? r : mpages; +return mpages; + } +return r; }/**
@@ -482,7 +492,7 @@ svm_migrate_ram_to_vram(struct svm_range *prange, uint32_t best_loc, {unsigned long addr, start, end;struct vm_area_struct *vma; -uint64_t ttm_res_offset; +u64 ttm_res_offset;struct kfd_node *node;unsigned long mpages =0 ;long r =0 ;
@@ -569,18 +579,17 @@ static void svm_migrate_page_free(struct page *page) } } -static long +static int svm_migrate_copy_to_ram (struct amdgpu_device *adev,struct svm_range *prange,struct migrate_vma *migrate,struct dma_fence **mfence, -dma_addr_t *scratch,uint64_t npages) +dma_addr_t *scratch,u64 npages) {struct device *dev = adev->dev; -uint64_t *src; +u64 *src;dma_addr_t *dst;struct page *dpage; -long mpages; -uint64_t i =0 , j; -uint64_t addr; +u64 i =0 , j; +u64 addr;int r =0 ; pr_debug("svms 0x%p [0x%lx 0x%lx]\n", prange->svms, prange->start,
@@ -588,10 +597,9 @@ svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange, addr = migrate->start; - src = (uint64_t *)(scratch + npages); + src = (u64 *)(scratch + npages); dst = scratch; - mpages =0 ;for (i =0 , j =0 ; i < npages; i++, addr +=PAGE_SIZE ) {struct page *spage;
@@ -640,7 +648,6 @@ svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange, dst[i] >> PAGE_SHIFT, page_to_pfn(dpage)); migrate->dst[i] =migrate_pfn (page_to_pfn (dpage)); - mpages++; j++; }
@@ -650,17 +657,13 @@ svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange, out_oom:if (r) {pr_debug ("failed %d copy to ram\n" , r); -while (i-- && mpages) { -if (!migrate->dst[i]) -continue ; +while (i--) {svm_migrate_put_sys_page (dst[i]); migrate->dst[i] =0 ; - mpages--; } - mpages = r; } -return mpages; +return r; }/**
@@ -682,13 +685,14 @@ svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange,*/ static long svm_migrate_vma_to_ram (struct kfd_node *node,struct svm_range *prange, -struct vm_area_struct *vma,uint64_t start,uint64_t end, +struct vm_area_struct *vma,u64 start,u64 end,uint32_t trigger,struct page *fault_page) { struct kfd_process *p = container_of(prange->svms, struct kfd_process, svms); -uint64_t npages = (end - start) >>PAGE_SHIFT ; +u64 npages = (end - start) >>PAGE_SHIFT ; +unsigned long upages = npages;unsigned long cpages =0 ; -long mpages =0 ; +unsigned long mpages =0 ;struct amdgpu_device *adev = node->adev;struct kfd_process_device *pdd;struct dma_fence *mfence =NULL ;
@@ -708,7 +712,7 @@ svm_migrate_vma_to_ram(struct kfd_node *node, struct svm_range *prange, migrate.flags =MIGRATE_VMA_SELECT_DEVICE_PRIVATE ; buf =kvcalloc (npages, -2 *sizeof (*migrate.src) +sizeof (uint64_t ) +sizeof (dma_addr_t), +2 *sizeof (*migrate.src) +sizeof (u64) +sizeof (dma_addr_t),GFP_KERNEL );if (!buf) goto out;
@@ -743,15 +747,13 @@ svm_migrate_vma_to_ram(struct kfd_node *node, struct svm_range *prange,else pr_debug ("0x%lx pages collected\n" , cpages); - mpages =svm_migrate_copy_to_ram (adev, prange, &migrate, &mfence, + r =svm_migrate_copy_to_ram (adev, prange, &migrate, &mfence, scratch, npages);migrate_vma_pages (&migrate); -if (mpages >=0 ) -pr_debug ("migrated/collected/requested 0x%lx/0x%lx/0x%lx\n" , - mpages, cpages, migrate.npages); -else - r = mpages; + upages =svm_migrate_unsuccessful_pages (&migrate); +pr_debug ("unsuccessful/cpages/npages 0x%lx/0x%lx/0x%lx\n" , + upages, cpages, migrate.npages);svm_migrate_copy_done (adev, mfence);migrate_vma_finalize (&migrate);
@@ -765,7 +767,8 @@ svm_migrate_vma_to_ram(struct kfd_node *node, struct svm_range *prange, out_free:kvfree (buf); out: -if (!r && mpages >0 ) { +if (!r && cpages) { + mpages = cpages - upages; pdd =svm_range_get_pdd_by_node (prange, node);if (pdd)WRITE_ONCE (pdd->page_out, pdd->page_out + mpages);
@@ -848,9 +851,6 @@ int svm_migrate_vram_to_ram(struct svm_range *prange, struct mm_struct *mm, }if (r >=0 ) { -WARN_ONCE (prange->vram_pages < mpages, -"Recorded vram pages(0x%llx) should not be less than migration pages(0x%lx)." , - prange->vram_pages, mpages); prange->vram_pages -= mpages;/* prange does not have vram page set its actual_loc to system
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 583/869 drm/amdkfd: Fix the case that vm range is hole at svm_migrate_copy_to_vram
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiaogang Chen <[email protected]>
[ Upstream commit 520e345ffe05aabef1db82beda4288afb1757ff2 ]
When migration vm range is hole at cpu side(MIGRATE_PFN_MIGRATE set + MIGRATE_PFN_VALID unset) driver still allocates device pages. There is no dma map of src pages and migration. j is 0 and svm_migrate_copy_memory_gart() will return an uninitialized r. That can trigger out_free_vram_pages to drop all VRAM just set up.
Initialize r and only call the last svm_migrate_copy_memory_gart if j > 0.
Current code postponed the last page to the final copy. This patch flushes on the last page when reach to the end of current drm_buddy_block; avoids another svm_migrate_copy_memory_gart.
--- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +7 -4
@@ -132,7 +132,7 @@ svm_migrate_copy_memory_gart(struct amdgpu_device *adev, dma_addr_t *sys,u64 gart_s, gart_d;struct dma_fence *next;u64 size; -int r; +int r =0 ;mutex_lock (&adev->mman.gtt_window_lock);
@@ -287,7 +287,7 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange,dma_addr_t *src;u64 *dst;u64 i, j; -int r; +int r =0 ;pr_debug ("svms 0x%p [0x%lx 0x%lx 0x%llx]\n" , prange->svms, prange->start, prange->last, ttm_res_offset);
@@ -313,6 +313,7 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange, DMA_BIDIRECTIONAL); r =dma_mapping_error (dev, src[i]);if (r) { + src[i] =0 ;dev_err (dev,"%s: fail %d dma_map_page\n" , __func__, r); goto out_free_vram_pages;
@@ -337,7 +338,8 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange,pr_debug_ratelimited ("dma mapping src to 0x%llx, pfn 0x%lx\n" , src[i] >>PAGE_SHIFT ,page_to_pfn (spage)); -if (j >= (cursor.size >>PAGE_SHIFT ) -1 && i < npages -1 ) { +/* accumulated j + 1 pages reach end of current drm_buddy_block */ +if (j +1 >= (cursor.size >>PAGE_SHIFT )) { r = svm_migrate_copy_memory_gart(adev, src + i - j, dst + i - j, j + 1, FROM_RAM_TO_VRAM,
@@ -351,7 +353,8 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange, } } - r =svm_migrate_copy_memory_gart (adev, src + i - j, dst + i - j, j, +if (j >0 ) + r =svm_migrate_copy_memory_gart (adev, src + i - j, dst + i - j, j,FROM_RAM_TO_VRAM , mfence); out_free_vram_pages:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 584/869 drm/amdkfd: return migration pages from copy function - again
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Zhu <[email protected]>
[ Upstream commit bd6093e2f1601c0c83906f5115a2efb6b93050b1 ]
dst MIGRATE_PFN_VALID bit and src MIGRATE_PFN_MIGRATE bit should always be set when migration success. cpage includes src MIGRATE_PFN_MIGRATE bit set and MIGRATE_PFN_VALID bit unset pages for both ram and vram when memory is only allocated without being populated before migration, those ram pages should be counted as migrate pages and those vram pages should not be counted as migrate pages. Here migration pages refer to how many vram pages involved.
-v2 use dst to check MIGRATE_PFN_VALID bit (suggested-by Philip) -v3 add warning when vram pages is less than migration pages
return migration pages directly from copy function
-v4 correct comments and copy function return mpage (suggested-by Felix)
[ Dropped the leftover svm_migrate_unsuccessful_pages() call in the
no-collected-pages path of svm_migrate_vma_to_ram(), since the helper and upages no longer exist after this change. ]
[ Kept the forward unwind loop in svm_migrate_copy_to_vram() so the page
at the failing index is released too. ]
Stable-dep-of: 960c4a8069bf ("drm/amdkfd: Fix error path at svm_migrate_copy_to_ram")
--- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 73 ++++++++++++------------ 1 file changed, 36 insertions(+), 37 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +36 -37
@@ -261,20 +261,7 @@ static void svm_migrate_put_sys_page(unsigned long addr)put_page (page); } -static unsigned long svm_migrate_unsuccessful_pages (struct migrate_vma *migrate) -{ -unsigned long upages =0 ; -unsigned long i; - -for (i =0 ; i < migrate->npages; i++) { -if (migrate->src[i] &MIGRATE_PFN_VALID && - !(migrate->src[i] &MIGRATE_PFN_MIGRATE )) - upages++; - } -return upages; -} - -static int +static long svm_migrate_copy_to_vram (struct kfd_node *node,struct svm_range *prange,struct migrate_vma *migrate,struct dma_fence **mfence,dma_addr_t *scratch,u64 ttm_res_offset)
@@ -283,7 +270,7 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange,struct amdgpu_device *adev = node->adev;struct device *dev = adev->dev;struct amdgpu_res_cursor cursor; -u64 mpages =0 ; +long mpages;dma_addr_t *src;u64 *dst;u64 i, j;
@@ -297,6 +284,7 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange,amdgpu_res_first (prange->ttm_res, ttm_res_offset, npages <<PAGE_SHIFT , &cursor); + mpages =0 ;for (i = j =0 ; (i < npages) && (mpages < migrate->cpages); i++) {struct page *spage;
@@ -367,6 +355,7 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange, migrate->dst[i] =0 ; mpages--; } + mpages = r; }#ifdef DEBUG_FORCE_MIXED_DOMAINS
@@ -384,7 +373,7 @@ svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange, }#endif -return r; +return mpages; } static long
@@ -399,7 +388,7 @@ svm_migrate_vma_to_vram(struct kfd_node *node, struct svm_range *prange,struct dma_fence *mfence =NULL ;struct migrate_vma migrate = {0 };unsigned long cpages =0 ; -unsigned long mpages =0 ; +long mpages =0 ;dma_addr_t *scratch;void *buf;int r = -ENOMEM ;
@@ -445,15 +434,17 @@ svm_migrate_vma_to_vram(struct kfd_node *node, struct svm_range *prange,else pr_debug ("0x%lx pages collected\n" , cpages); - r =svm_migrate_copy_to_vram (node, prange, &migrate, &mfence, scratch, ttm_res_offset); + mpages =svm_migrate_copy_to_vram (node, prange, &migrate, &mfence, scratch, ttm_res_offset);migrate_vma_pages (&migrate);svm_migrate_copy_done (adev, mfence);migrate_vma_finalize (&migrate); - mpages = cpages -svm_migrate_unsuccessful_pages (&migrate); -pr_debug ("successful/cpages/npages 0x%lx/0x%lx/0x%lx\n" , - mpages, cpages, migrate.npages); +if (mpages >=0 ) +pr_debug ("migrated/collected/requested 0x%lx/0x%lx/0x%lx\n" , + mpages, cpages, migrate.npages); +else + r = mpages; kfd_smi_event_migration_end(node, p->lead_thread->pid, start >> PAGE_SHIFT, end >> PAGE_SHIFT,
@@ -464,14 +455,13 @@ svm_migrate_vma_to_vram(struct kfd_node *node, struct svm_range *prange, out_free:kvfree (buf); out: -if (!r && mpages) { +if (!r && mpages >0 ) { pdd =svm_range_get_pdd_by_node (prange, node);if (pdd)WRITE_ONCE (pdd->page_in, pdd->page_in + mpages); - -return mpages; } -return r; + +return r ? r : mpages; }/**
@@ -582,7 +572,7 @@ static void svm_migrate_page_free(struct page *page) } } -static int +static long svm_migrate_copy_to_ram (struct amdgpu_device *adev,struct svm_range *prange,struct migrate_vma *migrate,struct dma_fence **mfence,dma_addr_t *scratch,u64 npages)
@@ -591,6 +581,7 @@ svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange,u64 *src;dma_addr_t *dst;struct page *dpage; +long mpages;u64 i =0 , j;u64 addr;int r =0 ;
@@ -603,6 +594,7 @@ svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange, src = (u64 *)(scratch + npages); dst = scratch; + mpages =0 ;for (i =0 , j =0 ; i < npages; i++, addr +=PAGE_SIZE ) {struct page *spage;
@@ -651,6 +643,7 @@ svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange, dst[i] >> PAGE_SHIFT, page_to_pfn(dpage)); migrate->dst[i] =migrate_pfn (page_to_pfn (dpage)); + mpages++; j++; }
@@ -660,13 +653,17 @@ svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange, out_oom:if (r) {pr_debug ("failed %d copy to ram\n" , r); -while (i--) { +while (i-- && mpages) { +if (!migrate->dst[i]) +continue ;svm_migrate_put_sys_page (dst[i]); migrate->dst[i] =0 ; + mpages--; } + mpages = r; } -return r; +return mpages; }/**
@@ -693,9 +690,8 @@ svm_migrate_vma_to_ram(struct kfd_node *node, struct svm_range *prange, { struct kfd_process *p = container_of(prange->svms, struct kfd_process, svms);u64 npages = (end - start) >>PAGE_SHIFT ; -unsigned long upages = npages;unsigned long cpages =0 ; -unsigned long mpages =0 ; +long mpages =0 ;struct amdgpu_device *adev = node->adev;struct kfd_process_device *pdd;struct dma_fence *mfence =NULL ;
@@ -741,7 +737,6 @@ svm_migrate_vma_to_ram(struct kfd_node *node, struct svm_range *prange,if (!cpages) {pr_debug ("failed collect migrate device pages [0x%lx 0x%lx]\n" , prange->start, prange->last); - upages =svm_migrate_unsuccessful_pages (&migrate); goto out_free; }if (cpages != npages)
@@ -750,13 +745,15 @@ svm_migrate_vma_to_ram(struct kfd_node *node, struct svm_range *prange,else pr_debug ("0x%lx pages collected\n" , cpages); - r =svm_migrate_copy_to_ram (adev, prange, &migrate, &mfence, + mpages =svm_migrate_copy_to_ram (adev, prange, &migrate, &mfence, scratch, npages);migrate_vma_pages (&migrate); - upages =svm_migrate_unsuccessful_pages (&migrate); -pr_debug ("unsuccessful/cpages/npages 0x%lx/0x%lx/0x%lx\n" , - upages, cpages, migrate.npages); +if (mpages >=0 ) +pr_debug ("migrated/collected/requested 0x%lx/0x%lx/0x%lx\n" , + mpages, cpages, migrate.npages); +else + r = mpages;svm_migrate_copy_done (adev, mfence);migrate_vma_finalize (&migrate);
@@ -770,8 +767,7 @@ svm_migrate_vma_to_ram(struct kfd_node *node, struct svm_range *prange, out_free:kvfree (buf); out: -if (!r && cpages) { - mpages = cpages - upages; +if (!r && mpages >0 ) { pdd =svm_range_get_pdd_by_node (prange, node);if (pdd)WRITE_ONCE (pdd->page_out, pdd->page_out + mpages);
@@ -854,6 +850,9 @@ int svm_migrate_vram_to_ram(struct svm_range *prange, struct mm_struct *mm, }if (r >=0 ) { +WARN_ONCE (prange->vram_pages < mpages, +"Recorded vram pages(0x%llx) should not be less than migration pages(0x%lx)." , + prange->vram_pages, mpages); prange->vram_pages -= mpages;/* prange does not have vram page set its actual_loc to system
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 585/869 drm/amdkfd: Fix error path at svm_migrate_copy_to_ram
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiaogang Chen <[email protected]>
[ Upstream commit 960c4a8069bfd352c48cc88592618f1ebe24c69e ]
If page migration from device to sys ram fails for some reasons driver needs release and unlock allocated system pages. To do that driver should use page physical address, or pfn, then get struct page*. Current driver uses dma address(for adev) that is not correct with IOMMU enabled, or even in general.
The patch releases and unlocks allocated system pages based on where migration failed by struct page* of sys ram pages. Also dma_unmap correspodent system ram pages at error path.
--- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 47 +++++++++++++++--------- 1 file changed, 30 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +30 -17
@@ -252,15 +252,6 @@ svm_migrate_get_sys_page(struct vm_area_struct *vma, unsigned long addr)return page; } -static void svm_migrate_put_sys_page (unsigned long addr) -{ -struct page *page; - - page =pfn_to_page (addr >>PAGE_SHIFT ); -unlock_page (page); -put_page (page); -} - static long svm_migrate_copy_to_vram(struct kfd_node *node, struct svm_range *prange, struct migrate_vma *migrate, struct dma_fence **mfence,
@@ -578,10 +569,11 @@ svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange, dma_addr_t *scratch, u64 npages) {struct device *dev = adev->dev; -u64 *src; +struct page *dpage =NULL ;dma_addr_t *dst; -struct page *dpage; +u64 *src;long mpages; +u64 i =0 , j;u64 addr;int r =0 ;
@@ -636,6 +628,7 @@ svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange, r =dma_mapping_error (dev, dst[i]);if (r) {dev_err (adev->dev,"%s: fail %d dma_map_page\n" , __func__, r); + dst[i] =0 ; goto out_oom; }
@@ -644,19 +637,39 @@ svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange, migrate->dst[i] =migrate_pfn (page_to_pfn (dpage)); mpages++; + + dpage =NULL ; j++; } - r =svm_migrate_copy_memory_gart (adev, dst + i - j, src + i - j, j, -FROM_VRAM_TO_RAM , mfence); - +if (j >0 ) + r =svm_migrate_copy_memory_gart (adev, dst + i - j, src + i - j, j, +FROM_VRAM_TO_RAM , mfence); out_oom:if (r) {pr_debug ("failed %d copy to ram\n" , r); -while (i-- && mpages) { -if (!migrate->dst[i]) + +/* first release current dpage when dma_map_page fail */ +if (dpage) { +unlock_page (dpage); +put_page (dpage); + } + +/* release previous allocated sys pages and unmap dma address */ +while (i--) { + +if (dst[i]) { +dma_unmap_page (dev, dst[i],PAGE_SIZE , +DMA_BIDIRECTIONAL ); + dst[i] =0 ; + } + + dpage =migrate_pfn_to_page (migrate->dst[i]); +if (!dpage)continue ; -svm_migrate_put_sys_page (dst[i]); + +unlock_page (dpage); +put_page (dpage); migrate->dst[i] =0 ; mpages--; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 586/869 drm/amdkfd: Add TLB flush after MES queue eviction/suspension
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Priya Hosur <[email protected]>
[ Upstream commit 94e25cb6ab7f4f025bcdcd8ea79fda30f12843a4 ]
MES (Micro Engine Scheduler) does not perform heavy-weight TLB invalidation after unmapping queues, unlike HWS which does this automatically. This causes a race condition where in-flight DMA descriptors can access memory that has been unmapped, leading to page faults and GPU queue hangs during SVM page migration.
The issue manifests as KFDSVMRangeTest.MultiThreadMigrationTest failures on gfx1151 (Strix Point) with XNACK mode 1 enabled - the GPU compute queue hangs with packets submitted but never consumed.
Add kfd_flush_tlb() calls after MES queue removal in two locations:
- evict_process_queues_cpsch(): after all queues removed during eviction
- suspend_queues(): after debug/criu queue suspension (with mem_fence barrier)
This ensures all in-flight memory accesses from unmapped queues are flushed before memory is freed or migrated.
--- .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +13 -1
@@ -1222,6 +1222,15 @@ static int evict_process_queues_cpsch(struct device_queue_manager *dqm, } } } + +/* +* Heavy-weight TLB flush after MES removes queues to ensure +* in-flight memory accesses complete before memory is freed/migrated. +* HWS does this automatically, MES does not. +*/ +if (dqm->dev->kfd->shared_resources.enable_mes) +kfd_flush_tlb (pdd); + pdd->last_evict_timestamp =get_jiffies_64 ();if (!dqm->dev->kfd->shared_resources.enable_mes) retval = execute_queues_cpsch(dqm,
@@ -3404,8 +3413,11 @@ int suspend_queues(struct kfd_process *p,if (!per_device_suspended) {dqm_unlock (dqm);mutex_unlock (&p->event_mutex); -if (total_suspended) +if (total_suspended) {amdgpu_amdkfd_debug_mem_fence (dqm->dev->adev); +/* Heavy-weight TLB flush after MES suspends queues */ +kfd_flush_tlb (pdd); + }continue ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 587/869 drm/amdgpu: force complete the MES ring fences on reset
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jesse Zhang <[email protected]>
[ Upstream commit 48dc279c3010ac8f91b1845b2abb3a1e9943a0f5 ]
The MES scheduler ring has no drm scheduler (no_scheduler = true), so it is skipped by the force-completion loop in amdgpu_device_pre_asic_reset(). It uses a polling fence whose hw value lives in wb (GTT) memory and survives a MODE1 reset, while fence_drv.sync_seq keeps advancing for every packet.
When the reset is triggered because MES itself stopped responding, the timed-out packets advance sync_seq past the last hw fence value MES wrote. After resume the first MES submission polls forever on a seq that is never written back, failing the resume and wedging the box on a second reset:
amdgpu: MES ring buffer is full.
amdgpu: *ERROR* ring gfx_0.0.0 test failed (-110)
amdgpu: resume of IP block <gfx_v11_0> failed -110
amdgpu: GPU reset end with ret = -110
Force complete the MES scheduler ring fences together with the scheduler rings so their hw fence is realigned to sync_seq.
v2: cover all XCCs (one scheduler ring each), not just mes.ring[0].
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +13 -0
@@ -5498,6 +5498,19 @@ int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,amdgpu_fence_driver_force_completion (ring, fence); } +/* +* MES scheduler rings have no drm scheduler, so they are missed by the +* loop above. Realign their polling fence too (one per XCC), otherwise the +* first post-reset submission polls forever on a stale seq. sched.ready is +* only set while the driver owns the ring. +*/ +for (i =0 ; i <AMDGPU_MAX_MES_PIPES ; i++) { +struct amdgpu_ring *mes_ring = &adev->mes.ring[i]; + +if (mes_ring->fence_drv.initialized && mes_ring->sched.ready) +amdgpu_fence_driver_force_completion (mes_ring, fence); + } +amdgpu_fence_driver_isr_toggle (adev, false);if (job && job->vm)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 588/869 drm/amdgpu: force complete the KIQ ring fences on reset
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jesse Zhang <[email protected]>
[ Upstream commit fd65d1742992361fc2201ecb4e43411e6e417fcb ]
Like the MES scheduler ring, the KIQ ring sets no_scheduler = true and uses a polling fence, so it is skipped by the force-completion loop in amdgpu_device_pre_asic_reset(). Its hw fence value lives in wb (GTT) memory and survives a MODE1 reset while fence_drv.sync_seq keeps advancing, so after a reset the first KIQ submission can poll forever on a seq that is never written back.
Force complete the KIQ ring fences too so their hw fence is realigned to sync_seq.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +12 -0
@@ -5511,6 +5511,18 @@ int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,amdgpu_fence_driver_force_completion (mes_ring, fence); } +/* +* KIQ rings are polling-fence/no_scheduler like MES, so realign their +* fence too (one ring per XCC), otherwise the first post-reset KIQ +* submission polls forever on a stale seq. +*/ +for (i =0 ; i <AMDGPU_MAX_GC_INSTANCES ; i++) { +struct amdgpu_ring *kiq_ring = &adev->gfx.kiq[i].ring; + +if (kiq_ring->fence_drv.initialized && kiq_ring->sched.ready) +amdgpu_fence_driver_force_completion (kiq_ring, fence); + } +amdgpu_fence_driver_isr_toggle (adev, false);if (job && job->vm)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 589/869 f2fs: fix to avoid potential deadloop in f2fs_fsync_node_pages()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
[ Upstream commit ce366bfa821ec81dd45bde547ee31e659306cc61 ]
There is potential deadloop in race condition:
Thread A Thread B
- fsync
- f2fs_do_sync_file
- f2fs_fsync_node_pages
- last_fsync_dnode
- folio_get(last_folio)
- f2fs_setattr
- f2fs_truncate
- f2fs_truncate_blocks
- f2fs_do_truncate_blocks
- f2fs_truncate_inode_blocks
- truncate_dnode
- truncate_node
- invalidate_mapping_pages
- folio->mapping = NULL
- is_node_folio alwasy return false
- atomic && !marked is always true,
then goto retry
--- fs/f2fs/node.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/f2fs/node.c +5 -0
@@ -1916,6 +1916,11 @@ int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,f2fs_debug (sbi,"Retry to write fsync mark: ino=%u, idx=%lx" , ino,page_folio (last_page)->index);lock_page (last_page); +if (unlikely (last_page->mapping !=NODE_MAPPING (sbi))) { +f2fs_put_page (last_page,1 ); + ret = -EAGAIN ; + goto out; + }f2fs_wait_on_page_writeback (last_page,NODE , true, true);set_page_dirty (last_page);unlock_page (last_page);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 590/869 LoongArch: BPF: Refactor jump offset calculation in tail call
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tiezhu Yang <[email protected]>
[ Upstream commit 37d545d12f21c4d50612ecaebd7ae1e5bf91b2d8 ]
The old macro-based jmp_offset calculation derives the jump distance from a stale prior-pass code stride, which can lead to wrong branch offsets and soft lockups under extra JIT passes.
Fix this by calculating the offset directly on the absolute target:
"ctx->offset[insn + 1] - ctx->idx".
To avoid a false 16-bit range check abort during size estimation, add a "ctx->image == NULL" guard to inject a safe dummy offset.
--- arch/loongarch/net/bpf_jit.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
arch/loongarch/net/bpf_jit.c +4 -8
@@ -210,17 +210,13 @@ bool bpf_jit_supports_far_kfunc_call(void)static int emit_bpf_tail_call (struct jit_ctx *ctx,int insn) { -int off, tc_ninsn =0 ; +int off, jmp_offset;u8 tcc =tail_call_reg (ctx);u8 a1 =LOONGARCH_GPR_A1 ;u8 a2 =LOONGARCH_GPR_A2 ;u8 t1 =LOONGARCH_GPR_T1 ;u8 t2 =LOONGARCH_GPR_T2 ;u8 t3 =LOONGARCH_GPR_T3 ; -const int idx0 = ctx->idx; - -#define cur_offset (ctx->idx - idx0) -#define jmp_offset (tc_ninsn - (cur_offset))/* * a0: &ctx
@@ -230,12 +226,12 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx, int insn)* if (index >= array->map.max_entries) * goto out; */ - tc_ninsn = insn ? ctx->offset[insn+1 ] - ctx->offset[insn] : ctx->offset[0 ];emit_zext_32 (ctx, a2, true); off = offsetof(struct bpf_array, map.max_entries);emit_insn (ctx, ldwu, t1, a1, off);/* bgeu $a2, $t1, jmp_offset */ + jmp_offset = ctx->image ? (ctx->offset[insn +1 ] - ctx->idx) :0 ;if (emit_tailcall_jmp (ctx,BPF_JGE , a2, t1, jmp_offset) <0 ) goto toofar;
@@ -244,6 +240,7 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx, int insn)* goto out; */ emit_insn (ctx, addid,REG_TCC , tcc,-1 ); + jmp_offset = ctx->image ? (ctx->offset[insn +1 ] - ctx->idx) :0 ;if (emit_tailcall_jmp (ctx,BPF_JSLT ,REG_TCC ,LOONGARCH_GPR_ZERO , jmp_offset) <0 ) goto toofar;
@@ -256,6 +253,7 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx, int insn) off = offsetof(struct bpf_array , ptrs);emit_insn (ctx, ldd, t2, t2, off);/* beq $t2, $zero, jmp_offset */ + jmp_offset = ctx->image ? (ctx->offset[insn +1 ] - ctx->idx) :0 ;if (emit_tailcall_jmp (ctx,BPF_JEQ , t2,LOONGARCH_GPR_ZERO , jmp_offset) <0 ) goto toofar;
@@ -269,8 +267,6 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx, int insn) toofar:pr_info_once ("tail_call: jump too far\n" );return -1 ; -#undef cur_offset -#undef jmp_offset }static void emit_atomic (const struct bpf_insn *insn,struct jit_ctx *ctx)
Signature · 1 line
2.53.0
Re: [PATCH 6.12 590/869] LoongArch: BPF: Refactor jump offset calculation in tail call
Hi, Greg and Sasha,
Quoted 8 lines
-----原始邮件-----
发件人: "Greg Kroah-Hartman" <[email protected]>
发送时间:2026-10-17 23:57:11 (星期六)
收件人: [email protected]
抄送: "Greg Kroah-Hartman" <[email protected]>, [email protected], "Tiezhu Yang" <[email protected]>, "Huacai Chen" <[email protected]>, "Sasha Levin" <[email protected]> 主题: [PATCH 6.12 590/869] LoongArch: BPF: Refactor jump offset calculation in tail call6.12-stable review patch. If anyone has any objections, please let me know.
6.6/6.12 doesn't need this patch, I have already point out.
https://marc.info/?l=linux-stable-commits&m=179222528850661&w=2
https://marc.info/?l=linux-stable-commits&m=179222522850616&w=2
Huacai
Quoted 92 lines
------------------
From: Tiezhu Yang <[email protected]>
[ Upstream commit
37d545d12f21c4d50612ecaebd7ae1e5bf91b2d8]The old macro-based
jmp_offsetcalculation derives the jump distance from a stale prior-pass code stride, which can lead to wrong branch offsets and soft lockups under extra JIT passes.Fix this by calculating the offset directly on the absolute target:
"ctx->offset[insn + 1] -ctx->idx".To avoid a false 16-bit range check abort during size estimation, add a "
ctx->image== NULL" guard to inject a safe dummy offset.Fixes cd39d9e6b7e4 ("LoongArch: BPF: Fix jump offset calculation in tailcall")Signed-off-by Tiezhu Yang <[email protected]>Signed-off-by Huacai Chen <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- arch/loongarch/net/bpf_jit.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)arch/loongarch/net/bpf_jit.c +4
-8@@ -210,17 +210,13 @@ bool bpf_jit_supports_far_kfunc_call(void)static int emit_bpf_tail_call (struct jit_ctx *ctx,int insn) { -int off, tc_ninsn =0 ; +int off, jmp_offset;u8 tcc =tail_call_reg (ctx);u8 a1 =LOONGARCH_GPR_A1 ;u8 a2 =LOONGARCH_GPR_A2 ;u8 t1 =LOONGARCH_GPR_T1 ;u8 t2 =LOONGARCH_GPR_T2 ;u8 t3 =LOONGARCH_GPR_T3 ; -const int idx0 = ctx->idx; - -#define cur_offset (ctx->idx - idx0) -#define jmp_offset (tc_ninsn - (cur_offset))/* * a0: &ctx @@ -230,12 +226,12 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx, int insn)* if (index >= array->map.max_entries) * goto out; */ - tc_ninsn = insn ? ctx->offset[insn+1 ] - ctx->offset[insn] : ctx->offset[0 ];emit_zext_32 (ctx, a2, true); off = offsetof(struct bpf_array, map.max_entries);emit_insn (ctx, ldwu, t1, a1, off);/* bgeu $a2, $t1, jmp_offset */ + jmp_offset = ctx->image ? (ctx->offset[insn +1 ] - ctx->idx) :0 ;if (emit_tailcall_jmp (ctx,BPF_JGE , a2, t1, jmp_offset) <0 ) goto toofar;@@ -244,6 +240,7 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx, int insn)* goto out; */ emit_insn (ctx, addid,REG_TCC , tcc,-1 ); + jmp_offset = ctx->image ? (ctx->offset[insn +1 ] - ctx->idx) :0 ;if (emit_tailcall_jmp (ctx,BPF_JSLT ,REG_TCC ,LOONGARCH_GPR_ZERO , jmp_offset) <0 ) goto toofar;@@ -256,6 +253,7 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx, int insn) off = offsetof(struct bpf_array , ptrs);emit_insn (ctx, ldd, t2, t2, off);/* beq $t2, $zero, jmp_offset */ + jmp_offset = ctx->image ? (ctx->offset[insn +1 ] - ctx->idx) :0 ;if (emit_tailcall_jmp (ctx,BPF_JEQ , t2,LOONGARCH_GPR_ZERO , jmp_offset) <0 ) goto toofar;@@ -269,8 +267,6 @@ static int emit_bpf_tail_call(struct jit_ctx *ctx, int insn) toofar:pr_info_once ("tail_call: jump too far\n" );return -1 ; -#undef cur_offset -#undef jmp_offset }static void emit_atomic (const struct bpf_insn *insn,struct jit_ctx *ctx)Signature · 1 line
2.53.0
本邮件及其附件含有龙芯中科的商业秘密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制或散发)本邮件及其附件中的信息。如果您错收本邮件,请您立即电话或邮件通知发件人并删除本邮件。
This email and its attachments contain confidential information from Loongson Technology , which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this email in error, please notify the sender by phone or email immediately and delete it.
Sasha Levin
maintainerRe: [PATCH 6.12 590/869] LoongArch: BPF: Refactor jump offset calculation in tail call
Quoted 1 line · Huacai Chen
6.6/6.12 doesn't need this patch, I have already point out.
Thanks. I am keeping 37d545d12f21 in the 6.12 and 6.6 queues, because the commit it fixes, cd39d9e6b7e4 ("LoongArch: BPF: Fix jump offset calculation in tailcall"), is in both trees: f83d469e16bb in v6.12.43 and 17c010fe45de in v6.6.103. The emit_bpf_tail_call() in the stable trees still has the tc_ninsn/cur_offset/jmp_offset macros that the patch removes, and the CVE-2026-89906 announcement lists those releases as where the issue was introduced, with no fix yet.
Signature · 2 lines
Thanks, Sasha
Greg Kroah-Hartman
maintainerPATCH 591/869 KVM: arm64: vgic-v3: take an LPI reference in vgic_v3_save_pending_tables
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qihang <[email protected]>
[ Upstream commit f5b8f203bfc07a5a257dff859e66d2c500f9f509 ]
vgic_v3_save_pending_tables() iterates dist->lpi_xa using xa_for_each() and dereferences the returned struct vgic_irq in the loop body without holding a reference on the LPI.
The xarray iterator only provides temporary RCU coverage while looking up the current entry. That is not sufficient for this loop body, which reads fields from struct vgic_irq and performs guest memory accesses before the iteration completes.
A concurrent path can trigger this race: the irqfd cached injection path (vgic_its_inject_cached_translation) obtains a transient LPI reference via vgic_its_check_cache() without holding kvm->lock, vcpu->mutex, config_lock, or its_lock. If guest ITS DISCARD then drops the cache and ITE references under its_lock, the transient inject reference may become the final one. When vgic_put_irq() drops it, the LPI is erased from lpi_xa and freed via kfree_rcu(). Meanwhile, vgic_v3_save_pending_tables() may still hold a stale pointer obtained from the xarray iterator and dereference it after the RCU grace period completes.
Fix this by re-fetching each iterated LPI via vgic_get_irq(), which takes a stable reference, and dropping it with vgic_put_irq() on all paths. This matches the pattern already used by other lpi_xa iterators in the vgic ITS code.
--- arch/arm64/kvm/vgic/vgic-v3.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
arch/arm64/kvm/vgic/vgic-v3.c +9 -3
@@ -416,9 +416,13 @@ int vgic_v3_save_pending_tables(struct kvm *kvm)bool is_pending;bool stored; + irq =vgic_get_irq (kvm,NULL , index); +if (!irq) +continue ; + vcpu = irq->target_vcpu;if (!vcpu) -continue ; + goto put_irq; pendbase =GICR_PENDBASER_ADDRESS (vcpu->arch.vgic_cpu.pendbaser);
@@ -429,7 +433,7 @@ int vgic_v3_save_pending_tables(struct kvm *kvm)if (ptr != last_ptr) { ret =kvm_read_guest_lock (kvm, ptr, &val,1 );if (ret) - goto out; + goto put_irq; last_ptr = ptr; }
@@ -441,7 +445,7 @@ int vgic_v3_save_pending_tables(struct kvm *kvm)vgic_v4_get_vlpi_state (irq, &is_pending);if (stored == is_pending) -continue ; + goto put_irq;if (is_pending) val |=1 << bit_nr;
@@ -449,6 +453,8 @@ int vgic_v3_save_pending_tables(struct kvm *kvm) val &= ~(1 << bit_nr); ret =vgic_write_guest_lock (kvm, ptr, &val,1 ); +put_irq: +vgic_put_irq (kvm, irq);if (ret) goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 592/869 KVM: s390: Fix memory corruption by not reinjecting CK machine checks
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Borntraeger <[email protected]>
[ Upstream commit 546dde823a36d7283dcf46127c2f3d093443860f ]
Channel-subsystem damage machine checks are for the host channel subsystem. The guest channel subsystem is emulated in the userspace VMM. There is no point in forwarding such machine checks into the guest.
This also simplifies the machine check reinjection and avoids kfree of a stack variable as reported by sashiko. There might be still machine checks that have the ck bit set with another bit (like instruction damage), mask out the CK bit in s390_backup_mcck_info(), like the CP and ED bits already are.
Message-ID: <[email protected]>
--- arch/s390/include/asm/nmi.h | 3 +++ arch/s390/kernel/nmi.c | 5 +---- arch/s390/kvm/interrupt.c | 24 ++++++++---------------- 3 files changed, 12 insertions(+), 20 deletions(-)
arch/s390/include/asm/nmi.h +3 -0
@@ -22,6 +22,7 @@#define MCCK_CODE_SYSTEM_DAMAGE BIT(63)#define MCCK_CODE_EXT_DAMAGE BIT(63 - 5)#define MCCK_CODE_CP BIT(63 - 9) +#define MCCK_CODE_CK BIT(63 - 11)#define MCCK_CODE_STG_ERROR BIT(63 - 16)#define MCCK_CODE_STG_KEY_ERROR BIT(63 - 18)#define MCCK_CODE_STG_DEGRAD BIT(63 - 19)
@@ -33,6 +34,8 @@#define MCCK_CODE_FC_VALID BIT(63 - 43)#define MCCK_CODE_CPU_TIMER_VALID BIT(63 - 46) +#define MCCK_CODE_NO_GUEST (MCCK_CODE_CP | MCCK_CODE_EXT_DAMAGE | MCCK_CODE_CK) +#ifndef __ASSEMBLY__ union mci {
arch/s390/kernel/nmi.c +1 -4
@@ -279,8 +279,7 @@ static void notrace s390_backup_mcck_info(struct pt_regs *regs) sie_page = container_of(sie_block, struct sie_page, sie_block); mcck_backup = &sie_page->mcck_info; - mcck_backup->mcic =get_lowcore ()->mcck_interruption_code & - ~(MCCK_CODE_CP |MCCK_CODE_EXT_DAMAGE ); + mcck_backup->mcic =get_lowcore ()->mcck_interruption_code & ~MCCK_CODE_NO_GUEST ; mcck_backup->ext_damage_code =get_lowcore ()->external_damage_code; mcck_backup->failing_storage_address =get_lowcore ()->failing_storage_address; }
@@ -292,8 +291,6 @@ NOKPROBE_SYMBOL(s390_backup_mcck_info);#define ED_STP_ISLAND 6/* External damage STP island check */ #define ED_STP_SYNC 7/* External damage STP sync check */ -#define MCCK_CODE_NO_GUEST (MCCK_CODE_CP | MCCK_CODE_EXT_DAMAGE) -/* * machine check handler. */
arch/s390/kvm/interrupt.c +8 -16
@@ -2865,9 +2865,7 @@ static int set_adapter_int(struct kvm_kernel_irq_routing_entry *e,void kvm_s390_reinject_machine_check (struct kvm_vcpu *vcpu,struct mcck_volatile_info *mcck_info) { -struct kvm_s390_interrupt_info inti;struct kvm_s390_irq irq = {}; -struct kvm_s390_mchk_info *mchk;union mci mci;__u64 cr14 =0 ;/* upper bits are not used */ int rc;
@@ -2880,20 +2878,14 @@ void kvm_s390_reinject_machine_check(struct kvm_vcpu *vcpu,if (mci.w) cr14 |=CR14_WARNING_SUBMASK ; - mchk = mci.ck ? &inti.mchk : &irq.u.mchk; - mchk->cr14 = cr14; - mchk->mcic = mcck_info->mcic; - mchk->ext_damage_code = mcck_info->ext_damage_code; - mchk->failing_storage_address = mcck_info->failing_storage_address; -if (mci.ck) { -/* Inject the floating machine check */ - inti.type =KVM_S390_MCHK ; - rc =__inject_vm (vcpu->kvm, &inti); - }else { -/* Inject the machine check to specified vcpu */ - irq.type =KVM_S390_MCHK ; - rc =kvm_s390_inject_vcpu (vcpu, &irq); - } + irq.u.mchk.cr14 = cr14; + irq.u.mchk.mcic = mcck_info->mcic; + irq.u.mchk.ext_damage_code = mcck_info->ext_damage_code; + irq.u.mchk.failing_storage_address = mcck_info->failing_storage_address; + +/* Inject the machine check to specified vcpu */ + irq.type =KVM_S390_MCHK ; + rc =kvm_s390_inject_vcpu (vcpu, &irq);WARN_ON_ONCE (rc); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 593/869 mm/huge_memory: transfer the pmd dirty bit to the folio on zap
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Usama Arif <[email protected]>
[ Upstream commit fe6cf984939d8e12cb33a99673c8d026c5135e68 ]
zap_huge_pmd_folio() propagates the pmd young bit to the folio for the file case, but not the dirty bit. The pte path does propagate it, in zap_present_folio_ptes() and so does the pmd split path, in __split_huge_pmd_locked().
For most file mappings the omission is harmless, because writing to a shared file mapping goes through page_mkwrite(), which dirties the folio. tmpfs is different: it has no page_mkwrite(), and vma_wants_writenotify() is false for it, so a *read* fault on a MAP_SHARED tmpfs mapping installs a writable pmd via do_read_fault(). do_read_fault() does not call fault_dirty_shared_page(), so subsequent stores through that mapping set only the hardware dirty bit in the pmd and never call folio_mark_dirty(). A shmem folio allocated by a fault is marked uptodate but not dirty (see the clear: block in shmem_get_folio_gfp()), so PG_dirty is never set at all.
Unmapping such a folio - munmap(), or exit_mmap() when the process dies - then loses the only record that it was written, because zap_huge_pmd() drops the pmd without transferring the dirty bit. Reclaim afterwards sees a clean shmem folio: the whole swap-out block in shrink_folio_list() is inside "if (folio_test_dirty(folio))", so pageout() is skipped and the folio falls into __remove_mapping(). There, folio_is_file_lru() is false for a swapbacked folio, so no shadow entry is created and __filemap_remove_folio(folio, NULL) simply empties the i_pages slot. The data is freed without ever being written to swap, and the next fault on that index returns a freshly zeroed folio.
This is silent data loss for any process that keeps state in a MAP_SHARED tmpfs segment across an unmap - for example a cache handed from one process generation to the next through /dev/shm. It requires the folio to be PMD-mapped, so it only shows up once shmem THP is enabled (which is what we did in Meta fleet and started noticing crashes); with THP off the pte path transfers the dirty bit correctly. It also only becomes visible when swap is enabled, because with no swap device shmem folios (which are on the anon LRU) are not scanned by reclaim at all, so the clean folio is never dropped.
Reproduced on x86_64 with a tmpfs mounted huge=within_size: read-fault a 2MB-backed region, write a known pattern through the resulting mapping, munmap, force reclaim of the cgroup, then re-map and read back. Without this patch the region reads back as zeros and vmstat shows zswpout 0 - the data was discarded rather than swapped. With this patch the region reads back correctly and the pages are swapped out as expected. With huge=never, or when the first touch is a write, the test passes either way.
shared file mapping goes through page_mkwrite(), which dirties the folio. tmpfs is different: it has no page_mkwrite(), and vma_wants_writenotify() is false for it, so a *read* fault on a MAP_SHARED tmpfs mapping installs a writable pmd via do_read_fault(). do_read_fault() does not call fault_dirty_shared_page(), so subsequent stores through that mapping set only the hardware dirty bit in the pmd and never call folio_mark_dirty().
--- mm/huge_memory.c | 3 +++ 1 file changed, 3 insertions(+)
mm/huge_memory.c +3 -0
@@ -2112,6 +2112,9 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,zap_deposited_table (tlb->mm, pmd);add_mm_counter (tlb->mm,mm_counter_file (folio), -HPAGE_PMD_NR ); + +if (pmd_present (orig_pmd) &&pmd_dirty (orig_pmd)) +folio_mark_dirty (folio); }spin_unlock (ptl);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 594/869 netfilter: nf_tables: prefer nft_trans_elem_alloc helper
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 08e52cccae11a4148a5810f0bd5614796994d221 ]
Reduce references to sizeof(struct nft_trans_elem). Preparation patch to move this to a flexiable array to store elem references.
Stable-dep-of: 43559058d21e ("netfilter: nf_tables: skip double clone set expressions on element insert")
--- net/netfilter/nf_tables_api.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
net/netfilter/nf_tables_api.c +2 -4
@@ -6357,7 +6357,7 @@ static void nf_tables_setelem_notify(const struct nft_ctx *ctx,nfnetlink_set_err (net, portid,NFNLGRP_NFTABLES , -ENOBUFS ); } -static struct nft_trans *nft_trans_elem_alloc (struct nft_ctx *ctx, +static struct nft_trans *nft_trans_elem_alloc (const struct nft_ctx *ctx,int msg_type,struct nft_set *set) {
@@ -7453,13 +7453,11 @@ static int __nft_set_catchall_flush(const struct nft_ctx *ctx, {struct nft_trans *trans; - trans =nft_trans_alloc_gfp (ctx,NFT_MSG_DELSETELEM , -sizeof (struct nft_trans_elem ),GFP_KERNEL ); + trans =nft_trans_elem_alloc (ctx,NFT_MSG_DELSETELEM , set);if (!trans)return -ENOMEM ;nft_setelem_data_deactivate (ctx->net, set, elem_priv); -nft_trans_elem_set (trans) = set;nft_trans_elem_priv (trans) = elem_priv;nft_trans_commit_list_add_tail (ctx->net, trans);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 595/869 netfilter: nf_tables: add nft_trans_commit_list_add_elem helper
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 4ee29181216d2acb7be210126324ec3bc0e3bd01 ]
Add and use a wrapper to append trans_elem structures to the transaction log.
Unlike the existing helper, pass a gfp_t to indicate if sleeping is allowed.
This will be used by a followup patch to realloc nft_trans_elem structures after they gain a flexible array member to reduce number of such container structures on the transaction list.
Stable-dep-of: 43559058d21e ("netfilter: nf_tables: skip double clone set expressions on element insert")
--- net/netfilter/nf_tables_api.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
net/netfilter/nf_tables_api.c +16 -5
@@ -440,6 +440,17 @@ static void nft_trans_commit_list_add_tail(struct net *net, struct nft_trans *tr } } +static void nft_trans_commit_list_add_elem (struct net *net,struct nft_trans *trans, +gfp_t gfp) +{ +WARN_ON_ONCE (trans->msg_type !=NFT_MSG_NEWSETELEM && + trans->msg_type !=NFT_MSG_DELSETELEM ); + +might_alloc (gfp); + +nft_trans_commit_list_add_tail (net, trans); +} +static int nft_trans_table_add (struct nft_ctx *ctx,int msg_type) {struct nft_trans *trans;
@@ -7167,7 +7178,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,if (update_flags) {nft_trans_elem_priv (trans) = elem_priv;nft_trans_elem_update_flags (trans) = update_flags; -nft_trans_commit_list_add_tail (ctx->net, trans); +nft_trans_commit_list_add_elem (ctx->net, trans,GFP_KERNEL ); goto err_set_size; } }
@@ -7187,7 +7198,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set, }nft_trans_elem_priv (trans) = elem.priv; -nft_trans_commit_list_add_tail (ctx->net, trans); +nft_trans_commit_list_add_elem (ctx->net, trans,GFP_KERNEL );return set_full ? -ENFILE :0 ;
@@ -7406,7 +7417,7 @@ static int nft_del_setelem(struct nft_ctx *ctx, struct nft_set *set,nft_setelem_data_deactivate (ctx->net, set, elem.priv);nft_trans_elem_priv (trans) = elem.priv; -nft_trans_commit_list_add_tail (ctx->net, trans); +nft_trans_commit_list_add_elem (ctx->net, trans,GFP_KERNEL );return 0 ; fail_ops:
@@ -7442,7 +7453,7 @@ static int nft_setelem_flush(const struct nft_ctx *ctx,nft_setelem_data_deactivate (ctx->net, set, elem_priv);nft_trans_elem_set (trans) = set;nft_trans_elem_priv (trans) = elem_priv; -nft_trans_commit_list_add_tail (ctx->net, trans); +nft_trans_commit_list_add_elem (ctx->net, trans,GFP_ATOMIC );return 0 ; }
@@ -7459,7 +7470,7 @@ static int __nft_set_catchall_flush(const struct nft_ctx *ctx,nft_setelem_data_deactivate (ctx->net, set, elem_priv);nft_trans_elem_priv (trans) = elem_priv; -nft_trans_commit_list_add_tail (ctx->net, trans); +nft_trans_commit_list_add_elem (ctx->net, trans,GFP_KERNEL );return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 596/869 netfilter: nf_tables: prepare for multiple elements in nft_trans_elem structure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit a8ee6b900c147d3bedced6c52ba6cb603226aaa3 ]
Add helpers to release the individual elements contained in the trans_elem container structure.
No functional change intended.
Followup patch will add 'nelems' member and will turn 'priv' into a flexible array.
These helpers can then loop over all elements.
Care needs to be taken to handle a mix of new elements and existing elements that are being updated (e.g. timeout refresh).
Before this patch, NEWSETELEM transaction with update is released early so nft_trans_set_elem_destroy() won't get called, so we need to skip elements marked as update.
Stable-dep-of: 43559058d21e ("netfilter: nf_tables: skip double clone set expressions on element insert")
--- include/net/netfilter/nf_tables.h | 21 ++- net/netfilter/nf_tables_api.c | 228 +++++++++++++++++++++--------- 2 files changed, 173 insertions(+), 76 deletions(-)
include/net/netfilter/nf_tables.h +9 -12
@@ -1774,28 +1774,25 @@ enum nft_trans_elem_flags { NFT_TRANS_UPD_EXPIRATION = (1 << 1), }; -struct nft_trans_elem { -struct nft_trans nft_trans; -struct nft_set *set; -struct nft_elem_priv *elem_priv; +struct nft_trans_one_elem { +struct nft_elem_priv *priv;u64 timeout;u64 expiration;u8 update_flags; +}; + +struct nft_trans_elem { +struct nft_trans nft_trans; +struct nft_set *set;bool bound; +unsigned int nelems; + struct nft_trans_one_elem elems[] __counted_by(nelems); };#define nft_trans_container_elem (t) \ container_of(t, struct nft_trans_elem, nft_trans)#define nft_trans_elem_set (trans) \ nft_trans_container_elem(trans)->set -#define nft_trans_elem_priv (trans) \ - nft_trans_container_elem(trans)->elem_priv -#define nft_trans_elem_update_flags (trans) \ - nft_trans_container_elem(trans)->update_flags -#define nft_trans_elem_timeout (trans) \ - nft_trans_container_elem(trans)->timeout -#define nft_trans_elem_expiration (trans) \ - nft_trans_container_elem(trans)->expiration#define nft_trans_elem_set_bound (trans) \ nft_trans_container_elem(trans)->bound
net/netfilter/nf_tables_api.c +164 -64
372 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 597/869 netfilter: nf_tables: skip double clone set expressions on element insert
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit 43559058d21e0493aa220ac167e0279334dea5f9 ]
Both the dynset and newsetelem path clone the existing set expressions when setting set element expressions if no override expressions are provided. This results in a double clone, once to clone the template set expressions then another clone on the new element. Add a flag to annotate if userspace provides a override expression (ie. expression of the same type of the set but different configuration), otherwise borrow the existing expression from the set. Add conditionals to release expression iif they represent an override. Use this new override_exprs flag to dump the dynset expression override to userspace.
This simplifies the existing logic and it also fixes a bug with the connlimit expression which results in a module refcount imbalance WARNING splat when resorting on the default set expressions.
--- include/net/netfilter/nf_tables.h | 2 -- net/netfilter/nf_tables_api.c | 56 ++++++++++--------------------- net/netfilter/nft_dynset.c | 25 ++++++++------ 3 files changed, 33 insertions(+), 50 deletions(-)
include/net/netfilter/nf_tables.h +0 -2
@@ -867,8 +867,6 @@ struct nft_elem_priv *nft_set_elem_init(const struct nft_set *set, const u32 *key, const u32 *key_end, const u32 *data, u64 timeout, u64 expiration, gfp_t gfp); -int nft_set_elem_expr_clone (const struct nft_ctx *ctx,struct nft_set *set, -struct nft_expr *expr_array[]);void nft_set_elem_expr_destroy (const struct nft_ctx *ctx,struct nft_set_elem_expr *elem_expr); void nft_set_elem_destroy(const struct nft_set *set,
net/netfilter/nf_tables_api.c +18 -38
114 lines not on this page · raw message
net/netfilter/nft_dynset.c +15 -10
@@ -19,7 +19,8 @@ struct nft_dynset {u8 sreg_key;u8 sreg_data;bool invert; -bool expr; + bool expr:1, + override_exprs:1;u8 num_exprs;u64 timeout;struct nft_expr *expr_array[NFT_SET_EXPR_MAX ];
@@ -257,6 +258,7 @@ static int nft_dynset_init(const struct nft_ctx *ctx, priv->num_exprs++; priv->expr_array[0 ] = dynset_expr; + priv->override_exprs = true; if (set->num_exprs > 1 || (set->num_exprs == 1 &&
@@ -289,6 +291,7 @@ static int nft_dynset_init(const struct nft_ctx *ctx, } priv->expr_array[i] = dynset_expr; priv->num_exprs++; + priv->override_exprs = true;if (set->num_exprs) {if (i >= set->num_exprs) {
@@ -307,9 +310,8 @@ static int nft_dynset_init(const struct nft_ctx *ctx, goto err_expr_free; } }else if (set->num_exprs >0 ) { - err =nft_set_elem_expr_clone (ctx, set, priv->expr_array); -if (err <0 ) -return err; +for (i =0 ; i < set->num_exprs; i++) + priv->expr_array[i] = set->exprs[i]; priv->num_exprs = set->num_exprs; }
@@ -339,8 +341,10 @@ static int nft_dynset_init(const struct nft_ctx *ctx,return 0 ; err_expr_free: -for (i =0 ; i < priv->num_exprs; i++) -nft_expr_destroy (ctx, priv->expr_array[i]); +if (priv->override_exprs) { +for (i =0 ; i < priv->num_exprs; i++) +nft_expr_destroy (ctx, priv->expr_array[i]); + }return err; }
@@ -367,9 +371,10 @@ static void nft_dynset_destroy(const struct nft_ctx *ctx,struct nft_dynset *priv =nft_expr_priv (expr);int i; -for (i =0 ; i < priv->num_exprs; i++) -nft_expr_destroy (ctx, priv->expr_array[i]); - +if (priv->override_exprs) { +for (i =0 ; i < priv->num_exprs; i++) +nft_expr_destroy (ctx, priv->expr_array[i]); + }nf_tables_destroy_set (ctx, priv->set); }
@@ -393,7 +398,7 @@ static int nft_dynset_dump(struct sk_buff *skb, nf_jiffies64_to_msecs(priv->timeout), NFTA_DYNSET_PAD)) goto nla_put_failure; -if (priv->set->num_exprs ==0 ) { +if (priv->set->num_exprs ==0 || priv->override_exprs) {if (priv->num_exprs ==1 ) {if (nft_expr_dump (skb,NFTA_DYNSET_EXPR , priv->expr_array[0 ], reset))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 598/869 net_sched: sch_fq: add three drop_reason
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 5765c7f6e3173eb894889a29963a497aeb721c5e ]
Add three new drop_reason, more precise than generic QDISC_DROP:
"tc -s qd" show aggregate counters, it might be more useful to use drop_reason infrastructure for bug hunting.
1) SKB_DROP_REASON_FQ_BAND_LIMIT
Whenever a packet is added while its band limit is hit. Corresponding value in "tc -s qd" is bandX_drops XXXX
2) SKB_DROP_REASON_FQ_HORIZON_LIMIT
Whenever a packet has a timestamp too far in the future. Corresponding value in "tc -s qd" is horizon_drops XXXX
3) SKB_DROP_REASON_FQ_FLOW_LIMIT
Whenever a flow has reached its limit. Corresponding value in "tc -s qd" is flows_plimit XXXX
Tested:
tc qd replace dev eth1 root fq flow_limit 10 limit 100000 perf record -a -e skb:kfree_skb sleep 1; perf script
udp_stream 12329 [004] 216.929492: skb:kfree_skb: skbaddr=0xffff888eabe17e00 rx_sk=(nil) protocol=34525 location=__dev_queue_xmit+0x9d9 reason: FQ_FLOW_LIMIT
udp_stream 12385 [006] 216.929593: skb:kfree_skb: skbaddr=0xffff888ef8827f00 rx_sk=(nil) protocol=34525 location=__dev_queue_xmit+0x9d9 reason: FQ_FLOW_LIMIT
udp_stream 12389 [005] 216.929871: skb:kfree_skb: skbaddr=0xffff888ecb9ba500 rx_sk=(nil) protocol=34525 location=__dev_queue_xmit+0x9d9 reason: FQ_FLOW_LIMIT
udp_stream 12316 [009] 216.930398: skb:kfree_skb: skbaddr=0xffff888eca286b00 rx_sk=(nil) protocol=34525 location=__dev_queue_xmit+0x9d9 reason: FQ_FLOW_LIMIT
udp_stream 12400 [008] 216.930490: skb:kfree_skb: skbaddr=0xffff888eabf93d00 rx_sk=(nil) protocol=34525 location=__dev_queue_xmit+0x9d9 reason: FQ_FLOW_LIMITtc qd replace dev eth1 root fq flow_limit 100 limit 10000 perf record -a -e skb:kfree_skb sleep 1; perf script
udp_stream 18074 [001] 1058.318040: skb:kfree_skb: skbaddr=0xffffa23c881fc000 rx_sk=(nil) protocol=34525 location=__dev_queue_xmit+0x9d9 reason: FQ_BAND_LIMIT
udp_stream 18126 [005] 1058.320651: skb:kfree_skb: skbaddr=0xffffa23c6aad4000 rx_sk=(nil) protocol=34525 location=__dev_queue_xmit+0x9d9 reason: FQ_BAND_LIMIT
udp_stream 18118 [006] 1058.321065: skb:kfree_skb: skbaddr=0xffffa23df0d48a00 rx_sk=(nil) protocol=34525 location=__dev_queue_xmit+0x9d9 reason: FQ_BAND_LIMIT
udp_stream 18074 [001] 1058.321126: skb:kfree_skb: skbaddr=0xffffa23c881ffa00 rx_sk=(nil) protocol=34525 location=__dev_queue_xmit+0x9d9 reason: FQ_BAND_LIMIT
udp_stream 15815 [003] 1058.321224: skb:kfree_skb: skbaddr=0xffffa23c9835db00 rx_sk=(nil) protocol=34525 location=__dev_queue_xmit+0x9d9 reason: FQ_BAND_LIMITtc -s -d qd sh dev eth1
qdisc fq 8023: root refcnt 257 limit 10000p flow_limit 100p buckets 1024 orphan_mask 1023
bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1 weights 589824 196608 65536 quantum 18Kb initial_quantum 92120b low_rate_threshold 550Kbit refill_delay 40ms timer_slack 10us horizon 10s horizon_drop
Sent 492439603330 bytes 336953991 pkt (dropped 61724094, overlimits 0 requeues 4463) backlog 14611228b 9995p requeues 4463
flows 2965 (inactive 1151 throttled 0) band0_pkts 0 band1_pkts 9993 band2_pkts 0 gc 6347 highprio 0 fastpath 30 throttled 5 latency 2.32us flows_plimit 7403693
band1_drops 54320401
Stable-dep-of: 5b483f7791b0 ("net/sched: act_ife: Only operate on Ethernet frames")
--- include/net/dropreason-core.h | 18 ++++++++++++++++++ include/net/sch_generic.h | 8 ++++++++ net/sched/sch_fq.c | 14 ++++++++++---- 3 files changed, 36 insertions(+), 4 deletions(-)
include/net/dropreason-core.h +18 -0
@@ -60,6 +60,9 @@ FN(TC_EGRESS) \ FN(SECURITY_HOOK) \ FN(QDISC_DROP) \ + FN(FQ_BAND_LIMIT) \ + FN(FQ_HORIZON_LIMIT) \ + FN(FQ_FLOW_LIMIT) \ FN(CPU_BACKLOG) \ FN(XDP) \ FN(TC_INGRESS) \
@@ -316,6 +319,21 @@ enum skb_drop_reason {* failed to enqueue to current qdisc) */ SKB_DROP_REASON_QDISC_DROP , +/** +* @SKB_DROP_REASON_FQ_BAND_LIMIT: dropped by fq qdisc when per band +* limit is reached. +*/ +SKB_DROP_REASON_FQ_BAND_LIMIT , +/** +* @SKB_DROP_REASON_FQ_HORIZON_LIMIT: dropped by fq qdisc when packet +* timestamp is too far in the future. +*/ +SKB_DROP_REASON_FQ_HORIZON_LIMIT , +/** +* @SKB_DROP_REASON_FQ_FLOW_LIMIT: dropped by fq qdisc when a flow +* exceeds its limits. +*/ +SKB_DROP_REASON_FQ_FLOW_LIMIT ,/** * @SKB_DROP_REASON_CPU_BACKLOG: failed to enqueue the skb to the per CPU * backlog queue. This can be caused by backlog queue full (see
include/net/sch_generic.h +8 -0
@@ -1320,6 +1320,14 @@ static inline int qdisc_drop(struct sk_buff *skb, struct Qdisc *sch,return NET_XMIT_DROP ; } +static inline int qdisc_drop_reason (struct sk_buff *skb,struct Qdisc *sch, +struct sk_buff **to_free, +enum skb_drop_reason reason) +{ +tcf_set_drop_reason (skb, reason); +return qdisc_drop (skb, sch, to_free); +} +static inline int qdisc_drop_all (struct sk_buff *skb,struct Qdisc *sch,struct sk_buff **to_free) {
net/sched/sch_fq.c +10 -4
@@ -535,6 +535,8 @@ static bool fq_packet_beyond_horizon(const struct sk_buff *skb,return unlikely ((s64 )skb->tstamp > (s64)(now + q->horizon)); } +#define FQDR (reason) SKB_DROP_REASON_FQ_##reason +static int fq_enqueue (struct sk_buff *skb,struct Qdisc *sch,struct sk_buff **to_free) {
@@ -546,7 +548,8 @@ static int fq_enqueue(struct sk_buff *skb, struct Qdisc *sch, band =fq_prio2band (q->prio2band, skb->priority &TC_PRIO_MAX );if (unlikely (q->band_pkt_count[band] >= sch->limit)) { q->stat_band_drops[band]++; -return qdisc_drop (skb, sch, to_free); +return qdisc_drop_reason (skb, sch, to_free, +FQDR (BAND_LIMIT )); } now =ktime_get_ns ();
@@ -556,8 +559,9 @@ static int fq_enqueue(struct sk_buff *skb, struct Qdisc *sch,/* Check if packet timestamp is too far in the future. */ if (fq_packet_beyond_horizon (skb, q, now)) {if (q->horizon_drop) { - q->stat_horizon_drops++; -return qdisc_drop (skb, sch, to_free); + q->stat_horizon_drops++; +return qdisc_drop_reason (skb, sch, to_free, +FQDR (HORIZON_LIMIT )); } q->stat_horizon_caps++; skb->tstamp = now + q->horizon;
@@ -570,7 +574,8 @@ static int fq_enqueue(struct sk_buff *skb, struct Qdisc *sch,if (f != &q->internal) {if (unlikely (f->qlen >= q->flow_plimit)) { q->stat_flows_plimit++; -return qdisc_drop (skb, sch, to_free); +return qdisc_drop_reason (skb, sch, to_free, +FQDR (FLOW_LIMIT )); }if (fq_flow_is_detached (f)) {
@@ -595,6 +600,7 @@ static int fq_enqueue(struct sk_buff *skb, struct Qdisc *sch,return NET_XMIT_SUCCESS ; } +#undef FQDRstatic void fq_check_throttled (struct fq_sched_data *q,u64 now) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 599/869 net/sched: add qstats_cpu_drop_inc() helper
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 3f3aa77ff1c8b45ec8c9e40212f1a24a93e00df3 ]
1) Using this_cpu_inc() is better than going through this_cpu_ptr():
- Single instruction on x86.
- Store tearing prevention.
2) Change tcf_action_update_stats() to use this_cpu_add().
3) Add WRITE_ONCE() to __qdisc_qstats_drop() and qstats_drop_inc() in preparation for lockless "tc qdisc show".
$ scripts/bloat-o-meter -t vmlinux.old vmlinux.new add/remove: 0/0 grow/shrink: 3/17 up/down: 72/-216 (-144) Function old new delta dualpi2_enqueue_skb 462 511 +49 tcf_ife_act 1061 1077 +16 taprio_enqueue 613 620 +7 codel_qdisc_enqueue 149 143 -6 tcf_vlan_act 684 676 -8 tcf_skbedit_act 626 618 -8 tcf_police_act 725 717 -8 tcf_mpls_act 1297 1289 -8 tcf_gate_act 310 302 -8 tcf_gact_act 222 214 -8 tcf_csum_act 2438 2430 -8 tcf_bpf_act 709 701 -8 tcf_action_update_stats 124 115 -9 pie_qdisc_enqueue 865 856 -9 pfifo_enqueue 116 107 -9 choke_enqueue 2069 2059 -10 plug_enqueue 139 128 -11 bfifo_enqueue 121 110 -11 tcf_nat_act 1501 1489 -12 gred_enqueue 1743 1668 -75 Total: Before=24388609, After=24388465, chg -0.00%
Stable-dep-of: 5b483f7791b0 ("net/sched: act_ife: Only operate on Ethernet frames")
--- include/net/act_api.h | 2 +- include/net/sch_generic.h | 9 +++++++-- net/sched/act_api.c | 2 +- net/sched/act_bpf.c | 2 +- net/sched/act_ife.c | 8 ++++---- net/sched/act_mpls.c | 2 +- net/sched/act_police.c | 2 +- net/sched/act_skbedit.c | 2 +- net/sched/sch_cake.c | 2 +- net/sched/sch_fq_codel.c | 2 +- net/sched/sch_gred.c | 2 +- 11 files changed, 20 insertions(+), 15 deletions(-)
include/net/act_api.h +1 -1
@@ -238,7 +238,7 @@ static inline void tcf_action_update_bstats(struct tc_action *a,static inline void tcf_action_inc_drop_qstats (struct tc_action *a) {if (likely (a->cpu_qstats)) { -qstats_drop_inc (this_cpu_ptr (a->cpu_qstats)); +qstats_cpu_drop_inc (a->cpu_qstats);return ; }spin_lock (&a->tcfa_lock);
include/net/sch_generic.h +7 -2
@@ -976,12 +976,17 @@ static inline void qdisc_qstats_cpu_requeues_inc(struct Qdisc *sch)static inline void __qdisc_qstats_drop (struct Qdisc *sch,int count) { - sch->qstats.drops += count; +WRITE_ONCE (sch->qstats.drops, sch->qstats.drops + count); }static inline void qstats_drop_inc (struct gnet_stats_queue *qstats) { - qstats->drops++; +WRITE_ONCE (qstats->drops, qstats->drops +1 ); +} + +static inline void qstats_cpu_drop_inc (struct gnet_stats_queue __percpu *qstats) +{ +this_cpu_inc (qstats->drops); }static inline void qstats_overlimit_inc (struct gnet_stats_queue *qstats)
net/sched/act_api.c +1 -1
@@ -1570,7 +1570,7 @@ void tcf_action_update_stats(struct tc_action *a, u64 bytes, u64 packets,if (a->cpu_bstats) {_bstats_update (this_cpu_ptr (a->cpu_bstats), bytes, packets); -this_cpu_ptr (a->cpu_qstats)->drops += drops; +this_cpu_add (a->cpu_qstats->drops, drops);if (hw) _bstats_update(this_cpu_ptr(a->cpu_bstats_hw),
net/sched/act_bpf.c +1 -1
@@ -76,7 +76,7 @@ TC_INDIRECT_SCOPE int tcf_bpf_act(struct sk_buff *skb,break ;case TC_ACT_SHOT : action = filter_res; -qstats_drop_inc (this_cpu_ptr (prog->common.cpu_qstats)); +qstats_cpu_drop_inc (prog->common.cpu_qstats);break ;case TC_ACT_UNSPEC : action = prog->tcf_action;
net/sched/act_ife.c +4 -4
@@ -727,7 +727,7 @@ static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a, tlv_data =ife_decode (skb, &metalen);if (unlikely (!tlv_data)) { -qstats_drop_inc (this_cpu_ptr (ife->common.cpu_qstats)); +qstats_cpu_drop_inc (ife->common.cpu_qstats);return TC_ACT_SHOT ; }
@@ -740,7 +740,7 @@ static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a, curr_data =ife_tlv_meta_decode (tlv_data, ifehdr_end, &mtype, &dlen,NULL );if (!curr_data) { -qstats_drop_inc (this_cpu_ptr (ife->common.cpu_qstats)); +qstats_cpu_drop_inc (ife->common.cpu_qstats);return TC_ACT_SHOT ; }
@@ -755,7 +755,7 @@ static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a, }if (WARN_ON (tlv_data != ifehdr_end)) { -qstats_drop_inc (this_cpu_ptr (ife->common.cpu_qstats)); +qstats_cpu_drop_inc (ife->common.cpu_qstats);return TC_ACT_SHOT ; }
@@ -821,7 +821,7 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a,* so lets be conservative.. */ if ((action ==TC_ACT_SHOT ) || exceed_mtu) { drop: -qstats_drop_inc (this_cpu_ptr (ife->common.cpu_qstats)); +qstats_cpu_drop_inc (ife->common.cpu_qstats);return TC_ACT_SHOT ; }
net/sched/act_mpls.c +1 -1
@@ -125,7 +125,7 @@ TC_INDIRECT_SCOPE int tcf_mpls_act(struct sk_buff *skb,return ret; drop: -qstats_drop_inc (this_cpu_ptr (m->common.cpu_qstats)); +qstats_cpu_drop_inc (m->common.cpu_qstats);return TC_ACT_SHOT ; }
net/sched/act_police.c +1 -1
@@ -317,7 +317,7 @@ TC_INDIRECT_SCOPE int tcf_police_act(struct sk_buff *skb,qstats_overlimit_inc (this_cpu_ptr (police->common.cpu_qstats)); inc_drops:if (ret ==TC_ACT_SHOT ) -qstats_drop_inc (this_cpu_ptr (police->common.cpu_qstats)); +qstats_cpu_drop_inc (police->common.cpu_qstats); end:return ret; }
net/sched/act_skbedit.c +1 -1
@@ -85,7 +85,7 @@ TC_INDIRECT_SCOPE int tcf_skbedit_act(struct sk_buff *skb,return params->action; err: -qstats_drop_inc (this_cpu_ptr (d->common.cpu_qstats)); +qstats_cpu_drop_inc (d->common.cpu_qstats);return TC_ACT_SHOT ; }
net/sched/sch_cake.c +1 -1
@@ -1824,7 +1824,7 @@ static s32 cake_enqueue(struct sk_buff *skb, struct Qdisc *sch,if (ack) { b->ack_drops++; - sch->qstats.drops++; +qdisc_qstats_drop (sch); ack_pkt_len =qdisc_pkt_len (ack); b->bytes += ack_pkt_len; q->buffer_used += skb->truesize - ack->truesize;
net/sched/sch_fq_codel.c +1 -1
@@ -175,7 +175,7 @@ static unsigned int fq_codel_drop(struct Qdisc *sch, unsigned int max_packets, flow->cvars.count += i; q->backlogs[idx] -= len; q->memory_usage -= mem; - sch->qstats.drops += i; +__qdisc_qstats_drop (sch, i); sch->qstats.backlog -= len; sch->q.qlen -= i;return idx;
net/sched/sch_gred.c +1 -1
@@ -389,7 +389,7 @@ static int gred_offload_dump_stats(struct Qdisc *sch) packets +=u64_stats_read (&hw_stats->stats.bstats[i].packets); sch->qstats.qlen += hw_stats->stats.qstats[i].qlen; sch->qstats.backlog += hw_stats->stats.qstats[i].backlog; - sch->qstats.drops += hw_stats->stats.qstats[i].drops; +__qdisc_qstats_drop (sch, hw_stats->stats.qstats[i].drops); sch->qstats.requeues += hw_stats->stats.qstats[i].requeues; sch->qstats.overlimits += hw_stats->stats.qstats[i].overlimits; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 600/869 net/sched: act_ife: Only operate on Ethernet frames
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Victor Nogueira <[email protected]>
[ Upstream commit 5b483f7791b079bb97d411f1066652ff659207ff ]
act_ife encapsulates/decapsulates the original Ethernet header and uses skb->dev->hard_header_len as the length of that header. That is only correct for Ethernet devices: on a device where hard_header_len does not match the L2 header that was actually pulled (PPP reports PPP_HDRLEN while nothing is stripped on ingress), the ingress skb_push()/skb_pull() use the wrong length and can hit skb_under_panic when headroom is tight.
IFE is Ethernet-only by design - it builds an outer ethhdr, rewrites h_source/h_dest/h_proto, and calls eth_type_trans() on decode - so instead of trying to make the offsets work for arbitrary link types, simply drop packets that do not carry an Ethernet header.
Checking skb->dev->type alone is not enough. We have to cater for a corner case where mirred can redirect an skb from a non-Ethernet device to an Ethernet one, and skb->dev then says nothing about the framing the skb actually has: an skb redirected from ppp0 reaches the target's ingress hook with mac_len 0 and no Ethernet header at all. So at ingress also require mac_len to be ETH_HLEN. On egress mac_len is not maintained, so the device type is all we have; a bogus redirect there yields a malformed frame rather than an out-of-bounds push, and it would be malformed with or without IFE.
That corner case is not theoretical - redirecting from ppp0 into a veth that has an ife encode action on its ingress hook panics without this patch:
skbuff: skb_under_panic: len:98 put:14 head:ffff88800e410000
data:ffff88800e40fff5 tail:0x57 end:0x640 dev:veth3 kernel BUG at net/core/skbuff.c:214! Call Trace: skb_push (net/core/skbuff.c:224 net/core/skbuff.c:2657) tcf_ife_act (net/sched/act_ife.c:829 net/sched/act_ife.c:874) tc_run (net/core/dev.c:4463) netif_receive_skb (net/core/dev.c:6463 net/core/dev.c:6522) tcf_mirred_to_dev (net/sched/act_mirred.c:248 net/sched/act_mirred.c:328) tcf_mirred_act (net/sched/act_mirred.c:489) tc_run (net/core/dev.c:4463) process_backlog (net/core/dev.c:6728)
With Ethernet framing guaranteed, use ETH_HLEN instead of hard_header_len.
--- net/ife/ife.c | 14 +++++++------- net/sched/act_ife.c | 32 ++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 11 deletions(-)
net/ife/ife.c +7 -7
@@ -37,7 +37,7 @@ void *ife_encode(struct sk_buff *skb, u16 metalen)* where ORIGDATA = original ethernet header ... */ int hdrm = metalen +IFE_METAHDRLEN ; -int total_push = hdrm + skb->dev->hard_header_len; +int total_push = hdrm +ETH_HLEN ;struct ifeheadr *ifehdr;struct ethhdr *iethh;/* inner ether header */ int skboff =0 ;
@@ -50,9 +50,9 @@ void *ife_encode(struct sk_buff *skb, u16 metalen) iethh = (struct ethhdr *) skb->data;__skb_push (skb, total_push); -memcpy (skb->data, iethh, skb->dev->hard_header_len); +memcpy (skb->data, iethh,ETH_HLEN );skb_reset_mac_header (skb); - skboff += skb->dev->hard_header_len; + skboff +=ETH_HLEN ;/* total metadata length */ ifehdr = (struct ifeheadr *) (skb->data + skboff);
@@ -69,12 +69,12 @@ void *ife_decode(struct sk_buff *skb, u16 *metalen)int total_pull;u16 ifehdrln; -if (!pskb_may_pull (skb, skb->dev->hard_header_len +IFE_METAHDRLEN )) +if (!pskb_may_pull (skb,ETH_HLEN +IFE_METAHDRLEN ))return NULL ; - ifehdr = (struct ifeheadr *) (skb->data + skb->dev->hard_header_len); + ifehdr = (struct ifeheadr *)(skb->data +ETH_HLEN ); ifehdrln =ntohs (ifehdr->metalen); - total_pull = skb->dev->hard_header_len + ifehdrln; + total_pull =ETH_HLEN + ifehdrln;if (unlikely (ifehdrln <2 ))return NULL ;
@@ -82,7 +82,7 @@ void *ife_decode(struct sk_buff *skb, u16 *metalen)if (unlikely (!pskb_may_pull (skb, total_pull +ETH_HLEN )))return NULL ; - ifehdr = (struct ifeheadr *)(skb->data + skb->dev->hard_header_len); + ifehdr = (struct ifeheadr *)(skb->data +ETH_HLEN );skb_set_mac_header (skb, total_pull);__skb_pull (skb, total_pull); *metalen = ifehdrln -IFE_METAHDRLEN ;
net/sched/act_ife.c +28 -4
@@ -28,6 +28,7 @@#include <uapi/linux/tc_act/tc_ife.h> #include <net/tc_act/tc_ife.h> #include <linux/etherdevice.h> +#include <linux/if_arp.h> #include <net/ife.h> #include <net/tc_wrapper.h>
@@ -723,7 +724,7 @@ static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a,tcf_lastuse_update (&ife->tcf_tm);if (skb_at_tc_ingress (skb)) -skb_push (skb, skb->dev->hard_header_len); +skb_push (skb,ETH_HLEN ); tlv_data =ife_decode (skb, &metalen);if (unlikely (!tlv_data)) {
@@ -795,7 +796,7 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a,where ORIGDATA = original ethernet header ... */ u16 metalen =ife_get_sz (skb, p); -int hdrm = metalen + skb->dev->hard_header_len +IFE_METAHDRLEN ; +int hdrm = metalen +ETH_HLEN +IFE_METAHDRLEN ;unsigned int skboff =0 ;int new_len = skb->len + hdrm;bool exceed_mtu = false;
@@ -826,7 +827,7 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a, }if (skb_at_tc_ingress (skb)) -skb_push (skb, skb->dev->hard_header_len); +skb_push (skb,ETH_HLEN ); ife_meta =ife_encode (skb, metalen);if (!ife_meta)
@@ -856,11 +857,27 @@ static int tcf_ife_encode(struct sk_buff *skb, const struct tc_action *a, oethh->h_proto =htons (p->eth_type);if (skb_at_tc_ingress (skb)) -skb_pull (skb, skb->dev->hard_header_len); +skb_pull (skb,ETH_HLEN );return action; } +/* IFE encapsulates the original Ethernet header and, on decode, expects to +* find one, so it can only ever work on skbs that carry one. Loopback carries +* Ethernet header as well, so it qualifies here. +* At ingress, also verify that the L2 header about to be pushed back really +* is an Ethernet header because the skb could've been redirected with mirred +* from a non-Ethernet device. +*/ +static bool tcf_ife_is_eth_skb (const struct sk_buff *skb) +{ +if (skb->dev->type !=ARPHRD_ETHER && + skb->dev->type !=ARPHRD_LOOPBACK ) +return false; + +return !skb_at_tc_ingress (skb) || skb->mac_len ==ETH_HLEN ; +} + TC_INDIRECT_SCOPE int tcf_ife_act(struct sk_buff *skb,const struct tc_action *a,struct tcf_result *res)
@@ -869,6 +886,13 @@ TC_INDIRECT_SCOPE int tcf_ife_act(struct sk_buff *skb,struct tcf_ife_params *p;int ret; +if (unlikely (!tcf_ife_is_eth_skb (skb))) { +bstats_update (this_cpu_ptr (ife->common.cpu_bstats), skb); +tcf_lastuse_update (&ife->tcf_tm); +qstats_cpu_drop_inc (ife->common.cpu_qstats); +return TC_ACT_SHOT ; + } + p =rcu_dereference_bh (ife->params);if (p->flags &IFE_ENCODE ) { ret =tcf_ife_encode (skb, a, res, p);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 601/869 octeontx2-vf: fix workqueue and netdev race in probe/remove
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anshumali Gaur <[email protected]>
[ Upstream commit 3ba97ff4f873481d370bee7f7dfb87f8296af9be ]
Initialize the VF workqueue before register_netdev() so ndo_set_rx_mode does not queue work on a NULL workqueue. Unregister the netdev before destroying the workqueue, and add proper probe error cleanup.
--- .../ethernet/marvell/octeontx2/nic/otx2_vf.c | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c +13 -7
@@ -685,16 +685,16 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id)snprintf (netdev->name,sizeof (netdev->name),"lbk%d" , n); } + err =otx2_wq_init (vf); +if (err) + goto err_ptp_destroy; + err =register_netdev (netdev);if (err) {dev_err (dev,"Failed to register netdevice\n" ); - goto err_ptp_destroy; + goto err_wq_destroy; } - err =otx2_wq_init (vf); -if (err) - goto err_unreg_netdev; -otx2vf_set_ethtool_ops (netdev); err =otx2vf_mcam_flow_init (vf);
@@ -722,6 +722,10 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id)otx2_shutdown_tc (vf); err_unreg_netdev:unregister_netdev (netdev); +err_wq_destroy: +cancel_work_sync (&vf->reset_task); +cancel_work_sync (&vf->rx_mode_work); +destroy_workqueue (vf->otx2_wq); err_ptp_destroy:otx2_ptp_destroy (vf); err_detach_rsrc:
@@ -769,11 +773,13 @@ static void otx2vf_remove(struct pci_dev *pdev) }#endif -cancel_work_sync (&vf->reset_task);otx2_unregister_dl (vf);unregister_netdev (netdev); -if (vf->otx2_wq) +if (vf->otx2_wq) { +cancel_work_sync (&vf->reset_task); +cancel_work_sync (&vf->rx_mode_work);destroy_workqueue (vf->otx2_wq); + }otx2_ptp_destroy (vf);otx2_mcam_flow_del (vf);otx2_shutdown_tc (vf);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 602/869 xsk: honor XDP_TX_METADATA in zero-copy path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanislav Fomichev <[email protected]>
[ Upstream commit a6e4b9a6deb9362ef7a0706c70d674e92fe1411a ]
The zero-copy path reads TX metadata whenever the UMEM has metadata space, even if the descriptor does not set XDP_TX_METADATA. Pass descriptor options through the metadata helpers and ignore metadata unless the option is set.
This does not fix the existing per-WQE metadata handling for mlx5 MPWQEs. Only the descriptor that starts a session passes through xsk_tx_metadata_request() and configures offload state shared by the batch. Metadata on descriptors joining an open session is therefore not validated and does not configure its requested offloads. In addition, a non-NULL metadata pointer from such a descriptor is treated as a timestamp completion request even when XDP_TXMD_FLAGS_TIMESTAMP is not set, so its metadata union can be overwritten with an unrequested timestamp. Fixing mixed metadata states within one MPWQE requires a separate change.
--- drivers/net/ethernet/intel/igc/igc_main.c | 3 ++- drivers/net/ethernet/mellanox/mlx5/core/en/xsk/tx.c | 4 ++-- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 +++- include/net/xdp_sock_drv.h | 6 +++--- 4 files changed, 10 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/igc/igc_main.c +2 -1
@@ -3002,7 +3002,8 @@ static void igc_xdp_xmit_zc(struct igc_ring *ring) olinfo_status = xdp_desc.len <<IGC_ADVTXD_PAYLEN_SHIFT ; dma =xsk_buff_raw_get_dma (pool, xdp_desc.addr); - meta =xsk_buff_get_metadata (pool, xdp_desc.addr); + meta =xsk_buff_get_metadata (pool, xdp_desc.addr, + xdp_desc.options);xsk_buff_raw_dma_sync_for_device (pool, dma, xdp_desc.len); bi = &ring->tx_buffer_info[ntu];
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/tx.c +2 -2
@@ -97,7 +97,7 @@ bool mlx5e_xsk_tx(struct mlx5e_xdpsq *sq, unsigned int budget) xdptxd.dma_addr =xsk_buff_raw_get_dma (pool, desc.addr); xdptxd.data =xsk_buff_raw_get_data (pool, desc.addr); xdptxd.len = desc.len; - meta =xsk_buff_get_metadata (pool, desc.addr); + meta =xsk_buff_get_metadata (pool, desc.addr, desc.options);xsk_buff_raw_dma_sync_for_device (pool, xdptxd.dma_addr, xdptxd.len);
@@ -112,7 +112,7 @@ bool mlx5e_xsk_tx(struct mlx5e_xdpsq *sq, unsigned int budget) }else {mlx5e_xdpi_fifo_push (&sq->db.xdpi_fifo, xdpi);if (xp_tx_metadata_enabled (sq->xsk_pool)) { -struct xsk_tx_metadata_compl compl; +struct xsk_tx_metadata_compl compl = {};xsk_tx_metadata_to_compl (meta, &compl);XSK_TX_COMPL_FITS (void *);
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +3 -1
@@ -2521,7 +2521,8 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget) tx_desc = tx_q->dma_tx + entry; dma_addr =xsk_buff_raw_get_dma (pool, xdp_desc.addr); - meta =xsk_buff_get_metadata (pool, xdp_desc.addr); + meta =xsk_buff_get_metadata (pool, xdp_desc.addr, + xdp_desc.options);xsk_buff_raw_dma_sync_for_device (pool, dma_addr, xdp_desc.len); tx_q->tx_skbuff_dma[entry].buf_type =STMMAC_TXBUF_T_XSK_TX ;
@@ -2566,6 +2567,7 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)stmmac_enable_dma_transmission (priv, priv->ioaddr, queue); + tx_q->tx_skbuff_dma[entry].xsk_meta.tx_timestamp =NULL ;xsk_tx_metadata_to_compl (meta, &tx_q->tx_skbuff_dma[entry].xsk_meta);
include/net/xdp_sock_drv.h +3 -3
@@ -232,11 +232,11 @@ xsk_buff_valid_tx_metadata(const struct xsk_tx_metadata *meta)return !(meta->flags & ~XDP_TXMD_FLAGS_VALID ); } -static inline struct xsk_tx_metadata *xsk_buff_get_metadata (struct xsk_buff_pool *pool,u64 addr) +static inline struct xsk_tx_metadata *xsk_buff_get_metadata (struct xsk_buff_pool *pool,u64 addr,u32 options) {struct xsk_tx_metadata *meta; -if (!pool->tx_metadata_len) +if (!pool->tx_metadata_len || !(options &XDP_TX_METADATA ))return NULL ; meta =xp_raw_get_data (pool, addr) - pool->tx_metadata_len;
@@ -426,7 +426,7 @@ static inline bool xsk_buff_valid_tx_metadata(struct xsk_tx_metadata *meta)return false; } -static inline struct xsk_tx_metadata *xsk_buff_get_metadata (struct xsk_buff_pool *pool,u64 addr) +static inline struct xsk_tx_metadata *xsk_buff_get_metadata (struct xsk_buff_pool *pool,u64 addr,u32 options) {return NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 603/869 Bluetooth: do not leak an hci_conn when a second LE connect is rejected
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Radek Podgorny <[email protected]>
[ Upstream commit 7e1e4047200fd7519f9bdfe8a001437715e618b4 ]
create_le_conn_complete() decides whether the failed connection is still pending by comparing it against hci_lookup_le_connect(), which returns the first LE connection in BT_CONNECT. That is the same connection only while at most one is pending.
Two can be pending. Connections created on the passive scan path sit in BT_CONNECT with HCI_CONN_SCANNING set and are invisible to hci_lookup_le_connect() until hci_le_create_conn_sync() clears the flag when their command is issued, so the -EBUSY guard in hci_connect_le() does not prevent a second connection from being queued while the first is still on the scan path. Whenever two connections are in BT_CONNECT at once, the lookup may return one connection while create_le_conn_complete() is reporting the failure of the other; the early exit then drops the error and hci_conn_failed() never runs on the connection that failed.
The controller also rejects a second HCI_OP_LE_CREATE_CONN issued while another connection creation is still outstanding, per Core Spec Vol 4, Part E. The spec calls for Command Disallowed there; the bcm43438 observed here answers with an LMP/LL error code instead, which bt_to_errno() maps to the -EPROTO (-71) in the log below.
The leaked connection stays in BT_CONNECT forever, and because hci_connect_le() refuses to dial while hci_lookup_le_connect() finds anything, every subsequent attempt to reach any peer fails with -EBUSY and no command reaches the controller at all.
Seen on a bcm43438 with two BLE peers polled on the same interval (state 5 is BT_CONNECT; both handles are UNSET ones, allocated from the ida above HCI_CONN_HANDLE_MAX):
Bluetooth: hci1: Opcode 0x2013 failed: -71
# hcitool con
< LE 14:9C:EF:03:68:81 handle 3840 state 5 lm CENTRAL
< LE C4:D3:6A:8C:B5:38 handle 3841 state 5 lm CENTRALA btmon capture across the next ten minutes of connect attempts contains no HCI_OP_LE_CREATE_CONN at all; outgoing LE connections do not recover until the adapter is reset. With this change the same scenario fails the rejected connection cleanly and further connects to both peers go through.
Ask about the connection itself instead of about the device.
--- net/bluetooth/hci_sync.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/bluetooth/hci_sync.c +7 -2
@@ -7188,8 +7188,13 @@ static void create_le_conn_complete(struct hci_dev *hdev, void *data, int err) goto unlock; } -/* Check if connection is still pending */ -if (conn !=hci_lookup_le_connect (hdev)) +/* Check if this connection is still pending. +* +* hci_lookup_le_connect() returns only the first LE connection +* in BT_CONNECT, which is not necessarily this one when two are +* pending at once, so ask the connection itself. +*/ +if (conn->state !=BT_CONNECT ) goto unlock;/* Flush to make sure we send create conn cancel command if needed */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 604/869 net: add getsockopt_iter callback to proto_ops
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
[ Upstream commit 67fab22a7adcec0279b9b057eb3dc669e32834f0 ]
Add a new getsockopt_iter callback to struct proto_ops that uses sockopt_t, a type-safe wrapper around iov_iter. This provides a clean interface for socket option operations that works with both user and kernel buffers.
The sockopt_t type encapsulates an iov_iter and an optlen field.
The optlen field, although not suggested by Linus, serves as both input (buffer size) and output (returned data size), allowing callbacks to return random values independent of the bytes written via copy_to_iter(), so, keep it separated from iov_iter.count.
This is preparatory work for removing the SOL_SOCKET level restriction from io_uring getsockopt operations.
Keep in mind that both iter_out and iter_in always point to the same data at all times, and we just have two of them to make the callback implementation sane.
Stable-dep-of: ca2c4c264986 ("Bluetooth: L2CAP: access chan->conn safely in get/setsockopt")
--- include/linux/net.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
include/linux/net.h +23 -0
@@ -23,9 +23,30 @@#include <linux/fs.h> #include <linux/mm.h> #include <linux/sockptr.h> +#include <linux/uio.h> #include <uapi/linux/net.h> +/** +* struct sockopt - socket option value container +* @iter_in: iov_iter for reading optval with the content from the caller. +* Use copy_from_iter() given this iov direction is ITER_SOURCE +* @iter_out: iov_iter for protocols to update optval data to userspace +* Use _copy_to_iter() given iov direction is ITER_DEST +* @optlen: serves as both input (buffer size) and output (returned data size). +* +* Type-safe wrapper for socket option data that works with both +* user and kernel buffers. +* +* The optlen field allows callbacks to return a specific length value +* independent of the bytes written via copy_to_iter(). +*/ +typedef struct sockopt { +struct iov_iter iter_in; +struct iov_iter iter_out; +int optlen; +}sockopt_t ; +struct poll_table_struct ;struct pipe_inode_info ;struct inode ;
@@ -194,6 +215,8 @@ struct proto_ops { unsigned int optlen);int (*getsockopt)(struct socket *sock,int level,int optname,char __user *optval,int __user *optlen); +int (*getsockopt_iter)(struct socket *sock,int level, +int optname,sockopt_t *opt);void (*show_fdinfo)(struct seq_file *m,struct socket *sock);int (*sendmsg) (struct socket *sock,struct msghdr *m,size_t total_len);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 605/869 Bluetooth: L2CAP: convert to getsockopt_iter
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
[ Upstream commit bf01627cc04b70c04a6d68eda06f836fed3078bc ]
Convert L2CAP socket's getsockopt implementation to use the new getsockopt_iter callback with sockopt_t.
Key changes:
- Replace (char __user *optval, int __user *optlen) with sockopt_t *sopt
- Use sopt->optlen for buffer length (input)
- Use copy_to_iter() instead of put_user()/copy_to_user()
- Add linux/uio.h for copy_to_iter()
The sockopt_t parameter is named sopt rather than opt to avoid collision with the existing local u32 opt used by L2CAP_LM. The same naming is reused for the new u32 helper in l2cap_sock_getsockopt(), with mtu and mval helpers covering the u16 and u8 cases.
Stable-dep-of: ca2c4c264986 ("Bluetooth: L2CAP: access chan->conn safely in get/setsockopt")
--- net/bluetooth/l2cap_sock.c | 61 +++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 24 deletions(-)
net/bluetooth/l2cap_sock.c +37 -24
@@ -31,6 +31,7 @@#include <linux/export.h> #include <linux/filter.h> #include <linux/sched/signal.h> +#include <linux/uio.h> #include <net/bluetooth/bluetooth.h> #include <net/bluetooth/hci_core.h>
@@ -439,7 +440,7 @@ static int l2cap_get_mode(struct l2cap_chan *chan) }static int l2cap_sock_getsockopt_old (struct socket *sock,int optname, -char __user *optval,int __user *optlen) +sockopt_t *sopt) {struct sock *sk = sock->sk;struct l2cap_chan *chan =l2cap_pi (sk)->chan;
@@ -451,8 +452,7 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname,BT_DBG ("sk %p" , sk); -if (get_user (len, optlen)) -return -EFAULT ; + len = sopt->optlen;lock_sock (sk);
@@ -494,7 +494,7 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname,BT_DBG ("mode 0x%2.2x" , chan->mode); len =min (len,sizeof (opts)); -if (copy_to_user (optval, (char *) &opts, len)) +if (copy_to_iter (&opts, len, &sopt->iter_out) != len) err = -EFAULT ;break ;
@@ -526,7 +526,8 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname,if (test_bit (FLAG_FORCE_RELIABLE , &chan->flags)) opt |=L2CAP_LM_RELIABLE ; -if (put_user (opt, (u32 __user *) optval)) +if (copy_to_iter (&opt,sizeof (opt), &sopt->iter_out) != +sizeof (opt)) err = -EFAULT ;break ;
@@ -544,7 +545,7 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname,memcpy (cinfo.dev_class, chan->conn->hcon->dev_class,3 ); len =min (len,sizeof (cinfo)); -if (copy_to_user (optval, (char *) &cinfo, len)) +if (copy_to_iter (&cinfo, len, &sopt->iter_out) != len) err = -EFAULT ;break ;
@@ -559,25 +560,26 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, }static int l2cap_sock_getsockopt (struct socket *sock,int level,int optname, -char __user *optval,int __user *optlen) +sockopt_t *sopt) {struct sock *sk = sock->sk;struct l2cap_chan *chan =l2cap_pi (sk)->chan;struct bt_security sec;struct bt_power pwr; -u32 phys;int len, mode, err =0 ; +u32 opt; +u16 mtu; +u8 mval;BT_DBG ("sk %p" , sk);if (level ==SOL_L2CAP ) -return l2cap_sock_getsockopt_old (sock, optname, optval, optlen); +return l2cap_sock_getsockopt_old (sock, optname, sopt);if (level !=SOL_BLUETOOTH )return -ENOPROTOOPT ; -if (get_user (len, optlen)) -return -EFAULT ; + len = sopt->optlen;lock_sock (sk);
@@ -601,7 +603,7 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, } len = min_t(unsigned int, len, sizeof(sec)); -if (copy_to_user (optval, (char *) &sec, len)) +if (copy_to_iter (&sec, len, &sopt->iter_out) != len) err = -EFAULT ;break ;
@@ -612,15 +614,17 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname,break ; } -if (put_user (test_bit (BT_SK_DEFER_SETUP , &bt_sk (sk)->flags), - (u32 __user *) optval)) + opt =test_bit (BT_SK_DEFER_SETUP , &bt_sk (sk)->flags); +if (copy_to_iter (&opt,sizeof (opt), &sopt->iter_out) != +sizeof (opt)) err = -EFAULT ;break ;case BT_FLUSHABLE : -if (put_user (test_bit (FLAG_FLUSHABLE , &chan->flags), - (u32 __user *) optval)) + opt =test_bit (FLAG_FLUSHABLE , &chan->flags); +if (copy_to_iter (&opt,sizeof (opt), &sopt->iter_out) != +sizeof (opt)) err = -EFAULT ;break ;
@@ -635,13 +639,15 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, pwr.force_active =test_bit (FLAG_FORCE_ACTIVE , &chan->flags); len = min_t(unsigned int, len, sizeof(pwr)); -if (copy_to_user (optval, (char *) &pwr, len)) +if (copy_to_iter (&pwr, len, &sopt->iter_out) != len) err = -EFAULT ;break ;case BT_CHANNEL_POLICY : -if (put_user (chan->chan_policy, (u32 __user *) optval)) + opt = chan->chan_policy; +if (copy_to_iter (&opt,sizeof (opt), &sopt->iter_out) != +sizeof (opt)) err = -EFAULT ;break ;
@@ -656,7 +662,9 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname,break ; } -if (put_user (chan->omtu, (u16 __user *) optval)) + mtu = chan->omtu; +if (copy_to_iter (&mtu,sizeof (mtu), &sopt->iter_out) != +sizeof (mtu)) err = -EFAULT ;break ;
@@ -666,7 +674,9 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname,break ; } -if (put_user (chan->imtu, (u16 __user *) optval)) + mtu = chan->imtu; +if (copy_to_iter (&mtu,sizeof (mtu), &sopt->iter_out) != +sizeof (mtu)) err = -EFAULT ;break ;
@@ -676,9 +686,10 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname,break ; } - phys =hci_conn_get_phy (chan->conn->hcon); + opt =hci_conn_get_phy (chan->conn->hcon); -if (put_user (phys, (u32 __user *) optval)) +if (copy_to_iter (&opt,sizeof (opt), &sopt->iter_out) != +sizeof (opt)) err = -EFAULT ;break ;
@@ -699,7 +710,9 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname,break ; } -if (put_user (mode, (u8 __user *) optval)) + mval = mode; +if (copy_to_iter (&mval,sizeof (mval), &sopt->iter_out) != +sizeof (mval)) err = -EFAULT ;break ;
@@ -2019,7 +2032,7 @@ static const struct proto_ops l2cap_sock_ops = { .socketpair = sock_no_socketpair, .shutdown = l2cap_sock_shutdown, .setsockopt = l2cap_sock_setsockopt, - .getsockopt = l2cap_sock_getsockopt + .getsockopt_iter = l2cap_sock_getsockopt };static const struct net_proto_family l2cap_sock_family_ops = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 606/869 Bluetooth: L2CAP: access chan->conn safely in get/setsockopt
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pauli Virtanen <[email protected]>
[ Upstream commit ca2c4c26498643f421d35ffe258fafbd3ed461c3 ]
Since commit b66774b48dd9 ("Bluetooth: L2CAP: Fix UAF in channel timeout by holding conn ref") l2cap_chan::conn has held reference and remains non-NULL also after the corresponding hci_conn is deleted. In this state accessing various
fields eg. hci_conn::hdev is invalid, which leads to KASAN crash in l2cap_sock_setsockopt() access of conn->hcon->hdev.
Check l2cap_chan::conn.hcon corresponds to an alive hci_conn before trying to use it in l2cap_sock.c. Hold l2cap_chan_lock() in getsockopt/setsockopt to ensure it stays alive, and to avoid data races in l2cap_chan fields.
--- net/bluetooth/l2cap_sock.c | 57 ++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 11 deletions(-)
net/bluetooth/l2cap_sock.c +46 -11
@@ -439,11 +439,26 @@ static int l2cap_get_mode(struct l2cap_chan *chan)return -EINVAL ; } +static struct l2cap_conn *l2cap_chan_conn (struct l2cap_chan *chan) +{ +lockdep_assert_held (&chan->lock); + +/* l2cap_conn_del() sets FLAG_DEL while holding chan->lock before +* conn->hcon is deleted. If not set and conn is non-NULL, conn->hcon +* remains alive during this chan->lock critical section. +*/ +if (test_bit (FLAG_DEL , &chan->flags)) +return NULL ; + +return chan->conn; +} +static int l2cap_sock_getsockopt_old (struct socket *sock,int optname,sockopt_t *sopt) {struct sock *sk = sock->sk;struct l2cap_chan *chan =l2cap_pi (sk)->chan; +struct l2cap_conn *conn;struct l2cap_options opts;struct l2cap_conninfo cinfo;int err =0 ;
@@ -454,6 +469,7 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, len = sopt->optlen; +l2cap_chan_lock (chan);lock_sock (sk);switch (optname) {
@@ -540,9 +556,15 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname,break ; } + conn =l2cap_chan_conn (chan); +if (!conn) { + err = -ENOTCONN ; +break ; + } +memset (&cinfo,0 ,sizeof (cinfo)); - cinfo.hci_handle = chan->conn->hcon->handle; -memcpy (cinfo.dev_class, chan->conn->hcon->dev_class,3 ); + cinfo.hci_handle = conn->hcon->handle; +memcpy (cinfo.dev_class, conn->hcon->dev_class,3 ); len =min (len,sizeof (cinfo));if (copy_to_iter (&cinfo, len, &sopt->iter_out) != len)
@@ -556,6 +578,8 @@ static int l2cap_sock_getsockopt_old(struct socket *sock, int optname, }release_sock (sk); +l2cap_chan_unlock (chan); +return err; }
@@ -564,6 +588,7 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, {struct sock *sk = sock->sk;struct l2cap_chan *chan =l2cap_pi (sk)->chan; +struct l2cap_conn *conn;struct bt_security sec;struct bt_power pwr;int len, mode, err =0 ;
@@ -581,6 +606,7 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, len = sopt->optlen; +l2cap_chan_lock (chan);lock_sock (sk);switch (optname) {
@@ -592,12 +618,14 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname,break ; } + conn =l2cap_chan_conn (chan); +memset (&sec,0 ,sizeof (sec)); -if (chan->conn) { - sec.level = chan->conn->hcon->sec_level; +if (conn) { + sec.level = conn->hcon->sec_level;if (sk->sk_state ==BT_CONNECTED ) - sec.key_size = chan->conn->hcon->enc_key_size; + sec.key_size = conn->hcon->enc_key_size; }else { sec.level = chan->sec_level; }
@@ -681,12 +709,14 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname,break ;case BT_PHY : -if (sk->sk_state !=BT_CONNECTED ) { + conn =l2cap_chan_conn (chan); + +if (sk->sk_state !=BT_CONNECTED || !conn) { err = -ENOTCONN ;break ; } - opt =hci_conn_get_phy (chan->conn->hcon); + opt =hci_conn_get_phy (conn->hcon);if (copy_to_iter (&opt,sizeof (opt), &sopt->iter_out) !=sizeof (opt))
@@ -722,6 +752,7 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, }release_sock (sk); +l2cap_chan_unlock (chan);return err; }
@@ -752,6 +783,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,BT_DBG ("sk %p" , sk); +l2cap_chan_lock (chan);lock_sock (sk);switch (optname) {
@@ -853,6 +885,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, }release_sock (sk); +l2cap_chan_unlock (chan);return err; }
@@ -916,6 +949,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,if (level !=SOL_BLUETOOTH )return -ENOPROTOOPT ; +l2cap_chan_lock (chan);lock_sock (sk);switch (optname) {
@@ -941,11 +975,10 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, chan->sec_level = sec.level; -if (!chan->conn) + conn =l2cap_chan_conn (chan); +if (!conn)break ; - conn = chan->conn; -/* change security for LE channels */ if (chan->scid ==L2CAP_CID_ATT ) {if (smp_conn_security (conn->hcon, sec.level)) {
@@ -1000,7 +1033,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, }if (opt ==BT_FLUSHABLE_OFF ) { - conn = chan->conn; + conn =l2cap_chan_conn (chan); +/* proceed further only when we have l2cap_conn and No Flush support in the LM */ if (!conn || !lmp_no_flush_capable (conn->hcon->hdev)) {
@@ -1124,6 +1158,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, }release_sock (sk); +l2cap_chan_unlock (chan);return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 607/869 Drivers: hv: vmbus: Skip VMBus module cleanup for non-nested root partition
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Kelley <[email protected]>
[ Upstream commit cee0d90bceae1dee3bcc70f8d6b2ceb5b87deb42 ]
The VMBus module initialization function, hv_acpi_init(), currently does nothing when running in the root partition and root is not nested in another VM. But the initialization function reports success, so the VMBus module is indeed loaded. VMBus functionality is not actually needed, but the VMBus module must be loaded so that hv_vmbus_exists() can answer correctly. Furthermore, the mshv_root dependency on the VMBus module is needed as described in the commit message for 840b740a35bf ("mshv: Add conditional VMBus dependency").
Loading the VMBus module without actually initializing it causes failures if the module should later be unloaded. The module unload code tries to clean up things that were never initialized, resulting in memory faults and a panic.
Fix this by having VMBus module exit function perform the same check for non-nested root partition, and do nothing in such a case, just like hv_acpi_init().
In the long run, the code that manages the Hyper-V provided SynIC should be refactored to better coordinate the requirements of root partition scenarios and normal VM scenarios, and to hopefully remove the hv_vmbus_exists() dependnecy between mshv_root and VMBus modules. Preventing the current unload failure scenario is an expediency until such a refactoring is done.
--- drivers/hv/vmbus_drv.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/hv/vmbus_drv.c +15 -0
@@ -2832,6 +2832,13 @@ static int __init hv_acpi_init(void)return -ENODEV ;if (hv_root_partition && !hv_nested) +/* +* A non-nested root partition does not need VMBus client +* functionality. However, the mshv_root module may have +* a dependency on the VMBus module as described in +* commit 840b740a35bf. Return success so the module +* loads even though no VMBus initialization is done. +*/ return 0 ;/*
@@ -2880,6 +2887,14 @@ static void __exit vmbus_exit(void) {int cpu; +if (hv_root_partition && !hv_nested) +/* +* If a non-nested root partition loaded the VMBus module, +* hv_acpi_init() did not do any VMBus initialization. +* There's nothing to clean up, so just return. +*/ +return ; +unregister_syscore (&hv_synic_syscore);hv_remove_kexec_handler ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 608/869 net/sched: account classifier filter allocations to memcg
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
[ Upstream commit 1beb81947eb486716af80db7a584f9e9fef7e003 ]
Allocations in the tc classifier *_change() paths (filter objects, per-CPU counters, and per-filter aux data) use plain GFP_KERNEL without __GFP_ACCOUNT, allowing unprivileged users to pin kernel memory outside memcg charging. The shared tcf_exts_init_ex() action array allocation in cls_api.c was also uncharged; this patch closes it along with the per-classifier filter-object/percpu/aux allocations that remain unaccounted.
Add GFP_KERNEL_ACCOUNT to:
- the shared tcf_exts_init_ex() action array (cls_api.c), common to every filter of every classifier (32 pointers, 256 bytes);
- the filter-object, per-CPU-counter, and per-filter aux allocations in cls_basic, cls_bpf, cls_cgroup, cls_flow, cls_flower, cls_fw, cls_matchall, cls_route and cls_u32;
- the u32_init_knode() replace-path knode allocation (cls_u32.c), which allocates the same struct tc_u_knode + sel.keys on every replace of an existing knode and was missed by the create-path-only conversion.
Also fix the cls_basic error path: basic_change() inserts fnew into the IDR before allocating the per-CPU counter. If alloc_percpu() fails the errout path kfree'd fnew without idr_remove, leaving a dangling pointer in the IDR. With GFP_KERNEL_ACCOUNT the percpu alloc becomes failable on demand (memcg at memory.max), making the dead path attacker-reachable and burning the handle permanently. Add the idr_remove on the percpu failure path, matching the basic_set_parms failure-path pattern.
Note: [email protected] provided a poc for basic_cls, but it was easy to extend to the other classifiers.
Conditions to recreate the bug:
- CONFIG_NET_SCHED, CONFIG_NET_CLS_* (the classifier being used), CONFIG_NET_CLS_ACT, CONFIG_MEMCG, CONFIG_USER_NS, CONFIG_NET_NS.
- Unprivileged user in a fresh user+network namespace (unshare -Urn), or root with CAP_NET_ADMIN.
- Create a large number of tc filters (e.g. tc filter add dev lo ingress ... <classifier> ...) while watching a memcg-limited cgroup:
system slab grows far faster than memory.current, pinning kernel memory outside memcg charging.
--- net/sched/cls_api.c | 2 +- net/sched/cls_basic.c | 6 ++++-- net/sched/cls_bpf.c | 6 +++--- net/sched/cls_cgroup.c | 2 +- net/sched/cls_flow.c | 2 +- net/sched/cls_flower.c | 4 ++-- net/sched/cls_fw.c | 4 ++-- net/sched/cls_matchall.c | 4 ++-- net/sched/cls_route.c | 4 ++-- net/sched/cls_u32.c | 11 ++++++----- 10 files changed, 24 insertions(+), 21 deletions(-)
net/sched/cls_api.c +1 -1
@@ -3375,7 +3375,7 @@ int tcf_exts_init_ex(struct tcf_exts *exts, struct net *net, int action,*/ exts->net = net; exts->actions =kcalloc (TCA_ACT_MAX_PRIO ,sizeof (struct tc_action *), -GFP_KERNEL ); +GFP_KERNEL_ACCOUNT );if (!exts->actions)return -ENOMEM ;#endif
net/sched/cls_basic.c +4 -2
@@ -193,7 +193,7 @@ static int basic_change(struct net *net, struct sk_buff *in_skb,return -EINVAL ; } - fnew =kzalloc (sizeof (*fnew),GFP_KERNEL ); + fnew =kzalloc (sizeof (*fnew),GFP_KERNEL_ACCOUNT );if (!fnew)return -ENOBUFS ;
@@ -212,9 +212,11 @@ static int basic_change(struct net *net, struct sk_buff *in_skb,if (err) goto errout; fnew->handle = handle; - fnew->pf = alloc_percpu(struct tc_basic_pcnt); + fnew->pf = alloc_percpu_gfp(struct tc_basic_pcnt, GFP_KERNEL_ACCOUNT);if (!fnew->pf) { err = -ENOMEM ; +if (!fold) +idr_remove (&head->handle_idr, fnew->handle); goto errout; }
net/sched/cls_bpf.c +3 -3
@@ -352,7 +352,7 @@ static int cls_bpf_prog_from_ops(struct nlattr **tb, struct cls_bpf_prog *prog)if (bpf_size !=nla_len (tb[TCA_BPF_OPS ]))return -EINVAL ; - bpf_ops =kmemdup (nla_data (tb[TCA_BPF_OPS ]), bpf_size,GFP_KERNEL ); + bpf_ops =kmemdup (nla_data (tb[TCA_BPF_OPS ]), bpf_size,GFP_KERNEL_ACCOUNT );if (bpf_ops ==NULL )return -ENOMEM ;
@@ -403,7 +403,7 @@ static int cls_bpf_prog_from_efd(struct nlattr **tb, struct cls_bpf_prog *prog, }if (tb[TCA_BPF_NAME ]) { - name =nla_memdup (tb[TCA_BPF_NAME ],GFP_KERNEL ); + name =nla_memdup (tb[TCA_BPF_NAME ],GFP_KERNEL_ACCOUNT );if (!name) {bpf_prog_put (fp);return -ENOMEM ;
@@ -443,7 +443,7 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,if (ret <0 )return ret; - prog =kzalloc (sizeof (*prog),GFP_KERNEL ); + prog =kzalloc (sizeof (*prog),GFP_KERNEL_ACCOUNT );if (!prog)return -ENOBUFS ;
net/sched/cls_cgroup.c +1 -1
@@ -95,7 +95,7 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,if (head && handle != head->handle)return -ENOENT ; - new =kzalloc (sizeof (*head),GFP_KERNEL ); + new =kzalloc (sizeof (*head),GFP_KERNEL_ACCOUNT );if (!new)return -ENOBUFS ;
net/sched/cls_flow.c +1 -1
@@ -438,7 +438,7 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,return -EOPNOTSUPP ; } - fnew =kzalloc (sizeof (*fnew),GFP_KERNEL ); + fnew =kzalloc (sizeof (*fnew),GFP_KERNEL_ACCOUNT );if (!fnew)return -ENOBUFS ;
net/sched/cls_flower.c +2 -2
@@ -2237,7 +2237,7 @@ static struct fl_flow_mask *fl_create_new_mask(struct cls_fl_head *head,struct fl_flow_mask *newmask;int err; - newmask =kzalloc (sizeof (*newmask),GFP_KERNEL ); + newmask =kzalloc (sizeof (*newmask),GFP_KERNEL_ACCOUNT );if (!newmask)return ERR_PTR (-ENOMEM );
@@ -2398,7 +2398,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, goto errout_tb; } - fnew =kzalloc (sizeof (*fnew),GFP_KERNEL ); + fnew =kzalloc (sizeof (*fnew),GFP_KERNEL_ACCOUNT );if (!fnew) { err = -ENOBUFS ; goto errout_tb;
net/sched/cls_fw.c +2 -2
@@ -276,7 +276,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,if (f->id != handle && handle)return -EINVAL ; - fnew =kzalloc (sizeof (struct fw_filter ),GFP_KERNEL ); + fnew =kzalloc (sizeof (struct fw_filter ),GFP_KERNEL_ACCOUNT );if (!fnew)return -ENOBUFS ;
@@ -330,7 +330,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,rcu_assign_pointer (tp->root, head); } - f =kzalloc (sizeof (struct fw_filter ),GFP_KERNEL ); + f =kzalloc (sizeof (struct fw_filter ),GFP_KERNEL_ACCOUNT );if (f ==NULL )return -ENOBUFS ;
net/sched/cls_matchall.c +2 -2
@@ -189,7 +189,7 @@ static int mall_change(struct net *net, struct sk_buff *in_skb,return -EINVAL ; } - new =kzalloc (sizeof (*new),GFP_KERNEL ); + new =kzalloc (sizeof (*new),GFP_KERNEL_ACCOUNT );if (!new)return -ENOBUFS ;
@@ -201,7 +201,7 @@ static int mall_change(struct net *net, struct sk_buff *in_skb, handle =1 ; new->handle = handle; new->flags = userflags; - new->pf = alloc_percpu(struct tc_matchall_pcnt); + new->pf = alloc_percpu_gfp(struct tc_matchall_pcnt, GFP_KERNEL_ACCOUNT);if (!new->pf) { err = -ENOMEM ; goto err_alloc_percpu;
net/sched/cls_route.c +2 -2
@@ -455,7 +455,7 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp, h1 =to_hash (nhandle); b =rtnl_dereference (head->table[h1]);if (!b) { - b =kzalloc (sizeof (struct route4_bucket ),GFP_KERNEL ); + b =kzalloc (sizeof (struct route4_bucket ),GFP_KERNEL_ACCOUNT );if (b ==NULL )return -ENOBUFS ;
@@ -530,7 +530,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,return -EINVAL ; err = -ENOBUFS ; - f =kzalloc (sizeof (struct route4_filter ),GFP_KERNEL ); + f =kzalloc (sizeof (struct route4_filter ),GFP_KERNEL_ACCOUNT );if (!f) goto errout;
net/sched/cls_u32.c +6 -5
@@ -841,7 +841,7 @@ static struct tc_u_knode *u32_init_knode(struct net *net, struct tcf_proto *tp,struct tc_u32_sel *s = &n->sel;struct tc_u_knode *new; - new =kzalloc (struct_size (new, sel.keys, s->nkeys),GFP_KERNEL ); + new =kzalloc (struct_size (new, sel.keys, s->nkeys),GFP_KERNEL_ACCOUNT );if (!new)return NULL ;
@@ -1139,15 +1139,16 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, goto erridr; } - n =kzalloc (struct_size (n, sel.keys, s->nkeys),GFP_KERNEL ); + n =kzalloc (struct_size (n, sel.keys, s->nkeys),GFP_KERNEL_ACCOUNT );if (n ==NULL ) { err = -ENOBUFS ; goto erridr; }#ifdef CONFIG_CLS_U32_PERF - n->pf =__alloc_percpu (struct_size (n->pf, kcnts, s->nkeys), - __alignof__(struct tc_u32_pcnt )); + n->pf =__alloc_percpu_gfp (struct_size (n->pf, kcnts, s->nkeys), + __alignof__(struct tc_u32_pcnt ), +GFP_KERNEL_ACCOUNT );if (!n->pf) { err = -ENOBUFS ; goto errfree;
@@ -1169,7 +1170,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, goto errout;#ifdef CONFIG_CLS_U32_MARK - n->pcpu_success =alloc_percpu (u32); + n->pcpu_success =alloc_percpu_gfp (u32,GFP_KERNEL_ACCOUNT );if (!n->pcpu_success) { err = -ENOMEM ; goto errout;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 609/869 NFSv4.1: zero referring call lists before decoding
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit 8fa4804fe62ca4155a2d8fc2789d630376cbf2fc ]
decode_cb_sequence_args() allocates csa_rclists with kmalloc_objs(), so each referring_call_list starts uninitialized. decode_rc_list() assigns rcl_refcalls only when rcl_nrefcalls is nonzero. A valid list with zero referring calls therefore leaves the pointer uninitialized, and nfs4_callback_sequence() later passes stale slab contents to kfree().
Allocate csa_rclists with kzalloc_objs() so every rcl_refcalls member is NULL from the beginning, including valid empty referring call lists.
--- fs/nfs/callback_xdr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/nfs/callback_xdr.c +3 -3
@@ -422,9 +422,9 @@ static __be32 decode_cb_sequence_args(struct svc_rqst *rqstp, args->csa_nrclists =ntohl (*p++); args->csa_rclists =NULL ;if (args->csa_nrclists) { - args->csa_rclists =kmalloc_array (args->csa_nrclists, -sizeof (*args->csa_rclists), -GFP_KERNEL ); + args->csa_rclists =kcalloc (args->csa_nrclists, +sizeof (*args->csa_rclists), +GFP_KERNEL );if (unlikely (args->csa_rclists ==NULL ))return htonl (NFS4ERR_RESOURCE );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 610/869 vxlan: fix reading neigh ha
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nikolay Aleksandrov <[email protected]>
[ Upstream commit b824059a673b2283e78c7aae2c7d257aad7f0e1d ]
Currently arp/neigh_reduce read neigh ha directly which can lead to partial reads while the neigh is being updated. Use neigh_ha_snapshot to take a stable snapshot of the address similar to route_shortcircuit which already does the right thing.
--- drivers/net/vxlan/vxlan_core.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/net/vxlan/vxlan_core.c +13 -7
@@ -1917,6 +1917,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)if (n) {struct vxlan_rdst *rdst =NULL ; +u8 ha[ETH_ALEN ]__aligned(2) ;struct vxlan_fdb *f;struct sk_buff *reply;
@@ -1925,8 +1926,10 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) goto out; } +neigh_ha_snapshot (ha, n, n->dev); +rcu_read_lock (); - f =vxlan_find_mac_tx (vxlan, n->ha, vni); + f =vxlan_find_mac_tx (vxlan, ha, vni);if (f) rdst =first_remote_rcu (f);if (rdst &&vxlan_addr_any (&rdst->remote_ip)) {
@@ -1938,7 +1941,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)rcu_read_unlock (); reply =arp_create (ARPOP_REPLY ,ETH_P_ARP , sip, dev, tip, sha, - n->ha, sha); + ha, sha);neigh_release (n);
@@ -1971,7 +1974,8 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)#if IS_ENABLED (CONFIG_IPV6 )static struct sk_buff *vxlan_na_create (struct sk_buff *request, -struct neighbour *n,bool isrouter) +struct neighbour *n,u8 *ha, +bool isrouter) {struct net_device *dev = request->dev;struct sk_buff *reply;
@@ -2019,7 +2023,7 @@ static struct sk_buff *vxlan_na_create(struct sk_buff *request,/* Ethernet header */ ether_addr_copy (eth_hdr (reply)->h_dest, daddr); -ether_addr_copy (eth_hdr (reply)->h_source, n->ha); +ether_addr_copy (eth_hdr (reply)->h_source, ha);eth_hdr (reply)->h_proto =htons (ETH_P_IPV6 ); reply->protocol =htons (ETH_P_IPV6 );
@@ -2048,7 +2052,7 @@ static struct sk_buff *vxlan_na_create(struct sk_buff *request, na->icmph.icmp6_override =1 ; na->icmph.icmp6_solicited =1 ; na->target = ns->target; -ether_addr_copy (&na->opt[2 ], n->ha); +ether_addr_copy (&na->opt[2 ], ha); na->opt[0 ] =ND_OPT_TARGET_LL_ADDR ; na->opt[1 ] = na_olen >>3 ;
@@ -2091,6 +2095,7 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)if (n) {struct vxlan_rdst *rdst =NULL ; +u8 ha[ETH_ALEN ]__aligned(2) ;struct vxlan_fdb *f;struct sk_buff *reply;
@@ -2099,7 +2104,8 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) goto out; } - f =vxlan_find_mac_tx (vxlan, n->ha, vni); +neigh_ha_snapshot (ha, n, n->dev); + f =vxlan_find_mac_tx (vxlan, ha, vni);if (f) rdst =first_remote_rcu (f);if (rdst &&vxlan_addr_any (&rdst->remote_ip)) {
@@ -2108,7 +2114,7 @@ static int neigh_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni) goto out; } - reply =vxlan_na_create (skb, n, + reply =vxlan_na_create (skb, n, ha, !!(f ? f->flags &NTF_ROUTER :0 ));neigh_release (n);
Signature · 1 line
2.53.0