Merge 5.10.125 into android12-5.10-lts

Changes in 5.10.125
	s390/mm: use non-quiescing sske for KVM switch to keyed guest
	zonefs: fix zonefs_iomap_begin() for reads
	usb: gadget: u_ether: fix regression in setting fixed MAC address
	tcp: add some entropy in __inet_hash_connect()
	tcp: use different parts of the port_offset for index and offset
	tcp: add small random increments to the source port
	tcp: dynamically allocate the perturb table used by source ports
	tcp: increase source port perturb table to 2^16
	tcp: drop the hash_32() part from the index calculation
	serial: core: Initialize rs485 RTS polarity already on probe
	arm64: mm: Don't invalidate FROM_DEVICE buffers at start of DMA transfer
	io_uring: add missing item types for various requests
	Linux 5.10.125

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: Ie3934e1f246cb92d4775dd95120957c9fc12c30f
This commit is contained in:
Greg Kroah-Hartman
2022-07-28 16:06:01 +02:00
8 changed files with 124 additions and 77 deletions

View File

@@ -1,7 +1,7 @@
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
VERSION = 5 VERSION = 5
PATCHLEVEL = 10 PATCHLEVEL = 10
SUBLEVEL = 124 SUBLEVEL = 125
EXTRAVERSION = EXTRAVERSION =
NAME = Dare mighty things NAME = Dare mighty things

View File

@@ -228,8 +228,6 @@ SYM_FUNC_END_PI(__dma_flush_area)
* - dir - DMA direction * - dir - DMA direction
*/ */
SYM_FUNC_START_PI(__dma_map_area) SYM_FUNC_START_PI(__dma_map_area)
cmp w2, #DMA_FROM_DEVICE
b.eq __dma_inv_area
b __dma_clean_area b __dma_clean_area
SYM_FUNC_END_PI(__dma_map_area) SYM_FUNC_END_PI(__dma_map_area)

View File

@@ -734,7 +734,7 @@ void ptep_zap_key(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
pgste_val(pgste) |= PGSTE_GR_BIT | PGSTE_GC_BIT; pgste_val(pgste) |= PGSTE_GR_BIT | PGSTE_GC_BIT;
ptev = pte_val(*ptep); ptev = pte_val(*ptep);
if (!(ptev & _PAGE_INVALID) && (ptev & _PAGE_WRITE)) if (!(ptev & _PAGE_INVALID) && (ptev & _PAGE_WRITE))
page_set_storage_key(ptev & PAGE_MASK, PAGE_DEFAULT_KEY, 1); page_set_storage_key(ptev & PAGE_MASK, PAGE_DEFAULT_KEY, 0);
pgste_set_unlock(ptep, pgste); pgste_set_unlock(ptep, pgste);
preempt_enable(); preempt_enable();
} }

View File

