Message ID | 168506118166.3004974.13523455340007852589.stgit@djiang5-mobl3 |
---|---|
State | Accepted |
Commit | 793a539ac78843ef9378bb42a44edfbc552a67d5 |
Headers | show |
Series | cxl: Explicitly initialize resources when media is not ready | expand |
Dave Jiang wrote: > When media is not ready, all media information are not read from the > device. Explicitly set zero out the resources instead of going through the > success code path with 0 size capacity to init the resources and return. I'll fix this up to: When media is not ready do not assume that the capacity information from the identify command is valid, i.e. ->total_bytes ->partition_align_bytes ->{volatile,persistent}_only_bytes. Explicitly zero out the capacity resources and exit early. > Fixes: e764f12208b9 ("cxl: Move cxl_await_media_ready() to before capacity info retrieval") I'll drop this since e764f12208b9 is not broken in practice, this is just a readability fixup. > Suggested-by: Dan Williams <dan.j.williams@intel.com> > Signed-off-by: Dave Jiang <dave.jiang@intel.com> > --- > drivers/cxl/core/mbox.c | 17 +++++++++++------ > 1 file changed, 11 insertions(+), 6 deletions(-) > > diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c > index 2c8dc7e2b84d..e1d257051a7d 100644 > --- a/drivers/cxl/core/mbox.c > +++ b/drivers/cxl/core/mbox.c > @@ -1105,6 +1105,13 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds) > struct device *dev = cxlds->dev; > int rc; > > + if (!cxlds->media_ready) { > + cxlds->dpa_res = (struct resource)DEFINE_RES_MEM(0, 0); > + cxlds->ram_res = (struct resource)DEFINE_RES_MEM(0, 0); > + cxlds->pmem_res = (struct resource)DEFINE_RES_MEM(0, 0); > + return 0; > + } > + > cxlds->dpa_res = > (struct resource)DEFINE_RES_MEM(0, cxlds->total_bytes); > > @@ -1118,12 +1125,10 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds) > cxlds->persistent_only_bytes, "pmem"); > } > > - if (cxlds->media_ready) { > - rc = cxl_mem_get_partition_info(cxlds); > - if (rc) { > - dev_err(dev, "Failed to query partition information\n"); > - return rc; > - } > + rc = cxl_mem_get_partition_info(cxlds); > + if (rc) { > + dev_err(dev, "Failed to query partition information\n"); > + return rc; > } > > rc = add_dpa_res(dev, &cxlds->dpa_res, &cxlds->ram_res, 0, > >
Dave Jiang wrote: > When media is not ready, all media information are not read from the > device. Explicitly set zero out the resources instead of going through the > success code path with 0 size capacity to init the resources and return. > > Fixes: e764f12208b9 ("cxl: Move cxl_await_media_ready() to before capacity info retrieval") > Suggested-by: Dan Williams <dan.j.williams@intel.com> > Signed-off-by: Dave Jiang <dave.jiang@intel.com> > --- > drivers/cxl/core/mbox.c | 17 +++++++++++------ > 1 file changed, 11 insertions(+), 6 deletions(-) > > diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c > index 2c8dc7e2b84d..e1d257051a7d 100644 > --- a/drivers/cxl/core/mbox.c > +++ b/drivers/cxl/core/mbox.c > @@ -1105,6 +1105,13 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds) > struct device *dev = cxlds->dev; > int rc; > > + if (!cxlds->media_ready) { > + cxlds->dpa_res = (struct resource)DEFINE_RES_MEM(0, 0); > + cxlds->ram_res = (struct resource)DEFINE_RES_MEM(0, 0); > + cxlds->pmem_res = (struct resource)DEFINE_RES_MEM(0, 0); Btw, DEFINE_RES_MEM() already casts the result to (struct resource), so I'll drop those casts on applying.
diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index 2c8dc7e2b84d..e1d257051a7d 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -1105,6 +1105,13 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds) struct device *dev = cxlds->dev; int rc; + if (!cxlds->media_ready) { + cxlds->dpa_res = (struct resource)DEFINE_RES_MEM(0, 0); + cxlds->ram_res = (struct resource)DEFINE_RES_MEM(0, 0); + cxlds->pmem_res = (struct resource)DEFINE_RES_MEM(0, 0); + return 0; + } + cxlds->dpa_res = (struct resource)DEFINE_RES_MEM(0, cxlds->total_bytes); @@ -1118,12 +1125,10 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds) cxlds->persistent_only_bytes, "pmem"); } - if (cxlds->media_ready) { - rc = cxl_mem_get_partition_info(cxlds); - if (rc) { - dev_err(dev, "Failed to query partition information\n"); - return rc; - } + rc = cxl_mem_get_partition_info(cxlds); + if (rc) { + dev_err(dev, "Failed to query partition information\n"); + return rc; } rc = add_dpa_res(dev, &cxlds->dpa_res, &cxlds->ram_res, 0,
When media is not ready, all media information are not read from the device. Explicitly set zero out the resources instead of going through the success code path with 0 size capacity to init the resources and return. Fixes: e764f12208b9 ("cxl: Move cxl_await_media_ready() to before capacity info retrieval") Suggested-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Dave Jiang <dave.jiang@intel.com> --- drivers/cxl/core/mbox.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)