* [PATCH 0/5] staging: gasket: fixes and cleanups @ 2018-07-28 5:21 Todd Poynor 2018-07-28 5:21 ` [PATCH 1/5] staging: gasket: sysfs: remove check for refcount already zero Todd Poynor ` (4 more replies) 0 siblings, 5 replies; 7+ messages in thread From: Todd Poynor @ 2018-07-28 5:21 UTC (permalink / raw) To: Rob Springer, John Joseph, Ben Chan, Greg Kroah-Hartman Cc: devel, linux-kernel, Todd Poynor From: Todd Poynor <toddpoynor@google.com> The fun continues with gasket+apex: remove dead code and unnecessary stuff, fixup apex PCI class for devices that advertise class 0 (undefined), and make sure the struct device doesn't go away on us. Most of these from review comments of previous patch series. Todd Poynor (5): staging: gasket: sysfs: remove check for refcount already zero staging: gasket: apex: fixup undefined PCI class staging: gasket: sysfs: remove unnecessary NULL check on device ptr staging: gasket: page table: remove code for "no dma_ops" staging: gasket: core: hold reference on device kobj while in use drivers/staging/gasket/apex_driver.c | 7 +++ drivers/staging/gasket/gasket_core.c | 5 +- drivers/staging/gasket/gasket_page_table.c | 58 +++------------------- drivers/staging/gasket/gasket_page_table.h | 3 +- drivers/staging/gasket/gasket_sysfs.c | 7 --- 5 files changed, 17 insertions(+), 63 deletions(-) -- 2.18.0.345.g5c9ce644c3-goog ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/5] staging: gasket: sysfs: remove check for refcount already zero 2018-07-28 5:21 [PATCH 0/5] staging: gasket: fixes and cleanups Todd Poynor @ 2018-07-28 5:21 ` Todd Poynor 2018-07-28 5:21 ` [PATCH 2/5] staging: gasket: apex: fixup undefined PCI class Todd Poynor ` (3 subsequent siblings) 4 siblings, 0 replies; 7+ messages in thread From: Todd Poynor @ 2018-07-28 5:21 UTC (permalink / raw) To: Rob Springer, John Joseph, Ben Chan, Greg Kroah-Hartman Cc: devel, linux-kernel, Todd Poynor From: Todd Poynor <toddpoynor@google.com> Remove the check for refcount already zero, which shouldn't be necessary. Signed-off-by: Todd Poynor <toddpoynor@google.com> --- drivers/staging/gasket/gasket_sysfs.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/staging/gasket/gasket_sysfs.c b/drivers/staging/gasket/gasket_sysfs.c index 418b81797e638..2d8647de697cd 100644 --- a/drivers/staging/gasket/gasket_sysfs.c +++ b/drivers/staging/gasket/gasket_sysfs.c @@ -111,8 +111,6 @@ static void put_mapping(struct gasket_sysfs_mapping *mapping) } mutex_lock(&mapping->mutex); - if (refcount_read(&mapping->refcount.refcount) == 0) - dev_err(mapping->device, "Refcount is already 0\n"); if (kref_put(&mapping->refcount, release_entry)) { dev_dbg(mapping->device, "Removing Gasket sysfs mapping\n"); /* -- 2.18.0.345.g5c9ce644c3-goog ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/5] staging: gasket: apex: fixup undefined PCI class 2018-07-28 5:21 [PATCH 0/5] staging: gasket: fixes and cleanups Todd Poynor 2018-07-28 5:21 ` [PATCH 1/5] staging: gasket: sysfs: remove check for refcount already zero Todd Poynor @ 2018-07-28 5:21 ` Todd Poynor 2018-07-28 5:21 ` [PATCH 3/5] staging: gasket: sysfs: remove unnecessary NULL check on device ptr Todd Poynor ` (2 subsequent siblings) 4 siblings, 0 replies; 7+ messages in thread From: Todd Poynor @ 2018-07-28 5:21 UTC (permalink / raw) To: Rob Springer, John Joseph, Ben Chan, Greg Kroah-Hartman Cc: devel, linux-kernel, Todd Poynor From: Todd Poynor <toddpoynor@google.com> Apex chips with class 0 (PCI_CLASS_NOT_DEFINED) fixed up to PCI_CLASS_SYSTEM_OTHER to enable PCI resource assignments. Signed-off-by: Todd Poynor <toddpoynor@google.com> --- drivers/staging/gasket/apex_driver.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/staging/gasket/apex_driver.c b/drivers/staging/gasket/apex_driver.c index 73fc2683a834d..ab466d49608a7 100644 --- a/drivers/staging/gasket/apex_driver.c +++ b/drivers/staging/gasket/apex_driver.c @@ -739,3 +739,10 @@ static ssize_t sysfs_show( gasket_sysfs_put_device_data(device, gasket_dev); return ret; } + +static void apex_pci_fixup_class(struct pci_dev *pdev) +{ + pdev->class = (PCI_CLASS_SYSTEM_OTHER << 8) | pdev->class; +} +DECLARE_PCI_FIXUP_CLASS_HEADER(APEX_PCI_VENDOR_ID, APEX_PCI_DEVICE_ID, + PCI_CLASS_NOT_DEFINED, 8, apex_pci_fixup_class); -- 2.18.0.345.g5c9ce644c3-goog ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/5] staging: gasket: sysfs: remove unnecessary NULL check on device ptr 2018-07-28 5:21 [PATCH 0/5] staging: gasket: fixes and cleanups Todd Poynor 2018-07-28 5:21 ` [PATCH 1/5] staging: gasket: sysfs: remove check for refcount already zero Todd Poynor 2018-07-28 5:21 ` [PATCH 2/5] staging: gasket: apex: fixup undefined PCI class Todd Poynor @ 2018-07-28 5:21 ` Todd Poynor 2018-07-28 5:21 ` [PATCH 4/5] staging: gasket: page table: remove code for "no dma_ops" Todd Poynor 2018-07-28 5:22 ` [PATCH 5/5] staging: gasket: core: hold reference on device kobj while in use Todd Poynor 4 siblings, 0 replies; 7+ messages in thread From: Todd Poynor @ 2018-07-28 5:21 UTC (permalink / raw) To: Rob Springer, John Joseph, Ben Chan, Greg Kroah-Hartman Cc: devel, linux-kernel, Todd Poynor From: Todd Poynor <toddpoynor@google.com> The device pointer passed into get_mapping() will never be NULL; the check is unnecessary. Reported-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Todd Poynor <toddpoynor@google.com> --- drivers/staging/gasket/gasket_sysfs.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/staging/gasket/gasket_sysfs.c b/drivers/staging/gasket/gasket_sysfs.c index 2d8647de697cd..da972ce0e0db0 100644 --- a/drivers/staging/gasket/gasket_sysfs.c +++ b/drivers/staging/gasket/gasket_sysfs.c @@ -67,11 +67,6 @@ static struct gasket_sysfs_mapping *get_mapping(struct device *device) { int i; - if (!device) { - pr_debug("%s: Received NULL device\n", __func__); - return NULL; - } - for (i = 0; i < GASKET_SYSFS_NUM_MAPPINGS; i++) { mutex_lock(&dev_mappings[i].mutex); if (dev_mappings[i].device == device) { -- 2.18.0.345.g5c9ce644c3-goog ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/5] staging: gasket: page table: remove code for "no dma_ops" 2018-07-28 5:21 [PATCH 0/5] staging: gasket: fixes and cleanups Todd Poynor ` (2 preceding siblings ...) 2018-07-28 5:21 ` [PATCH 3/5] staging: gasket: sysfs: remove unnecessary NULL check on device ptr Todd Poynor @ 2018-07-28 5:21 ` Todd Poynor 2018-07-28 5:22 ` [PATCH 5/5] staging: gasket: core: hold reference on device kobj while in use Todd Poynor 4 siblings, 0 replies; 7+ messages in thread From: Todd Poynor @ 2018-07-28 5:21 UTC (permalink / raw) To: Rob Springer, John Joseph, Ben Chan, Greg Kroah-Hartman Cc: devel, linux-kernel, Todd Poynor From: Todd Poynor <toddpoynor@google.com> Remove code with TODOs on it for working around apparent problems previously seen in a qemu environment where dma_ops was not set correctly. There is no user of this in the current code. Signed-off-by: Todd Poynor <toddpoynor@google.com> --- drivers/staging/gasket/gasket_core.c | 2 +- drivers/staging/gasket/gasket_page_table.c | 58 +++------------------- drivers/staging/gasket/gasket_page_table.h | 3 +- 3 files changed, 8 insertions(+), 55 deletions(-) diff --git a/drivers/staging/gasket/gasket_core.c b/drivers/staging/gasket/gasket_core.c index f44805c38159b..859a6df9e12df 100644 --- a/drivers/staging/gasket/gasket_core.c +++ b/drivers/staging/gasket/gasket_core.c @@ -916,7 +916,7 @@ static int gasket_enable_dev( &gasket_dev->bar_data[ driver_desc->page_table_bar_index], &driver_desc->page_table_configs[tbl_idx], - gasket_dev->dev, gasket_dev->pci_dev, true); + gasket_dev->dev, gasket_dev->pci_dev); if (ret) { dev_err(gasket_dev->dev, "Couldn't init page table %d: %d\n", diff --git a/drivers/staging/gasket/gasket_page_table.c b/drivers/staging/gasket/gasket_page_table.c index 32f1c1e10c7e2..722839603f20d 100644 --- a/drivers/staging/gasket/gasket_page_table.c +++ b/drivers/staging/gasket/gasket_page_table.c @@ -212,12 +212,6 @@ struct gasket_page_table { * gasket_mmap function, so user_virt belongs in the driver anyhow. */ struct gasket_coherent_page_entry *coherent_pages; - - /* - * Whether the page table uses arch specific dma_ops or - * whether the driver is supplying its own. - */ - bool dma_ops; }; /* Mapping declarations */ @@ -290,7 +284,7 @@ int gasket_page_table_init( struct gasket_page_table **ppg_tbl, const struct gasket_bar_data *bar_data, const struct gasket_page_table_config *page_table_config, - struct device *device, struct pci_dev *pci_dev, bool has_dma_ops) + struct device *device, struct pci_dev *pci_dev) { ulong bytes; struct gasket_page_table *pg_tbl; @@ -353,7 +347,6 @@ int gasket_page_table_init( bar_data->virt_base[page_table_config->extended_reg]); pg_tbl->device = device; pg_tbl->pci_dev = pci_dev; - pg_tbl->dma_ops = has_dma_ops; dev_dbg(device, "Page table initialized successfully\n"); @@ -759,33 +752,6 @@ static int gasket_map_extended_pages( return 0; } -/* - * TODO: dma_map_page() is not plugged properly when running under qemu. i.e. - * dma_ops are not set properly, which causes the kernel to assert. - * - * This temporary hack allows the driver to work on qemu, but need to be fixed: - * - either manually set the dma_ops for the architecture (which incidentally - * can't be done in an out-of-tree module) - or get qemu to fill the device tree - * properly so as linux plug the proper dma_ops or so as the driver can detect - * that it is runnig on qemu - */ -static inline dma_addr_t _no_op_dma_map_page( - struct device *dev, struct page *page, size_t offset, size_t size, - enum dma_data_direction dir) -{ - /* - * struct dma_map_ops *ops = get_dma_ops(dev); - * dma_addr_t addr; - * - * kmemcheck_mark_initialized(page_address(page) + offset, size); - * BUG_ON(!valid_dma_direction(dir)); - * addr = ops->map_page(dev, page, offset, size, dir, NULL); - * debug_dma_map_page(dev, page, offset, size, dir, addr, false); - */ - - return page_to_phys(page); -} - /* * Get and map last level page table buffers. * @pg_tbl: Gasket page table pointer. @@ -856,16 +822,9 @@ static int gasket_perform_mapping( ptes[i].offset = offset; /* Map the page into DMA space. */ - if (pg_tbl->dma_ops) { - /* hook in to kernel map functions */ - ptes[i].dma_addr = dma_map_page(pg_tbl->device, - page, 0, PAGE_SIZE, DMA_BIDIRECTIONAL); - } else { - ptes[i].dma_addr = _no_op_dma_map_page( - pg_tbl->device, page, 0, PAGE_SIZE, - DMA_BIDIRECTIONAL); - } - + ptes[i].dma_addr = + dma_map_page(pg_tbl->device, page, 0, PAGE_SIZE, + DMA_BIDIRECTIONAL); dev_dbg(pg_tbl->device, "%s i %d pte %p pfn %p -> mapped %llx\n", __func__, i, &ptes[i], @@ -1042,13 +1001,8 @@ static int gasket_alloc_extended_subtable( } /* Map the page into DMA space. */ - if (pg_tbl->dma_ops) { - pte->dma_addr = dma_map_page(pg_tbl->device, pte->page, 0, - PAGE_SIZE, DMA_BIDIRECTIONAL); - } else { - pte->dma_addr = _no_op_dma_map_page(pg_tbl->device, pte->page, - 0, PAGE_SIZE, DMA_BIDIRECTIONAL); - } + pte->dma_addr = dma_map_page(pg_tbl->device, pte->page, 0, PAGE_SIZE, + DMA_BIDIRECTIONAL); /* Wait until the page is mapped. */ mb(); diff --git a/drivers/staging/gasket/gasket_page_table.h b/drivers/staging/gasket/gasket_page_table.h index 0e8afdb8c1139..765588649365f 100644 --- a/drivers/staging/gasket/gasket_page_table.h +++ b/drivers/staging/gasket/gasket_page_table.h @@ -37,7 +37,6 @@ struct gasket_page_table; * translation table. * @device: Device structure for the underlying device. Only used for logging. * @pci_dev: PCI system descriptor for the underlying device. - * @bool has_dma_ops: Whether the page table uses arch specific dma_ops or * whether the driver will supply its own. * * Description: Allocates and initializes data to track address translation - @@ -51,7 +50,7 @@ int gasket_page_table_init( struct gasket_page_table **ppg_tbl, const struct gasket_bar_data *bar_data, const struct gasket_page_table_config *page_table_config, - struct device *device, struct pci_dev *pci_dev, bool dma_ops); + struct device *device, struct pci_dev *pci_dev); /* * Deallocate and cleanup page table data. -- 2.18.0.345.g5c9ce644c3-goog ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/5] staging: gasket: core: hold reference on device kobj while in use 2018-07-28 5:21 [PATCH 0/5] staging: gasket: fixes and cleanups Todd Poynor ` (3 preceding siblings ...) 2018-07-28 5:21 ` [PATCH 4/5] staging: gasket: page table: remove code for "no dma_ops" Todd Poynor @ 2018-07-28 5:22 ` Todd Poynor 2018-07-28 7:23 ` Greg Kroah-Hartman 4 siblings, 1 reply; 7+ messages in thread From: Todd Poynor @ 2018-07-28 5:22 UTC (permalink / raw) To: Rob Springer, John Joseph, Ben Chan, Greg Kroah-Hartman Cc: devel, linux-kernel, Todd Poynor From: Todd Poynor <toddpoynor@google.com> Hold a reference on the struct device kobject while a pointer to that device is in use by gasket. Reported-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Todd Poynor <toddpoynor@google.com> --- drivers/staging/gasket/gasket_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/staging/gasket/gasket_core.c b/drivers/staging/gasket/gasket_core.c index 859a6df9e12df..1dc7273e38734 100644 --- a/drivers/staging/gasket/gasket_core.c +++ b/drivers/staging/gasket/gasket_core.c @@ -449,6 +449,7 @@ static int gasket_alloc_dev( gasket_dev->dev_idx = dev_idx; snprintf(gasket_dev->kobj_name, GASKET_NAME_MAX, "%s", kobj_name); gasket_dev->dev = parent; + kobject_get(&gasket_dev->dev->kobj); /* gasket_bar_data is uninitialized. */ gasket_dev->num_page_tables = driver_desc->num_page_tables; /* max_page_table_size and *page table are uninit'ed */ @@ -487,7 +488,7 @@ static void gasket_free_dev(struct gasket_dev *gasket_dev) mutex_lock(&internal_desc->mutex); internal_desc->devs[gasket_dev->dev_idx] = NULL; mutex_unlock(&internal_desc->mutex); - + kobject_put(&gasket_dev->dev->kobj); kfree(gasket_dev); } -- 2.18.0.345.g5c9ce644c3-goog ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 5/5] staging: gasket: core: hold reference on device kobj while in use 2018-07-28 5:22 ` [PATCH 5/5] staging: gasket: core: hold reference on device kobj while in use Todd Poynor @ 2018-07-28 7:23 ` Greg Kroah-Hartman 0 siblings, 0 replies; 7+ messages in thread From: Greg Kroah-Hartman @ 2018-07-28 7:23 UTC (permalink / raw) To: Todd Poynor Cc: Rob Springer, John Joseph, Ben Chan, devel, Todd Poynor, linux-kernel On Fri, Jul 27, 2018 at 10:22:00PM -0700, Todd Poynor wrote: > From: Todd Poynor <toddpoynor@google.com> > > Hold a reference on the struct device kobject while a pointer to that > device is in use by gasket. > > Reported-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> > Signed-off-by: Todd Poynor <toddpoynor@google.com> > --- > drivers/staging/gasket/gasket_core.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/staging/gasket/gasket_core.c b/drivers/staging/gasket/gasket_core.c > index 859a6df9e12df..1dc7273e38734 100644 > --- a/drivers/staging/gasket/gasket_core.c > +++ b/drivers/staging/gasket/gasket_core.c > @@ -449,6 +449,7 @@ static int gasket_alloc_dev( > gasket_dev->dev_idx = dev_idx; > snprintf(gasket_dev->kobj_name, GASKET_NAME_MAX, "%s", kobj_name); > gasket_dev->dev = parent; > + kobject_get(&gasket_dev->dev->kobj); Hint, if you are a driver, working with devices, you should never call a kobject_* or sysfs_* call. If you are, you are doing something really wrong and odd and should seriously reconsider it. No driver should ever be touching a "raw" kobject. For this case, get_device()/put_device() is what you should be using. thanks, greg k-h ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-07-28 7:23 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-07-28 5:21 [PATCH 0/5] staging: gasket: fixes and cleanups Todd Poynor 2018-07-28 5:21 ` [PATCH 1/5] staging: gasket: sysfs: remove check for refcount already zero Todd Poynor 2018-07-28 5:21 ` [PATCH 2/5] staging: gasket: apex: fixup undefined PCI class Todd Poynor 2018-07-28 5:21 ` [PATCH 3/5] staging: gasket: sysfs: remove unnecessary NULL check on device ptr Todd Poynor 2018-07-28 5:21 ` [PATCH 4/5] staging: gasket: page table: remove code for "no dma_ops" Todd Poynor 2018-07-28 5:22 ` [PATCH 5/5] staging: gasket: core: hold reference on device kobj while in use Todd Poynor 2018-07-28 7:23 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).