@@ -144,6 +144,11 @@ uart_update_mctrl(struct uart_port *port, unsigned int set, unsigned int clear)
unsigned long flags; unsigned long flags;
unsigned int old; unsigned int old;
if (port->rs485.flags & SER_RS485_ENABLED) {
set &= ~TIOCM_RTS;
clear &= ~TIOCM_RTS;
}
spin_lock_irqsave(&port->lock, flags); spin_lock_irqsave(&port->lock, flags);
old = port->mctrl; old = port->mctrl;
port->mctrl = (old & ~clear) | set; port->mctrl = (old & ~clear) | set;
@@ -157,23 +162,10 @@ uart_update_mctrl(struct uart_port *port, unsigned int set, unsigned int clear)
static void uart_port_dtr_rts(struct uart_port *uport, int raise) static void uart_port_dtr_rts(struct uart_port *uport, int raise)
{ {
int rs485_on = uport->rs485_config && if (raise)
(uport->rs485.flags & SER_RS485_ENABLED); uart_set_mctrl(uport, TIOCM_DTR | TIOCM_RTS);
int RTS_after_send = !!(uport->rs485.flags & SER_RS485_RTS_AFTER_SEND); else
uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS);
if (raise) {
if (rs485_on && RTS_after_send) {
uart_set_mctrl(uport, TIOCM_DTR);
uart_clear_mctrl(uport, TIOCM_RTS);
} else {
uart_set_mctrl(uport, TIOCM_DTR | TIOCM_RTS);
}
} else {
unsigned int clear = TIOCM_DTR;
clear |= (!rs485_on || RTS_after_send) ? TIOCM_RTS : 0;
uart_clear_mctrl(uport, clear);
}
} }
/* /*
@@ -1109,11 +1101,6 @@ uart_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear)
goto out; goto out;
if (!tty_io_error(tty)) { if (!tty_io_error(tty)) {
if (uport->rs485.flags & SER_RS485_ENABLED) {
set &= ~TIOCM_RTS;
clear &= ~TIOCM_RTS;
}
uart_update_mctrl(uport, set, clear); uart_update_mctrl(uport, set, clear);
ret = 0; ret = 0;
} }
@@ -2417,6 +2404,9 @@ uart_configure_port(struct uart_driver *drv, struct uart_state *state,
*/ */
spin_lock_irqsave(&port->lock, flags); spin_lock_irqsave(&port->lock, flags);
port->mctrl &= TIOCM_DTR; port->mctrl &= TIOCM_DTR;
if (port->rs485.flags & SER_RS485_ENABLED &&
!(port->rs485.flags & SER_RS485_RTS_AFTER_SEND))
port->mctrl |= TIOCM_RTS;
port->ops->set_mctrl(port, port->mctrl); port->ops->set_mctrl(port, port->mctrl);
spin_unlock_irqrestore(&port->lock, flags); spin_unlock_irqrestore(&port->lock, flags);

View File

