Re: [PATCH 2/2] libnvdimm/security: ensure sysfs poll thread woke up and fetch updated attr

2020-08-03 Thread Dave Jiang




On 7/24/2020 9:09 AM, Jane Chu wrote:

commit 7d988097c546 ("acpi/nfit, libnvdimm/security: Add security DSM overwrite 
support")
adds a sysfs_notify_dirent() to wake up userspace poll thread when the 
"overwrite"
operation has completed. But the notification is issued before the internal
dimm security state and flags have been updated, so the userspace poll thread
wakes up and fetches the not-yet-updated attr and falls back to sleep, forever.
But if user from another terminal issue "ndctl wait-overwrite nmemX" again,
the command returns instantly.

Cc: Dave Jiang 
Cc: Dan Williams 
Fixes: 7d988097c546 ("acpi/nfit, libnvdimm/security: Add security DSM overwrite 
support")
Signed-off-by: Jane Chu 


Reviewed-by: Dave Jiang 


---
  drivers/nvdimm/security.c | 11 ---
  1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/nvdimm/security.c b/drivers/nvdimm/security.c
index 8f3971c..4b80150 100644
--- a/drivers/nvdimm/security.c
+++ b/drivers/nvdimm/security.c
@@ -450,14 +450,19 @@ void __nvdimm_security_overwrite_query(struct nvdimm 
*nvdimm)
else
dev_dbg(&nvdimm->dev, "overwrite completed\n");
  
-	if (nvdimm->sec.overwrite_state)

-   sysfs_notify_dirent(nvdimm->sec.overwrite_state);
+   /*
+* Mark the overwrite work done and update dimm security flags,
+* then send a sysfs event notification to wake up userspace
+* poll threads to picked up the changed state.
+*/
nvdimm->sec.overwrite_tmo = 0;
clear_bit(NDD_SECURITY_OVERWRITE, &nvdimm->flags);
clear_bit(NDD_WORK_PENDING, &nvdimm->flags);
-   put_device(&nvdimm->dev);
nvdimm->sec.flags = nvdimm_security_flags(nvdimm, NVDIMM_USER);
nvdimm->sec.ext_flags = nvdimm_security_flags(nvdimm, NVDIMM_MASTER);
+   if (nvdimm->sec.overwrite_state)
+   sysfs_notify_dirent(nvdimm->sec.overwrite_state);
+   put_device(&nvdimm->dev);
  }
  
  void nvdimm_security_overwrite_query(struct work_struct *work)




[PATCH 2/2] libnvdimm/security: ensure sysfs poll thread woke up and fetch updated attr

2020-07-24 Thread Jane Chu
commit 7d988097c546 ("acpi/nfit, libnvdimm/security: Add security DSM overwrite 
support")
adds a sysfs_notify_dirent() to wake up userspace poll thread when the 
"overwrite"
operation has completed. But the notification is issued before the internal
dimm security state and flags have been updated, so the userspace poll thread
wakes up and fetches the not-yet-updated attr and falls back to sleep, forever.
But if user from another terminal issue "ndctl wait-overwrite nmemX" again,
the command returns instantly.

Cc: Dave Jiang 
Cc: Dan Williams 
Fixes: 7d988097c546 ("acpi/nfit, libnvdimm/security: Add security DSM overwrite 
support")
Signed-off-by: Jane Chu 
---
 drivers/nvdimm/security.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/nvdimm/security.c b/drivers/nvdimm/security.c
index 8f3971c..4b80150 100644
--- a/drivers/nvdimm/security.c
+++ b/drivers/nvdimm/security.c
@@ -450,14 +450,19 @@ void __nvdimm_security_overwrite_query(struct nvdimm 
*nvdimm)
else
dev_dbg(&nvdimm->dev, "overwrite completed\n");
 
-   if (nvdimm->sec.overwrite_state)
-   sysfs_notify_dirent(nvdimm->sec.overwrite_state);
+   /*
+* Mark the overwrite work done and update dimm security flags,
+* then send a sysfs event notification to wake up userspace
+* poll threads to picked up the changed state.
+*/
nvdimm->sec.overwrite_tmo = 0;
clear_bit(NDD_SECURITY_OVERWRITE, &nvdimm->flags);
clear_bit(NDD_WORK_PENDING, &nvdimm->flags);
-   put_device(&nvdimm->dev);
nvdimm->sec.flags = nvdimm_security_flags(nvdimm, NVDIMM_USER);
nvdimm->sec.ext_flags = nvdimm_security_flags(nvdimm, NVDIMM_MASTER);
+   if (nvdimm->sec.overwrite_state)
+   sysfs_notify_dirent(nvdimm->sec.overwrite_state);
+   put_device(&nvdimm->dev);
 }
 
 void nvdimm_security_overwrite_query(struct work_struct *work)
-- 
1.8.3.1



[PATCH 2/2] libnvdimm/security: ensure sysfs poll thread woke up and fetch updated attr

2020-07-23 Thread Jane Chu
commit 7d988097c546 ("acpi/nfit, libnvdimm/security: Add security DSM overwrite 
support")
adds a sysfs_notify_dirent() to wake up userspace poll thread when the 
"overwrite"
operation has completed. But the notification is issued before the internal
dimm security state and flags have been updated, so the userspace poll thread
wakes up and fetches the not-yet-updated attr and falls back to sleep, forever.
But if user from another terminal issue "ndctl wait-overwrite nmemX" again,
the command returns instantly.

Cc: Dave Jiang 
Cc: Dan Williams 
Fixes: 7d988097c546 ("acpi/nfit, libnvdimm/security: Add security DSM overwrite 
support")
Signed-off-by: Jane Chu 
---
 drivers/nvdimm/security.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/nvdimm/security.c b/drivers/nvdimm/security.c
index 8f3971c..4b80150 100644
--- a/drivers/nvdimm/security.c
+++ b/drivers/nvdimm/security.c
@@ -450,14 +450,19 @@ void __nvdimm_security_overwrite_query(struct nvdimm 
*nvdimm)
else
dev_dbg(&nvdimm->dev, "overwrite completed\n");
 
-   if (nvdimm->sec.overwrite_state)
-   sysfs_notify_dirent(nvdimm->sec.overwrite_state);
+   /*
+* Mark the overwrite work done and update dimm security flags,
+* then send a sysfs event notification to wake up userspace
+* poll threads to picked up the changed state.
+*/
nvdimm->sec.overwrite_tmo = 0;
clear_bit(NDD_SECURITY_OVERWRITE, &nvdimm->flags);
clear_bit(NDD_WORK_PENDING, &nvdimm->flags);
-   put_device(&nvdimm->dev);
nvdimm->sec.flags = nvdimm_security_flags(nvdimm, NVDIMM_USER);
nvdimm->sec.ext_flags = nvdimm_security_flags(nvdimm, NVDIMM_MASTER);
+   if (nvdimm->sec.overwrite_state)
+   sysfs_notify_dirent(nvdimm->sec.overwrite_state);
+   put_device(&nvdimm->dev);
 }
 
 void nvdimm_security_overwrite_query(struct work_struct *work)
-- 
1.8.3.1