summaryrefslogtreecommitdiffstats
path: root/net/sctp/ulpqueue.c
AgeCommit message (Expand)Author
2019-12-09sctp: get netns from asoc and ep baseXin Long
2019-05-24treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 104Thomas Gleixner
2019-04-15sctp: implement memory accounting on rx pathXin Long
2019-04-11sctp: Pass sk_buff_head explicitly to sctp_ulpq_tail_event().David Miller
2019-04-11sctp: Make sctp_enqueue_event tak an skb list.David Miller
2019-04-11sctp: Always pass skbs on a list to sctp_ulpq_tail_event().David Miller
2019-04-11sctp: Remove superfluous test in sctp_ulpq_reasm_drain().David Miller
2018-11-19sctp: add subscribe per asocXin Long
2018-11-19sctp: define subscribe in sctp_sock as __u16Xin Long
2018-09-10sctp: Use skb_queue_is_first().David S. Miller
2017-12-22Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/netDavid S. Miller
2017-12-18sctp: fix the issue that a __u16 variable may overflow in sctp_ulpq_renegeXin Long
2017-12-11sctp: add support for the process of unordered idataXin Long
2017-12-11sctp: implement abort_pd for sctp_stream_interleaveXin Long
2017-12-11sctp: implement renege_events for sctp_stream_interleaveXin Long
2017-12-11sctp: implement ulpevent_data for sctp_stream_interleaveXin Long
2017-09-08sctp: fix missing wake ups in some situationsMarcelo Ricardo Leitner
2017-07-01sctp: remove the typedef sctp_data_chunk_tXin Long
2017-06-02sctp: define the member stream as an object instead of pointer in asocXin Long
2017-01-06sctp: prepare asoc stream for stream reconfXin Long
2016-09-19sctp: Remove some redundant codeChristophe Jaillet
2016-07-30sctp: allow delivering notifications after receiving SHUTDOWNXin Long
2016-05-01sctp: signal sk_data_ready earlier on data chunks receptionMarcelo Ricardo Leitner
2016-04-15sctp: simplify sk_receive_queue lockingMarcelo Ricardo Leitner
2016-04-13sctp: delay calls to sk_data_ready() as much as possibleMarcelo Ricardo Leitner
2014-11-11net: introduce SO_INCOMING_CPUEric Dumazet
2014-04-20sctp: add support for busy polling to sctp protocolNeil Horman
2014-04-11net: Fix use after free by removing length arg from sk_data_ready callbacks.David S. Miller
2013-12-26sctp: fix checkpatch errors with open brace '{' and trailing statementswangweidong
2013-12-26sctp: fix checkpatch errors with (foo*)|foo * bar|foo* barwangweidong
2013-12-26sctp: fix checkpatch errors with space required or prohibitedwangweidong
2013-12-06sctp: Fix FSF address in file headersJeff Kirsher
2013-08-09net: sctp: trivial: update bug report in header commentDaniel Borkmann
2013-07-24net: sctp: trivial: update mailing list addressDaniel Borkmann
2013-04-17net: sctp: sctp_ulpq: remove 'malloced' struct memberDaniel Borkmann
2013-02-28sctp: fix association hangs due to partial delivery errorsLee A. Roberts
2013-02-28sctp: fix association hangs due to errors when reneging events from the order...Lee A. Roberts
2013-02-28sctp: fix association hangs due to reneging packets below the cumulative TSN ...Lee A. Roberts
2012-11-03sctp: Clean up type-punning in sctp_cmd_t unionNeil Horman
2012-08-14sctp: Make the mib per network namespaceEric W. Biederman
2012-06-30sctp: be more restrictive in transport selection on bundled sacksNeil Horman
2011-03-31Fix common misspellingsLucas De Marchi
2011-03-07sctp: several declared/set but unused fixesHagen Paul Pfeifer
2010-05-17net: Remove unnecessary returns from void function()sJoe Perches
2010-03-30include cleanup: Update gfp.h and slab.h includes to prepare for breaking imp...Tejun Heo
2008-09-21net: Remove __skb_insert() calls outside of skbuff internals.David S. Miller
2008-02-06[SCTP]: Correctly reap SSNs when processing FORWARD_TSN chunkVlad Yasevich
2008-02-05[SCTP]: Kill silly inlines in ulpqueue.cVlad Yasevich
2008-02-05[SCTP]: Stop claiming that this is a "reference implementation"Vlad Yasevich
2008-01-28[NET] CORE: Introducing new memory accounting interface.Hideo Aoki
ef='#n437'>437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
/*
 * mm/readahead.c - address_space-level file readahead.
 *
 * Copyright (C) 2002, Linus Torvalds
 *
 * 09Apr2002	akpm@zip.com.au
 *		Initial version.
 */

