Skip to content

Commit 5f153b6

Browse files
committed
Merge tag 'ntb-6.12' of https://github.com/jonmason/ntb
Pull PCIe non-transparent bridge updates from Jon Mason: "Bug fixes for intel ntb driver debugfs, use after free in switchtec driver, ntb transport rx ring buffers. Also, cleanups in printks, kernel-docs, and idt driver comment" * tag 'ntb-6.12' of https://github.com/jonmason/ntb: ntb: Force physically contiguous allocation of rx ring buffers ntb: ntb_hw_switchtec: Fix use after free vulnerability in switchtec_ntb_remove due to race condition ntb: idt: Fix the cacography in ntb_hw_idt.c NTB: epf: don't misuse kernel-doc marker NTB: ntb_transport: fix all kernel-doc warnings ntb: Constify struct bus_type ntb_perf: Fix printk format ntb: intel: Fix the NULL vs IS_ERR() bug for debugfs_create_dir()
2 parents d7dfb07 + 061a785 commit 5f153b6

File tree

7 files changed

+31
-15
lines changed

7 files changed

+31
-15
lines changed

drivers/ntb/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ MODULE_VERSION(DRIVER_VERSION);
7272
MODULE_AUTHOR(DRIVER_AUTHOR);
7373
MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
7474

75-
static struct bus_type ntb_bus;
75+
static const struct bus_type ntb_bus;
7676
static void ntb_dev_release(struct device *dev);
7777

7878
int __ntb_register_client(struct ntb_client *client, struct module *mod,
@@ -298,7 +298,7 @@ static void ntb_dev_release(struct device *dev)
298298
complete(&ntb->released);
299299
}
300300

