提交 de368ac6 编写于 作者: D Dave Jiang 提交者: Xiaochen Shen

dmaengine: idxd: fix group conf_dev lifetime

mainline inclusion
from mainline-v5.13
commit defe49f9
category: bugfix
bugzilla: https://gitee.com/openeuler/intel-kernel/issues/I596WO
CVE: NA

Intel-SIG: commit defe49f9 dmaengine: idxd: fix group conf_dev lifetime.
Incremental backporting patches for DSA/IAA on Intel Xeon platform.

--------------------------------

Remove devm_* allocation and fix group->conf_dev 'struct device'
lifetime. Address issues flagged by CONFIG_DEBUG_KOBJECT_RELEASE.
Add release functions in order to free the allocated memory at the
group->conf_dev destruction time.
Reported-by: NJason Gunthorpe <jgg@nvidia.com>
Fixes: bfe1d560 ("dmaengine: idxd: Init and probe for Intel data accelerators")
Signed-off-by: NDave Jiang <dave.jiang@intel.com>
Link: https://lore.kernel.org/r/161852987144.2203940.8830315575880047.stgit@djiang5-desk3.ch.intel.comSigned-off-by: NVinod Koul <vkoul@kernel.org>
Signed-off-by: NXiaochen Shen <xiaochen.shen@intel.com>
上级 f6ad9857
...@@ -659,7 +659,7 @@ static int idxd_groups_config_write(struct idxd_device *idxd) ...@@ -659,7 +659,7 @@ static int idxd_groups_config_write(struct idxd_device *idxd)
ioread32(idxd->reg_base + IDXD_GENCFG_OFFSET)); ioread32(idxd->reg_base + IDXD_GENCFG_OFFSET));
for (i = 0; i < idxd->max_groups; i++) { for (i = 0; i < idxd->max_groups; i++) {
struct idxd_group *group = &idxd->groups[i]; struct idxd_group *group = idxd->groups[i];
idxd_group_config_write(group); idxd_group_config_write(group);
} }
...@@ -754,7 +754,7 @@ static void idxd_group_flags_setup(struct idxd_device *idxd) ...@@ -754,7 +754,7 @@ static void idxd_group_flags_setup(struct idxd_device *idxd)
/* TC-A 0 and TC-B 1 should be defaults */ /* TC-A 0 and TC-B 1 should be defaults */
for (i = 0; i < idxd->max_groups; i++) { for (i = 0; i < idxd->max_groups; i++) {
struct idxd_group *group = &idxd->groups[i]; struct idxd_group *group = idxd->groups[i];
if (group->tc_a == -1) if (group->tc_a == -1)
group->tc_a = group->grpcfg.flags.tc_a = 0; group->tc_a = group->grpcfg.flags.tc_a = 0;
...@@ -781,7 +781,7 @@ static int idxd_engines_setup(struct idxd_device *idxd) ...@@ -781,7 +781,7 @@ static int idxd_engines_setup(struct idxd_device *idxd)
struct idxd_group *group; struct idxd_group *group;
for (i = 0; i < idxd->max_groups; i++) { for (i = 0; i < idxd->max_groups; i++) {
group = &idxd->groups[i]; group = idxd->groups[i];
group->grpcfg.engines = 0; group->grpcfg.engines = 0;
} }
...@@ -810,7 +810,7 @@ static int idxd_wqs_setup(struct idxd_device *idxd) ...@@ -810,7 +810,7 @@ static int idxd_wqs_setup(struct idxd_device *idxd)
struct device *dev = &idxd->pdev->dev; struct device *dev = &idxd->pdev->dev;
for (i = 0; i < idxd->max_groups; i++) { for (i = 0; i < idxd->max_groups; i++) {
group = &idxd->groups[i]; group = idxd->groups[i];
for (j = 0; j < 4; j++) for (j = 0; j < 4; j++)
group->grpcfg.wqs[j] = 0; group->grpcfg.wqs[j] = 0;
} }
......
...@@ -194,7 +194,7 @@ struct idxd_device { ...@@ -194,7 +194,7 @@ struct idxd_device {
spinlock_t dev_lock; /* spinlock for device */ spinlock_t dev_lock; /* spinlock for device */
struct completion *cmd_done; struct completion *cmd_done;
struct idxd_group *groups; struct idxd_group **groups;
struct idxd_wq **wqs; struct idxd_wq **wqs;
struct idxd_engine **engines; struct idxd_engine **engines;
...@@ -261,6 +261,7 @@ extern struct device_type dsa_device_type; ...@@ -261,6 +261,7 @@ extern struct device_type dsa_device_type;
extern struct device_type iax_device_type; extern struct device_type iax_device_type;
extern struct device_type idxd_wq_device_type; extern struct device_type idxd_wq_device_type;
extern struct device_type idxd_engine_device_type; extern struct device_type idxd_engine_device_type;
extern struct device_type idxd_group_device_type;
static inline bool is_dsa_dev(struct device *dev) static inline bool is_dsa_dev(struct device *dev)
{ {
......
...@@ -236,11 +236,54 @@ static int idxd_setup_engines(struct idxd_device *idxd) ...@@ -236,11 +236,54 @@ static int idxd_setup_engines(struct idxd_device *idxd)
return rc; return rc;
} }
static int idxd_setup_internals(struct idxd_device *idxd) static int idxd_setup_groups(struct idxd_device *idxd)
{ {
struct device *dev = &idxd->pdev->dev; struct device *dev = &idxd->pdev->dev;
struct idxd_group *group;
int i, rc; int i, rc;
idxd->groups = kcalloc_node(idxd->max_groups, sizeof(struct idxd_group *),
GFP_KERNEL, dev_to_node(dev));
if (!idxd->groups)
return -ENOMEM;
for (i = 0; i < idxd->max_groups; i++) {
group = kzalloc_node(sizeof(*group), GFP_KERNEL, dev_to_node(dev));
if (!group) {
rc = -ENOMEM;
goto err;
}
group->id = i;
group->idxd = idxd;
device_initialize(&group->conf_dev);
group->conf_dev.parent = &idxd->conf_dev;
group->conf_dev.bus = idxd_get_bus_type(idxd);
group->conf_dev.type = &idxd_group_device_type;
rc = dev_set_name(&group->conf_dev, "group%d.%d", idxd->id, group->id);
if (rc < 0) {
put_device(&group->conf_dev);
goto err;
}
idxd->groups[i] = group;
group->tc_a = -1;
group->tc_b = -1;
}
return 0;
err:
while (--i >= 0)
put_device(&idxd->groups[i]->conf_dev);
return rc;
}
static int idxd_setup_internals(struct idxd_device *idxd)
{
struct device *dev = &idxd->pdev->dev;
int rc, i;
init_waitqueue_head(&idxd->cmd_waitq); init_waitqueue_head(&idxd->cmd_waitq);
rc = idxd_setup_wqs(idxd); rc = idxd_setup_wqs(idxd);
...@@ -251,29 +294,22 @@ static int idxd_setup_internals(struct idxd_device *idxd) ...@@ -251,29 +294,22 @@ static int idxd_setup_internals(struct idxd_device *idxd)
if (rc < 0) if (rc < 0)
goto err_engine; goto err_engine;
idxd->groups = devm_kcalloc(dev, idxd->max_groups, rc = idxd_setup_groups(idxd);
sizeof(struct idxd_group), GFP_KERNEL); if (rc < 0)
if (!idxd->groups) { goto err_group;
rc = -ENOMEM;
goto err;
}
for (i = 0; i < idxd->max_groups; i++) {
idxd->groups[i].idxd = idxd;
idxd->groups[i].id = i;
idxd->groups[i].tc_a = -1;
idxd->groups[i].tc_b = -1;
}
idxd->wq = create_workqueue(dev_name(dev)); idxd->wq = create_workqueue(dev_name(dev));
if (!idxd->wq) { if (!idxd->wq) {
rc = -ENOMEM; rc = -ENOMEM;
goto err; goto err_wkq_create;
} }
return 0; return 0;
err: err_wkq_create:
for (i = 0; i < idxd->max_groups; i++)
put_device(&idxd->groups[i]->conf_dev);
err_group:
for (i = 0; i < idxd->max_engines; i++) for (i = 0; i < idxd->max_engines; i++)
put_device(&idxd->engines[i]->conf_dev); put_device(&idxd->engines[i]->conf_dev);
err_engine: err_engine:
......
...@@ -16,16 +16,6 @@ static char *idxd_wq_type_names[] = { ...@@ -16,16 +16,6 @@ static char *idxd_wq_type_names[] = {
[IDXD_WQT_USER] = "user", [IDXD_WQT_USER] = "user",
}; };
static void idxd_conf_sub_device_release(struct device *dev)
{
dev_dbg(dev, "%s for %s\n", __func__, dev_name(dev));
}
static struct device_type idxd_group_device_type = {
.name = "group",
.release = idxd_conf_sub_device_release,
};
static int idxd_config_bus_match(struct device *dev, static int idxd_config_bus_match(struct device *dev,
struct device_driver *drv) struct device_driver *drv)
{ {
...@@ -435,7 +425,7 @@ static ssize_t engine_group_id_store(struct device *dev, ...@@ -435,7 +425,7 @@ static ssize_t engine_group_id_store(struct device *dev,
if (prevg) if (prevg)
prevg->num_engines--; prevg->num_engines--;
engine->group = &idxd->groups[id]; engine->group = idxd->groups[id];
engine->group->num_engines++; engine->group->num_engines++;
return count; return count;
...@@ -479,7 +469,7 @@ static void idxd_set_free_tokens(struct idxd_device *idxd) ...@@ -479,7 +469,7 @@ static void idxd_set_free_tokens(struct idxd_device *idxd)
int i, tokens; int i, tokens;
for (i = 0, tokens = 0; i < idxd->max_groups; i++) { for (i = 0, tokens = 0; i < idxd->max_groups; i++) {
struct idxd_group *g = &idxd->groups[i]; struct idxd_group *g = idxd->groups[i];
tokens += g->tokens_reserved; tokens += g->tokens_reserved;
} }
...@@ -784,6 +774,19 @@ static const struct attribute_group *idxd_group_attribute_groups[] = { ...@@ -784,6 +774,19 @@ static const struct attribute_group *idxd_group_attribute_groups[] = {
NULL, NULL,
}; };
static void idxd_conf_group_release(struct device *dev)
{
struct idxd_group *group = container_of(dev, struct idxd_group, conf_dev);
kfree(group);
}
struct device_type idxd_group_device_type = {
.name = "group",
.release = idxd_conf_group_release,
.groups = idxd_group_attribute_groups,
};
/* IDXD work queue attribs */ /* IDXD work queue attribs */
static ssize_t wq_clients_show(struct device *dev, static ssize_t wq_clients_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
...@@ -856,7 +859,7 @@ static ssize_t wq_group_id_store(struct device *dev, ...@@ -856,7 +859,7 @@ static ssize_t wq_group_id_store(struct device *dev,
return count; return count;
} }
group = &idxd->groups[id]; group = idxd->groups[id];
prevg = wq->group; prevg = wq->group;
if (prevg) if (prevg)
...@@ -1680,37 +1683,27 @@ static int idxd_register_engine_devices(struct idxd_device *idxd) ...@@ -1680,37 +1683,27 @@ static int idxd_register_engine_devices(struct idxd_device *idxd)
return rc; return rc;
} }
static int idxd_setup_group_sysfs(struct idxd_device *idxd) static int idxd_register_group_devices(struct idxd_device *idxd)
{ {
struct device *dev = &idxd->pdev->dev; int i, j, rc;
int i, rc;
for (i = 0; i < idxd->max_groups; i++) { for (i = 0; i < idxd->max_groups; i++) {
struct idxd_group *group = &idxd->groups[i]; struct idxd_group *group = idxd->groups[i];
group->conf_dev.parent = &idxd->conf_dev; rc = device_add(&group->conf_dev);
dev_set_name(&group->conf_dev, "group%d.%d", if (rc < 0)
idxd->id, group->id);
group->conf_dev.bus = idxd_get_bus_type(idxd);
group->conf_dev.groups = idxd_group_attribute_groups;
group->conf_dev.type = &idxd_group_device_type;
dev_dbg(dev, "Group device register: %s\n",
dev_name(&group->conf_dev));
rc = device_register(&group->conf_dev);
if (rc < 0) {
put_device(&group->conf_dev);
goto cleanup; goto cleanup;
}
} }
return 0; return 0;
cleanup: cleanup:
while (i--) { j = i - 1;
struct idxd_group *group = &idxd->groups[i]; for (; i < idxd->max_groups; i++)
put_device(&idxd->groups[i]->conf_dev);
device_unregister(&group->conf_dev); while (j--)
} device_unregister(&idxd->groups[j]->conf_dev);
return rc; return rc;
} }
...@@ -1759,10 +1752,9 @@ int idxd_register_devices(struct idxd_device *idxd) ...@@ -1759,10 +1752,9 @@ int idxd_register_devices(struct idxd_device *idxd)
goto err_engine; goto err_engine;
} }
rc = idxd_setup_group_sysfs(idxd); rc = idxd_register_group_devices(idxd);
if (rc < 0) { if (rc < 0) {
/* unregister conf dev */ dev_dbg(dev, "Group device registering failed: %d\n", rc);
dev_dbg(dev, "Group sysfs registering failed: %d\n", rc);
goto err_group; goto err_group;
} }
...@@ -1796,7 +1788,7 @@ void idxd_unregister_devices(struct idxd_device *idxd) ...@@ -1796,7 +1788,7 @@ void idxd_unregister_devices(struct idxd_device *idxd)
} }
for (i = 0; i < idxd->max_groups; i++) { for (i = 0; i < idxd->max_groups; i++) {
struct idxd_group *group = &idxd->groups[i]; struct idxd_group *group = idxd->groups[i];
device_unregister(&group->conf_dev); device_unregister(&group->conf_dev);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册