#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/blkdev.h>
#include <linux/backing-dev.h>
#include <linux/task_io_accounting_ops.h>
#include <linux/pagevec.h>

void default_unplug_io_fn(struct backing_dev_info *bdi, struct page *page)
{
}
EXPORT_SYMBOL(default_unplug_io_fn);

/*
 * Convienent macros for min/max read-ahead pages.
 * Note that MAX_RA_PAGES is rounded down, while MIN_RA_PAGES is rounded up.
 * The latter is necessary for systems with large page size(i.e. 64k).
 */
#define MAX_RA_PAGES	(VM_MAX_READAHEAD*1024 / PAGE_CACHE_SIZE)
#define MIN_RA_PAGES	DIV_ROUND_UP(VM_MIN_READAHEAD*1024, PAGE_CACHE_SIZE)

struct backing_dev_info default_backing_dev_info = {
	.ra_pages	= MAX_RA_PAGES,
	.state		= 0,
	.capabilities	= BDI_CAP_MAP_COPY,
	.unplug_io_fn	= default_unplug_io_fn,
};
EXPORT_SYMBOL_GPL(default_backing_dev_info);

/*
 * Initialise a struct file's readahead state.  Assumes that the caller has
 * memset *ra to zero.
 */
void
file_ra_state_init(struct file_ra_state *ra, struct address_space *mapping)
{
	ra->ra_pages = mapping->backing_dev_info->ra_pages;
	ra->prev_index = -1;
}
EXPORT_SYMBOL_GPL(file_ra_state_init);

#define list_to_page(head) (list_entry((head)->prev, struct page, lru))

/**
 * read_cache_pages - populate an address space with some pages & start reads against them
 * @mapping: the address_space
 * @pages: The address of a list_head which contains the target pages.  These
 *   pages have their ->index populated and are otherwise uninitialised.
 * @filler: callback routine for filling a single page.
 * @data: private data for the callback routine.
 *
 * Hides the details of the LRU cache etc from the filesystems.
 */
int read_cache_pages(struct address_space *mapping, struct list_head *pages,
			int (*filler)(void *, struct page *), void *data)
{
	struct page *page;
	struct pagevec lru_pvec;
	int ret = 0;

	pagevec_init(&lru_pvec, 0);

	while (!list_empty(pages)) {
		page = list_to_page(pages);
		list_del(&page->lru);
		if (add_to_page_cache(page, mapping, page->index, GFP_KERNEL)) {
			page_cache_release(page);
			continue;
		}
		ret = filler(data, page);
		if (!pagevec_add(&lru_pvec, page))
			__pagevec_lru_add(&lru_pvec);
		if (ret) {
			put_pages_list(pages);
			break;
		}
		task_io_account_read(PAGE_CACHE_SIZE);
	}
	pagevec_lru_add(&lru_pvec);
	return ret;
}

EXPORT_SYMBOL(read_cache_pages);

static int read_pages(struct address_space *mapping, struct file *filp,
		struct list_head *pages, unsigned nr_pages)
{
	unsigned page_idx;
	struct pagevec lru_pvec;
	int ret;

	if (mapping->a_ops->readpages) {
		ret = mapping->a_ops->readpages(filp, mapping, pages, nr_pages);
		/* Clean up the remaining pages */
		put_pages_list(pages);
		goto out;
	}

	pagevec_init(&lru_pvec, 0);
	for (page_idx = 0; page_idx < nr_pages; page_idx++) {
		struct page *page = list_to_page(pages);
		list_del(&page->lru);
		if (!add_to_page_cache(page, mapping,
					page->index, GFP_KERNEL)) {
			mapping->a_ops->readpage(filp, page);
			if (!pagevec_add(&lru_pvec, page))
				__pagevec_lru_add(&lru_pvec);
		} else
			page_cache_release(page);
	}
	pagevec_lru_add(&lru_pvec);
	ret = 0;
out:
	return ret;
}

/*
 * do_page_cache_readahead actually reads a chunk of disk.  It allocates all
 * the pages first, then submits them all for I/O. This avoids the very bad
 * behaviour which would occur if page allocations are causing VM writeback.
 * We really don't want to intermingle reads and writes like that.
 *
 * Returns the number of pages requested, or the maximum amount of I/O allowed.
 *
 * do_page_cache_readahead() returns -1 if it encountered request queue
 * congestion.
 */