@@ -773,9 +773,13 @@ struct eth_dev *gether_setup_name(struct usb_gadget *g,
dev->qmult = qmult; dev->qmult = qmult;
snprintf(net->name, sizeof(net->name), "%s%%d", netname); snprintf(net->name, sizeof(net->name), "%s%%d", netname);
if (get_ether_addr(dev_addr, net->dev_addr)) if (get_ether_addr(dev_addr, net->dev_addr)) {
net->addr_assign_type = NET_ADDR_RANDOM;
dev_warn(&g->dev, dev_warn(&g->dev,
"using random %s ethernet address\n", "self"); "using random %s ethernet address\n", "self");
} else {
net->addr_assign_type = NET_ADDR_SET;
}
if (get_ether_addr(host_addr, dev->host_mac)) if (get_ether_addr(host_addr, dev->host_mac))
dev_warn(&g->dev, dev_warn(&g->dev,
"using random %s ethernet address\n", "host"); "using random %s ethernet address\n", "host");
@@ -832,6 +836,9 @@ struct net_device *gether_setup_name_default(const char *netname)
INIT_LIST_HEAD(&dev->tx_reqs); INIT_LIST_HEAD(&dev->tx_reqs);
INIT_LIST_HEAD(&dev->rx_reqs); INIT_LIST_HEAD(&dev->rx_reqs);
/* by default we always have a random MAC address */
net->addr_assign_type = NET_ADDR_RANDOM;
skb_queue_head_init(&dev->rx_frames); skb_queue_head_init(&dev->rx_frames);
/* network device setup */ /* network device setup */
@@ -869,7 +876,6 @@ int gether_register_netdev(struct net_device *net)
g = dev->gadget; g = dev->gadget;
memcpy(net->dev_addr, dev->dev_mac, ETH_ALEN); memcpy(net->dev_addr, dev->dev_mac, ETH_ALEN);
net->addr_assign_type = NET_ADDR_RANDOM;
status = register_netdev(net); status = register_netdev(net);
if (status < 0) { if (status < 0) {
@@ -909,6 +915,7 @@ int gether_set_dev_addr(struct net_device *net, const char *dev_addr)
if (get_ether_addr(dev_addr, new_addr)) if (get_ether_addr(dev_addr, new_addr))
return -EINVAL; return -EINVAL;
memcpy(dev->dev_mac, new_addr, ETH_ALEN); memcpy(dev->dev_mac, new_addr, ETH_ALEN);
net->addr_assign_type = NET_ADDR_SET;
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(gether_set_dev_addr); EXPORT_SYMBOL_GPL(gether_set_dev_addr);

View File

@@ -773,7 +773,8 @@ static const struct io_op_def io_op_defs[] = {
.buffer_select = 1, .buffer_select = 1,
.needs_async_data = 1, .needs_async_data = 1,
.async_size = sizeof(struct io_async_rw), .async_size = sizeof(struct io_async_rw),
.work_flags = IO_WQ_WORK_MM | IO_WQ_WORK_BLKCG, .work_flags = IO_WQ_WORK_MM | IO_WQ_WORK_BLKCG |
IO_WQ_WORK_FILES,
}, },
[IORING_OP_WRITEV] = { [IORING_OP_WRITEV] = {
.needs_file = 1, .needs_file = 1,
@@ -783,7 +784,7 @@ static const struct io_op_def io_op_defs[] = {
.needs_async_data = 1, .needs_async_data = 1,
.async_size = sizeof(struct io_async_rw), .async_size = sizeof(struct io_async_rw),
.work_flags = IO_WQ_WORK_MM | IO_WQ_WORK_BLKCG | .work_flags = IO_WQ_WORK_MM | IO_WQ_WORK_BLKCG |
IO_WQ_WORK_FSIZE, IO_WQ_WORK_FSIZE | IO_WQ_WORK_FILES,
}, },
[IORING_OP_FSYNC] = { [IORING_OP_FSYNC] = {
.needs_file = 1, .needs_file = 1,
@@ -794,7 +795,8 @@ static const struct io_op_def io_op_defs[] = {
.unbound_nonreg_file = 1, .unbound_nonreg_file = 1,
.pollin = 1, .pollin = 1,
.async_size = sizeof(struct io_async_rw), .async_size = sizeof(struct io_async_rw),
.work_flags = IO_WQ_WORK_BLKCG | IO_WQ_WORK_MM, .work_flags = IO_WQ_WORK_BLKCG | IO_WQ_WORK_MM |
IO_WQ_WORK_FILES,
}, },
[IORING_OP_WRITE_FIXED] = { [IORING_OP_WRITE_FIXED] = {
.needs_file = 1, .needs_file = 1,
@@ -803,7 +805,7 @@ static const struct io_op_def io_op_defs[] = {
.pollout = 1, .pollout = 1,
.async_size = sizeof(struct io_async_rw), .async_size = sizeof(struct io_async_rw),
.work_flags = IO_WQ_WORK_BLKCG | IO_WQ_WORK_FSIZE | .work_flags = IO_WQ_WORK_BLKCG | IO_WQ_WORK_FSIZE |
IO_WQ_WORK_MM, IO_WQ_WORK_MM | IO_WQ_WORK_FILES,
}, },
[IORING_OP_POLL_ADD] = { [IORING_OP_POLL_ADD] = {
.needs_file = 1, .needs_file = 1,
@@ -857,7 +859,7 @@ static const struct io_op_def io_op_defs[] = {
.pollout = 1, .pollout = 1,
.needs_async_data = 1, .needs_async_data = 1,
.async_size = sizeof(struct io_async_connect), .async_size = sizeof(struct io_async_connect),
.work_flags = IO_WQ_WORK_MM, .work_flags = IO_WQ_WORK_MM | IO_WQ_WORK_FS,
}, },
[IORING_OP_FALLOCATE] = { [IORING_OP_FALLOCATE] = {
.needs_file = 1, .needs_file = 1,
@@ -885,7 +887,8 @@ static const struct io_op_def io_op_defs[] = {
.pollin = 1, .pollin = 1,
.buffer_select = 1, .buffer_select = 1,
.async_size = sizeof(struct io_async_rw), .async_size = sizeof(struct io_async_rw),
.work_flags = IO_WQ_WORK_MM | IO_WQ_WORK_BLKCG, .work_flags = IO_WQ_WORK_MM | IO_WQ_WORK_BLKCG |
IO_WQ_WORK_FILES,
}, },
[IORING_OP_WRITE] = { [IORING_OP_WRITE] = {
.needs_file = 1, .needs_file = 1,
@@ -894,7 +897,7 @@ static const struct io_op_def io_op_defs[] = {
.pollout = 1, .pollout = 1,
.async_size = sizeof(struct io_async_rw), .async_size = sizeof(struct io_async_rw),
.work_flags = IO_WQ_WORK_MM | IO_WQ_WORK_BLKCG | .work_flags = IO_WQ_WORK_MM | IO_WQ_WORK_BLKCG |
IO_WQ_WORK_FSIZE, IO_WQ_WORK_FSIZE | IO_WQ_WORK_FILES,
}, },
[IORING_OP_FADVISE] = { [IORING_OP_FADVISE] = {
.needs_file = 1, .needs_file = 1,
@@ -907,14 +910,16 @@ static const struct io_op_def io_op_defs[] = {
.needs_file = 1, .needs_file = 1,
.unbound_nonreg_file = 1, .unbound_nonreg_file = 1,
.pollout = 1, .pollout = 1,
.work_flags = IO_WQ_WORK_MM | IO_WQ_WORK_BLKCG, .work_flags = IO_WQ_WORK_MM | IO_WQ_WORK_BLKCG |
IO_WQ_WORK_FS,
}, },
[IORING_OP_RECV] = { [IORING_OP_RECV] = {
.needs_file = 1, .needs_file = 1,
.unbound_nonreg_file = 1, .unbound_nonreg_file = 1,
.pollin = 1, .pollin = 1,
.buffer_select = 1, .buffer_select = 1,
.work_flags = IO_WQ_WORK_MM | IO_WQ_WORK_BLKCG, .work_flags = IO_WQ_WORK_MM | IO_WQ_WORK_BLKCG |
IO_WQ_WORK_FS,
}, },
[IORING_OP_OPENAT2] = { [IORING_OP_OPENAT2] = {
.work_flags = IO_WQ_WORK_FILES | IO_WQ_WORK_FS | .work_flags = IO_WQ_WORK_FILES | IO_WQ_WORK_FS |

View File

@@ -68,15 +68,49 @@ static inline void zonefs_i_size_write(struct inode *inode, loff_t isize)
zi->i_flags &= ~ZONEFS_ZONE_OPEN; zi->i_flags &= ~ZONEFS_ZONE_OPEN;
} }
static int zonefs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, static int zonefs_read_iomap_begin(struct inode *inode, loff_t offset,
unsigned int flags, struct iomap *iomap, loff_t length, unsigned int flags,
struct iomap *srcmap) struct iomap *iomap, struct iomap *srcmap)
{ {
struct zonefs_inode_info *zi = ZONEFS_I(inode); struct zonefs_inode_info *zi = ZONEFS_I(inode);
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
loff_t isize; loff_t isize;
/* All I/Os should always be within the file maximum size */ /*
* All blocks are always mapped below EOF. If reading past EOF,
* act as if there is a hole up to the file maximum size.
*/
mutex_lock(&zi->i_truncate_mutex);
iomap->bdev = inode->i_sb->s_bdev;
iomap->offset = ALIGN_DOWN(offset, sb->s_blocksize);
isize = i_size_read(inode);
if (iomap->offset >= isize) {
iomap->type = IOMAP_HOLE;
iomap->addr = IOMAP_NULL_ADDR;
iomap->length = length;
} else {
iomap->type = IOMAP_MAPPED;
iomap->addr = (zi->i_zsector << SECTOR_SHIFT) + iomap->offset;
iomap->length = isize - iomap->offset;
}
mutex_unlock(&zi->i_truncate_mutex);
return 0;
}
static const struct iomap_ops zonefs_read_iomap_ops = {
.iomap_begin = zonefs_read_iomap_begin,
};
static int zonefs_write_iomap_begin(struct inode *inode, loff_t offset,
loff_t length, unsigned int flags,
struct iomap *iomap, struct iomap *srcmap)
{
struct zonefs_inode_info *zi = ZONEFS_I(inode);
struct super_block *sb = inode->i_sb;
loff_t isize;
/* All write I/Os should always be within the file maximum size */
if (WARN_ON_ONCE(offset + length > zi->i_max_size)) if (WARN_ON_ONCE(offset + length > zi->i_max_size))
return -EIO; return -EIO;
@@ -86,7 +120,7 @@ static int zonefs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
* operation. * operation.
*/ */
if (WARN_ON_ONCE(zi->i_ztype == ZONEFS_ZTYPE_SEQ && if (WARN_ON_ONCE(zi->i_ztype == ZONEFS_ZTYPE_SEQ &&
(flags & IOMAP_WRITE) && !(flags & IOMAP_DIRECT))) !(flags & IOMAP_DIRECT)))
return -EIO; return -EIO;
/* /*
@@ -95,45 +129,42 @@ static int zonefs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
* write pointer) and unwriten beyond. * write pointer) and unwriten beyond.
*/ */
mutex_lock(&zi->i_truncate_mutex); mutex_lock(&zi->i_truncate_mutex);
isize = i_size_read(inode);
if (offset >= isize)
iomap->type = IOMAP_UNWRITTEN;
else
iomap->type = IOMAP_MAPPED;
if (flags & IOMAP_WRITE)
length = zi->i_max_size - offset;
else
length = min(length, isize - offset);
mutex_unlock(&zi->i_truncate_mutex);
iomap->offset = ALIGN_DOWN(offset, sb->s_blocksize);
iomap->length = ALIGN(offset + length, sb->s_blocksize) - iomap->offset;
iomap->bdev = inode->i_sb->s_bdev; iomap->bdev = inode->i_sb->s_bdev;
iomap->offset = ALIGN_DOWN(offset, sb->s_blocksize);
iomap->addr = (zi->i_zsector << SECTOR_SHIFT) + iomap->offset; iomap->addr = (zi->i_zsector << SECTOR_SHIFT) + iomap->offset;
isize = i_size_read(inode);
if (iomap->offset >= isize) {
iomap->type = IOMAP_UNWRITTEN;
iomap->length = zi->i_max_size - iomap->offset;
} else {
iomap->type = IOMAP_MAPPED;
iomap->length = isize - iomap->offset;
}
mutex_unlock(&zi->i_truncate_mutex);
return 0; return 0;
} }
static const struct iomap_ops zonefs_iomap_ops = { static const struct iomap_ops zonefs_write_iomap_ops = {
.iomap_begin = zonefs_iomap_begin, .iomap_begin = zonefs_write_iomap_begin,
}; };
static int zonefs_readpage(struct file *unused, struct page *page) static int zonefs_readpage(struct file *unused, struct page *page)
{ {
return iomap_readpage(page, &zonefs_iomap_ops); return iomap_readpage(page, &zonefs_read_iomap_ops);
} }
static void zonefs_readahead(struct readahead_control *rac) static void zonefs_readahead(struct readahead_control *rac)
{ {
iomap_readahead(rac, &zonefs_iomap_ops); iomap_readahead(rac, &zonefs_read_iomap_ops);
} }
/* /*
* Map blocks for page writeback. This is used only on conventional zone files, * Map blocks for page writeback. This is used only on conventional zone files,
* which implies that the page range can only be within the fixed inode size. * which implies that the page range can only be within the fixed inode size.
*/ */
static int zonefs_map_blocks(struct iomap_writepage_ctx *wpc, static int zonefs_write_map_blocks(struct iomap_writepage_ctx *wpc,
struct inode *inode, loff_t offset) struct inode *inode, loff_t offset)
{ {
struct zonefs_inode_info *zi = ZONEFS_I(inode); struct zonefs_inode_info *zi = ZONEFS_I(inode);
@@ -147,12 +178,12 @@ static int zonefs_map_blocks(struct iomap_writepage_ctx *wpc,
offset < wpc->iomap.offset + wpc->iomap.length) offset < wpc->iomap.offset + wpc->iomap.length)
return 0; return 0;
return zonefs_iomap_begin(inode, offset, zi->i_max_size - offset, return zonefs_write_iomap_begin(inode, offset, zi->i_max_size - offset,
IOMAP_WRITE, &wpc->iomap, NULL); IOMAP_WRITE, &wpc->iomap, NULL);
} }
static const struct iomap_writeback_ops zonefs_writeback_ops = { static const struct iomap_writeback_ops zonefs_writeback_ops = {
.map_blocks = zonefs_map_blocks, .map_blocks = zonefs_write_map_blocks,
}; };
static int zonefs_writepage(struct page *page, struct writeback_control *wbc) static int zonefs_writepage(struct page *page, struct writeback_control *wbc)
@@ -182,7 +213,8 @@ static int zonefs_swap_activate(struct swap_info_struct *sis,
return -EINVAL; return -EINVAL;
} }
return iomap_swapfile_activate(sis, swap_file, span, &zonefs_iomap_ops); return iomap_swapfile_activate(sis, swap_file, span,
&zonefs_read_iomap_ops);
} }
static const struct address_space_operations zonefs_file_aops = { static const struct address_space_operations zonefs_file_aops = {
@@ -612,7 +644,7 @@ static vm_fault_t zonefs_filemap_page_mkwrite(struct vm_fault *vmf)
/* Serialize against truncates */ /* Serialize against truncates */
down_read(&zi->i_mmap_sem); down_read(&zi->i_mmap_sem);
ret = iomap_page_mkwrite(vmf, &zonefs_iomap_ops); ret = iomap_page_mkwrite(vmf, &zonefs_write_iomap_ops);
up_read(&zi->i_mmap_sem); up_read(&zi->i_mmap_sem);
sb_end_pagefault(inode->i_sb); sb_end_pagefault(inode->i_sb);
@@ -869,7 +901,7 @@ static ssize_t zonefs_file_dio_write(struct kiocb *iocb, struct iov_iter *from)
if (append) if (append)
ret = zonefs_file_dio_append(iocb, from); ret = zonefs_file_dio_append(iocb, from);
else else
ret = iomap_dio_rw(iocb, from, &zonefs_iomap_ops, ret = iomap_dio_rw(iocb, from, &zonefs_write_iomap_ops,
&zonefs_write_dio_ops, sync); &zonefs_write_dio_ops, sync);
if (zi->i_ztype == ZONEFS_ZTYPE_SEQ && if (zi->i_ztype == ZONEFS_ZTYPE_SEQ &&
(ret > 0 || ret == -EIOCBQUEUED)) { (ret > 0 || ret == -EIOCBQUEUED)) {
@@ -911,7 +943,7 @@ static ssize_t zonefs_file_buffered_write(struct kiocb *iocb,
if (ret <= 0) if (ret <= 0)
goto inode_unlock; goto inode_unlock;
ret = iomap_file_buffered_write(iocb, from, &zonefs_iomap_ops); ret = iomap_file_buffered_write(iocb, from, &zonefs_write_iomap_ops);
if (ret > 0) if (ret > 0)
iocb->ki_pos += ret; iocb->ki_pos += ret;
else if (ret == -EIO) else if (ret == -EIO)
@@ -1004,7 +1036,7 @@ static ssize_t zonefs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
goto inode_unlock; goto inode_unlock;
} }
file_accessed(iocb->ki_filp); file_accessed(iocb->ki_filp);
ret = iomap_dio_rw(iocb, to, &zonefs_iomap_ops, ret = iomap_dio_rw(iocb, to, &zonefs_read_iomap_ops,
&zonefs_read_dio_ops, is_sync_kiocb(iocb)); &zonefs_read_dio_ops, is_sync_kiocb(iocb));
} else { } else {
ret = generic_file_read_iter(iocb, to); ret = generic_file_read_iter(iocb, to);

View File

@@ -726,12 +726,14 @@ EXPORT_SYMBOL_GPL(inet_unhash);
* Note that we use 32bit integers (vs RFC 'short integers') * Note that we use 32bit integers (vs RFC 'short integers')
* because 2^16 is not a multiple of num_ephemeral and this * because 2^16 is not a multiple of num_ephemeral and this
* property might be used by clever attacker. * property might be used by clever attacker.
* RFC claims using TABLE_LENGTH=10 buckets gives an improvement, * RFC claims using TABLE_LENGTH=10 buckets gives an improvement, though
* we use 256 instead to really give more isolation and * attacks were since demonstrated, thus we use 65536 instead to really
* privacy, this only consumes 1 KB of kernel memory. * give more isolation and privacy, at the expense of 256kB of kernel
* memory.
*/ */
#define INET_TABLE_PERTURB_SHIFT 8 #define INET_TABLE_PERTURB_SHIFT 16
static u32 table_perturb[1 << INET_TABLE_PERTURB_SHIFT]; #define INET_TABLE_PERTURB_SIZE (1 << INET_TABLE_PERTURB_SHIFT)
static u32 *table_perturb;
int __inet_hash_connect(struct inet_timewait_death_row *death_row, int __inet_hash_connect(struct inet_timewait_death_row *death_row,
struct sock *sk, u64 port_offset, struct sock *sk, u64 port_offset,
@@ -774,10 +776,11 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row,
if (likely(remaining > 1)) if (likely(remaining > 1))
remaining &= ~1U; remaining &= ~1U;
net_get_random_once(table_perturb, sizeof(table_perturb)); net_get_random_once(table_perturb,
index = hash_32(port_offset, INET_TABLE_PERTURB_SHIFT); INET_TABLE_PERTURB_SIZE * sizeof(*table_perturb));
index = port_offset & (INET_TABLE_PERTURB_SIZE - 1);
offset = READ_ONCE(table_perturb[index]) + port_offset; offset = READ_ONCE(table_perturb[index]) + (port_offset >> 32);
offset %= remaining; offset %= remaining;
/* In first pass we try ports of @low parity. /* In first pass we try ports of @low parity.
@@ -833,6 +836,12 @@ next_port:
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
ok: ok:
/* Here we want to add a little bit of randomness to the next source
* port that will be chosen. We use a max() with a random here so that
* on low contention the randomness is maximal and on high contention
* it may be inexistent.
*/
i = max_t(int, i, (prandom_u32() & 7) * 2);
WRITE_ONCE(table_perturb[index], READ_ONCE(table_perturb[index]) + i + 2); WRITE_ONCE(table_perturb[index], READ_ONCE(table_perturb[index]) + i + 2);
/* Head lock still held and bh's disabled */ /* Head lock still held and bh's disabled */
@@ -906,6 +915,12 @@ void __init inet_hashinfo2_init(struct inet_hashinfo *h, const char *name,
low_limit, low_limit,
high_limit); high_limit);
init_hashinfo_lhash2(h); init_hashinfo_lhash2(h);
/* this one is used for source ports of outgoing connections */
table_perturb = kmalloc_array(INET_TABLE_PERTURB_SIZE,
sizeof(*table_perturb), GFP_KERNEL);
if (!table_perturb)
panic("TCP: failed to alloc table_perturb");
} }
int inet_hashinfo2_init_mod(struct inet_hashinfo *h) int inet_hashinfo2_init_mod(struct inet_hashinfo *h)