From d765147bc4fecfe7df3be9353986f84e37d28450 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 11 Nov 2019 12:01:21 +0100 Subject: [PATCH] 4.14-stable patches added patches: lib-scatterlist-introduce-sgl_alloc-and-sgl_free.patch --- ...ist-introduce-sgl_alloc-and-sgl_free.patch | 175 ++++++++++++++++++ queue-4.14/series | 1 + ...-urb-null-transfer-buffer-error-path.patch | 8 +- ...-support-to-vhci-hcd-and-stub-driver.patch | 15 +- 4 files changed, 194 insertions(+), 5 deletions(-) create mode 100644 queue-4.14/lib-scatterlist-introduce-sgl_alloc-and-sgl_free.patch diff --git a/queue-4.14/lib-scatterlist-introduce-sgl_alloc-and-sgl_free.patch b/queue-4.14/lib-scatterlist-introduce-sgl_alloc-and-sgl_free.patch new file mode 100644 index 00000000000..cad2c79ba4c --- /dev/null +++ b/queue-4.14/lib-scatterlist-introduce-sgl_alloc-and-sgl_free.patch @@ -0,0 +1,175 @@ +From e80a0af4759a164214f02da157a3800753ce135f Mon Sep 17 00:00:00 2001 +From: Bart Van Assche +Date: Fri, 5 Jan 2018 08:26:46 -0800 +Subject: lib/scatterlist: Introduce sgl_alloc() and sgl_free() + +From: Bart Van Assche + +commit e80a0af4759a164214f02da157a3800753ce135f upstream. + +Many kernel drivers contain code that allocates and frees both a +scatterlist and the pages that populate that scatterlist. +Introduce functions in lib/scatterlist.c that perform these tasks +instead of duplicating this functionality in multiple drivers. +Only include these functions in the build if CONFIG_SGL_ALLOC=y +to avoid that the kernel size increases if this functionality is +not used. + +Signed-off-by: Bart Van Assche +Reviewed-by: Hannes Reinecke +Reviewed-by: Johannes Thumshirn +Signed-off-by: Jens Axboe +Signed-off-by: Greg Kroah-Hartman + +--- + include/linux/scatterlist.h | 10 ++++ + lib/Kconfig | 4 + + lib/scatterlist.c | 105 ++++++++++++++++++++++++++++++++++++++++++++ + 3 files changed, 119 insertions(+) + +--- a/include/linux/scatterlist.h ++++ b/include/linux/scatterlist.h +@@ -267,6 +267,16 @@ int sg_alloc_table_from_pages(struct sg_ + unsigned long offset, unsigned long size, + gfp_t gfp_mask); + ++#ifdef CONFIG_SGL_ALLOC ++struct scatterlist *sgl_alloc_order(unsigned long long length, ++ unsigned int order, bool chainable, ++ gfp_t gfp, unsigned int *nent_p); ++struct scatterlist *sgl_alloc(unsigned long long length, gfp_t gfp, ++ unsigned int *nent_p); ++void sgl_free_order(struct scatterlist *sgl, int order); ++void sgl_free(struct scatterlist *sgl); ++#endif /* CONFIG_SGL_ALLOC */ ++ + size_t sg_copy_buffer(struct scatterlist *sgl, unsigned int nents, void *buf, + size_t buflen, off_t skip, bool to_buffer); + +--- a/lib/Kconfig ++++ b/lib/Kconfig +@@ -413,6 +413,10 @@ config HAS_DMA + depends on !NO_DMA + default y + ++config SGL_ALLOC ++ bool ++ default n ++ + config DMA_NOOP_OPS + bool + depends on HAS_DMA && (!64BIT || ARCH_DMA_ADDR_T_64BIT) +--- a/lib/scatterlist.c ++++ b/lib/scatterlist.c +@@ -433,6 +433,111 @@ int sg_alloc_table_from_pages(struct sg_ + } + EXPORT_SYMBOL(sg_alloc_table_from_pages); + ++#ifdef CONFIG_SGL_ALLOC ++ ++/** ++ * sgl_alloc_order - allocate a scatterlist and its pages ++ * @length: Length in bytes of the scatterlist. Must be at least one ++ * @order: Second argument for alloc_pages() ++ * @chainable: Whether or not to allocate an extra element in the scatterlist ++ * for scatterlist chaining purposes ++ * @gfp: Memory allocation flags ++ * @nent_p: [out] Number of entries in the scatterlist that have pages ++ * ++ * Returns: A pointer to an initialized scatterlist or %NULL upon failure. ++ */ ++struct scatterlist *sgl_alloc_order(unsigned long long length, ++ unsigned int order, bool chainable, ++ gfp_t gfp, unsigned int *nent_p) ++{ ++ struct scatterlist *sgl, *sg; ++ struct page *page; ++ unsigned int nent, nalloc; ++ u32 elem_len; ++ ++ nent = round_up(length, PAGE_SIZE << order) >> (PAGE_SHIFT + order); ++ /* Check for integer overflow */ ++ if (length > (nent << (PAGE_SHIFT + order))) ++ return NULL; ++ nalloc = nent; ++ if (chainable) { ++ /* Check for integer overflow */ ++ if (nalloc + 1 < nalloc) ++ return NULL; ++ nalloc++; ++ } ++ sgl = kmalloc_array(nalloc, sizeof(struct scatterlist), ++ (gfp & ~GFP_DMA) | __GFP_ZERO); ++ if (!sgl) ++ return NULL; ++ ++ sg_init_table(sgl, nent); ++ sg = sgl; ++ while (length) { ++ elem_len = min_t(u64, length, PAGE_SIZE << order); ++ page = alloc_pages(gfp, order); ++ if (!page) { ++ sgl_free(sgl); ++ return NULL; ++ } ++ ++ sg_set_page(sg, page, elem_len, 0); ++ length -= elem_len; ++ sg = sg_next(sg); ++ } ++ WARN_ON_ONCE(sg); ++ if (nent_p) ++ *nent_p = nent; ++ return sgl; ++} ++EXPORT_SYMBOL(sgl_alloc_order); ++ ++/** ++ * sgl_alloc - allocate a scatterlist and its pages ++ * @length: Length in bytes of the scatterlist ++ * @gfp: Memory allocation flags ++ * @nent_p: [out] Number of entries in the scatterlist ++ * ++ * Returns: A pointer to an initialized scatterlist or %NULL upon failure. ++ */ ++struct scatterlist *sgl_alloc(unsigned long long length, gfp_t gfp, ++ unsigned int *nent_p) ++{ ++ return sgl_alloc_order(length, 0, false, gfp, nent_p); ++} ++EXPORT_SYMBOL(sgl_alloc); ++ ++/** ++ * sgl_free_order - free a scatterlist and its pages ++ * @sgl: Scatterlist with one or more elements ++ * @order: Second argument for __free_pages() ++ */ ++void sgl_free_order(struct scatterlist *sgl, int order) ++{ ++ struct scatterlist *sg; ++ struct page *page; ++ ++ for (sg = sgl; sg; sg = sg_next(sg)) { ++ page = sg_page(sg); ++ if (page) ++ __free_pages(page, order); ++ } ++ kfree(sgl); ++} ++EXPORT_SYMBOL(sgl_free_order); ++ ++/** ++ * sgl_free - free a scatterlist and its pages ++ * @sgl: Scatterlist with one or more elements ++ */ ++void sgl_free(struct scatterlist *sgl) ++{ ++ sgl_free_order(sgl, 0); ++} ++EXPORT_SYMBOL(sgl_free); ++ ++#endif /* CONFIG_SGL_ALLOC */ ++ + void __sg_page_iter_start(struct sg_page_iter *piter, + struct scatterlist *sglist, unsigned int nents, + unsigned long pgoffset) diff --git a/queue-4.14/series b/queue-4.14/series index 494bbc18d94..88f9993d8d0 100644 --- a/queue-4.14/series +++ b/queue-4.14/series @@ -61,6 +61,7 @@ cpufreq-ti-cpufreq-add-missing-of_node_put.patch arm-dts-dra7-disable-usb-metastability-workaround-for-usb2.patch sched-fair-fix-low-cpu-usage-with-high-throttling-by-removing-expiration-of-cpu-local-slices.patch sched-fair-fix-wunused-but-set-variable-warnings.patch +lib-scatterlist-introduce-sgl_alloc-and-sgl_free.patch usbip-fix-vhci_urb_enqueue-urb-null-transfer-buffer-error-path.patch usbip-stub_rx-fix-static-checker-warning-on-unnecessary-checks.patch usbip-implement-sg-support-to-vhci-hcd-and-stub-driver.patch diff --git a/queue-4.14/usbip-fix-vhci_urb_enqueue-urb-null-transfer-buffer-error-path.patch b/queue-4.14/usbip-fix-vhci_urb_enqueue-urb-null-transfer-buffer-error-path.patch index e2968b3c8d2..2888129d61a 100644 --- a/queue-4.14/usbip-fix-vhci_urb_enqueue-urb-null-transfer-buffer-error-path.patch +++ b/queue-4.14/usbip-fix-vhci_urb_enqueue-urb-null-transfer-buffer-error-path.patch @@ -14,11 +14,13 @@ Signed-off-by: Shuah Khan Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman -diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c -index 1e592ec94ba4..f46ee1fefe02 100644 +--- + drivers/usb/usbip/vhci_hcd.c | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + --- a/drivers/usb/usbip/vhci_hcd.c +++ b/drivers/usb/usbip/vhci_hcd.c -@@ -702,8 +702,10 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag +@@ -716,8 +716,10 @@ static int vhci_urb_enqueue(struct usb_h } vdev = &vhci_hcd->vdev[portnum-1]; diff --git a/queue-4.14/usbip-implement-sg-support-to-vhci-hcd-and-stub-driver.patch b/queue-4.14/usbip-implement-sg-support-to-vhci-hcd-and-stub-driver.patch index cea73a38ab2..2e219090457 100644 --- a/queue-4.14/usbip-implement-sg-support-to-vhci-hcd-and-stub-driver.patch +++ b/queue-4.14/usbip-implement-sg-support-to-vhci-hcd-and-stub-driver.patch @@ -143,6 +143,7 @@ Link: https://lore.kernel.org/r/20190828032741.12234-1-suwan.kim027@gmail.com Signed-off-by: Greg Kroah-Hartman --- + drivers/usb/usbip/Kconfig | 1 drivers/usb/usbip/stub.h | 7 + drivers/usb/usbip/stub_main.c | 57 ++++++++--- drivers/usb/usbip/stub_rx.c | 202 +++++++++++++++++++++++++++------------ @@ -151,8 +152,18 @@ Signed-off-by: Greg Kroah-Hartman drivers/usb/usbip/vhci_hcd.c | 12 ++ drivers/usb/usbip/vhci_rx.c | 3 drivers/usb/usbip/vhci_tx.c | 66 ++++++++++-- - 8 files changed, 379 insertions(+), 126 deletions(-) - + 9 files changed, 380 insertions(+), 126 deletions(-) + +--- a/drivers/usb/usbip/Kconfig ++++ b/drivers/usb/usbip/Kconfig +@@ -2,6 +2,7 @@ config USBIP_CORE + tristate "USB/IP support" + depends on NET + select USB_COMMON ++ select SGL_ALLOC + ---help--- + This enables pushing USB packets over IP to allow remote + machines direct access to USB devices. It provides the --- a/drivers/usb/usbip/stub.h +++ b/drivers/usb/usbip/stub.h @@ -66,7 +66,11 @@ struct stub_priv { -- 2.47.3