static int
__do_page_cache_readahead(struct address_space *mapping, struct file *filp,
			pgoff_t offset, unsigned long nr_to_read,
			unsigned long lookahead_size)
{
	struct inode *inode = mapping->host;
	struct page *page;
	unsigned long end_index;	/* The last page we want to read */
	LIST_HEAD(page_pool);
	int page_idx;
	int ret = 0;
	loff_t isize = i_size_read(inode);

	if (isize == 0)
		goto out;

	end_index = ((isize - 1) >> PAGE_CACHE_SHIFT);

	/*
	 * Preallocate as many pages as we will need.
	 */
	read_lock_irq(&mapping->tree_lock);
	for (page_idx = 0; page_idx < nr_to_read; page_idx++) {
		pgoff_t page_offset = offset + page_idx;

		if (page_offset > end_index)
			break;

		page = radix_tree_lookup(&mapping->page_tree, page_offset);
		if (page)
			continue;

		read_unlock_irq(&mapping->tree_lock);
		page = page_cache_alloc_cold(mapping);
		read_lock_irq(&mapping->tree_lock);
		if (!page)
			break;
		page->index = page_offset;
		list_add(&page->lru, &page_pool);
		if (page_idx == nr_to_read - lookahead_size)
			SetPageReadahead(page);
		ret++;
	}
	read_unlock_irq(&mapping->tree_lock);

	/*
	 * Now start the IO.  We ignore I/O errors - if the page is not
	 * uptodate then the caller will launch readpage again, and
	 * will then handle the error.
	 */
	if (ret)
		read_pages(mapping, filp, &page_pool, ret);
	BUG_ON(!list_empty(&page_pool));
out:
	return ret;
}

/*
 * Chunk the readahead into 2 megabyte units, so that we don't pin too much
 * memory at once.
 */
int force_page_cache_readahead(struct address_space *mapping, struct file *filp,
		pgoff_t offset, unsigned long nr_to_read)
{
	int ret = 0;

	if (unlikely(!mapping->a_ops->readpage && !mapping->a_ops->readpages))
		return -EINVAL;

	while (nr_to_read) {
		int err;

		unsigned long this_chunk = (2 * 1024 * 1024) / PAGE_CACHE_SIZE;

		if (this_chunk > nr_to_read)
			this_chunk = nr_to_read;
		err = __do_page_cache_readahead(mapping, filp,
						offset, this_chunk, 0);
		if (err < 0) {
			ret = err;
			break;
		}
		ret += err;
		offset += this_chunk;
		nr_to_read -= this_chunk;
	}
	return ret;
}

/*
 * This version skips the IO if the queue is read-congested, and will tell the
 * block layer to abandon the readahead if request allocation would block.
 *
 * force_page_cache_readahead() will ignore queue congestion and will block on
 * request queues.
 */
int do_page_cache_readahead(struct address_space *mapping, struct file *filp,
			pgoff_t offset, unsigned long nr_to_read)
{
	if (bdi_read_congested(mapping->backing_dev_info))
		return -1;

	return __do_page_cache_readahead(mapping, filp, offset, nr_to_read, 0);
}

/*
 * Given a desired number of PAGE_CACHE_SIZE readahead pages, return a
 * sensible upper limit.
 */
unsigned long max_sane_readahead(unsigned long nr)
{
	return min(nr, (node_page_state(numa_node_id(), NR_INACTIVE)
		+ node_page_state(numa_node_id(), NR_FREE_PAGES)) / 2);
}

/*
 * Submit IO for the read-ahead request in file_ra_state.
 */
unsigned long ra_submit(struct file_ra_state *ra,
		       struct address_space *mapping, struct file *filp)
{
	unsigned long ra_size;
	unsigned long la_size;
	int actual;

	ra_size = ra_readahead_size(ra);
	la_size = ra_lookahead_size(ra);
	actual = __do_page_cache_readahead(mapping, filp,
					ra->ra_index, ra_size, la_size);

	return actual;
}
EXPORT_SYMBOL_GPL(ra_submit);

/*
 * Set the initial window size, round to next power of 2 and square
 * for small size, x 4 for medium, and x 2 for large
 * for 128k (32 page) max ra
 * 1-8 page = 32k initial, > 8 page = 128k initial
 */
static unsigned long get_init