301-
static struct bus_type ntb_bus = {
301+
static const struct bus_type ntb_bus = {
302302
.name = "ntb",
303303
.probe = ntb_probe,
304304
.remove = ntb_remove,

drivers/ntb/hw/epf/ntb_hw_epf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: GPL-2.0
2-
/**
2+
/*
33
* Host side endpoint driver to implement Non-Transparent Bridge functionality
44
*
55
* Copyright (C) 2020 Texas Instruments

drivers/ntb/hw/idt/ntb_hw_idt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2547,7 +2547,7 @@ static void idt_deinit_dbgfs(struct idt_ntb_dev *ndev)
25472547
*/
25482548

25492549
/*
2550-
* idt_check_setup() - Check whether the IDT PCIe-swtich is properly
2550+
* idt_check_setup() - Check whether the IDT PCIe-switch is properly
25512551
* pre-initialized
25522552
* @pdev: Pointer to the PCI device descriptor
25532553
*

drivers/ntb/hw/intel/ntb_hw_gen1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ static void ndev_init_debugfs(struct intel_ntb_dev *ndev)
778778
ndev->debugfs_dir =
779779
debugfs_create_dir(pci_name(ndev->ntb.pdev),
780780
debugfs_dir);
781-
if (!ndev->debugfs_dir)
781+
if (IS_ERR(ndev->debugfs_dir))
782782
ndev->debugfs_info = NULL;
783783
else
784784
ndev->debugfs_info =

drivers/ntb/hw/mscc/ntb_hw_switchtec.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,7 @@ static void switchtec_ntb_remove(struct device *dev)
15541554
switchtec_ntb_deinit_db_msg_irq(sndev);
15551555
switchtec_ntb_deinit_shared_mw(sndev);
15561556
switchtec_ntb_deinit_crosslink(sndev);
1557+
cancel_work_sync(&sndev->check_link_status_work);
15571558
kfree(sndev);
15581559
dev_info(dev, "ntb device unregistered\n");
15591560
}

drivers/ntb/ntb_transport.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ static void ntb_transport_bus_remove(struct device *dev)
314314
put_device(dev);
315315
}
316316

317-
static struct bus_type ntb_transport_bus = {
317+
static const struct bus_type ntb_transport_bus = {
318318
.name = "ntb_transport",
319319
.match = ntb_transport_bus_match,
320320
.probe = ntb_transport_bus_probe,
@@ -377,6 +377,8 @@ EXPORT_SYMBOL_GPL(ntb_transport_unregister_client_dev);
377377
* @device_name: Name of NTB client device
378378
*
379379
* Register an NTB client device with the NTB transport layer
380+
*
381+
* Returns: %0 on success or -errno code on error
380382
*/
381383
int ntb_transport_register_client_dev(char *device_name)
382384
{
@@ -807,16 +809,29 @@ static void ntb_free_mw(struct ntb_transport_ctx *nt, int num_mw)
807809
}
808810

809811
static int ntb_alloc_mw_buffer(struct ntb_transport_mw *mw,
810-
struct device *dma_dev, size_t align)
812+
struct device *ntb_dev, size_t align)
811813
{
812814
dma_addr_t dma_addr;
813815
void *alloc_addr, *virt_addr;
814816
int rc;
815817

816-
alloc_addr = dma_alloc_coherent(dma_dev, mw->alloc_size,
817-
&dma_addr, GFP_KERNEL);
818+
/*
819+
* The buffer here is allocated against the NTB device. The reason to
820+
* use dma_alloc_*() call is to allocate a large IOVA contiguous buffer
821+
* backing the NTB BAR for the remote host to write to. During receive
822+
* processing, the data is being copied out of the receive buffer to
823+
* the kernel skbuff. When a DMA device is being used, dma_map_page()
824+
* is called on the kvaddr of the receive buffer (from dma_alloc_*())
825+
* and remapped against the DMA device. It appears to be a double
826+
* DMA mapping of buffers, but first is mapped to the NTB device and
827+
* second is to the DMA device. DMA_ATTR_FORCE_CONTIGUOUS is necessary
828+
* in order for the later dma_map_page() to not fail.
829+
*/
830+
alloc_addr = dma_alloc_attrs(ntb_dev, mw->alloc_size,
831+
&dma_addr, GFP_KERNEL,
832+
DMA_ATTR_FORCE_CONTIGUOUS);
818833
if (!alloc_addr) {
819-
dev_err(dma_dev, "Unable to alloc MW buff of size %zu\n",
834+
dev_err(ntb_dev, "Unable to alloc MW buff of size %zu\n",
820835
mw->alloc_size);
821836
return -ENOMEM;
822837
}
@@ -845,7 +860,7 @@ static int ntb_alloc_mw_buffer(struct ntb_transport_mw *mw,
845860
return 0;
846861

847862
err:
848-
dma_free_coherent(dma_dev, mw->alloc_size, alloc_addr, dma_addr);
863+
dma_free_coherent(ntb_dev, mw->alloc_size, alloc_addr, dma_addr);
849864

850865
return rc;
851866
}
@@ -1966,9 +1981,9 @@ static bool ntb_dma_filter_fn(struct dma_chan *chan, void *node)
19661981

19671982
/**
19681983
* ntb_transport_create_queue - Create a new NTB transport layer queue
1969-
* @rx_handler: receive callback function
1970-
* @tx_handler: transmit callback function
1971-
* @event_handler: event callback function
1984+
* @data: pointer for callback data
1985+
* @client_dev: &struct device pointer
1986+
* @handlers: pointer to various ntb queue (callback) handlers
19721987
*
19731988
* Create a new NTB transport layer queue and provide the queue with a callback
19741989
* routine for both transmit and receive. The receive callback routine will be

drivers/ntb/test/ntb_perf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ static ssize_t perf_dbgfs_read_info(struct file *filep, char __user *ubuf,
12271227
"\tOut buffer addr 0x%pK\n", peer->outbuf);
12281228

12291229
pos += scnprintf(buf + pos, buf_size - pos,
1230-
"\tOut buff phys addr %pa[p]\n", &peer->out_phys_addr);
1230+
"\tOut buff phys addr %pap\n", &peer->out_phys_addr);
12311231

12321232
pos += scnprintf(buf + pos, buf_size - pos,
12331233
"\tOut buffer size %pa\n", &peer->outbuf_size);

0 commit comments

Comments
 (0)