Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1104197pxa; Thu, 20 Aug 2020 02:34:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYKNQeiXVA348MHvyMlMj1qVbBZk4UCU8tqMgNSpQyh/RVN/b0B77CUTd2ZqgeiH3kCvif X-Received: by 2002:aa7:ce0b:: with SMTP id d11mr1920348edv.357.1597916068067; Thu, 20 Aug 2020 02:34:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597916068; cv=none; d=google.com; s=arc-20160816; b=IxEinBkS+VtyJI4bamJFEPW6L2vvSXzQlfv5mnk8fUTvZA8sRunf8+nEMhVLgeyTT7 y4cbvtUqmiTpRwcfXJMqtF4Lv7cbjf0eqTN+sOhj94PTR5cztpD++XlDPi4eALd3oz9Q UCkJrd//ibfB91FhLXPS2OxiLF8lhWVVPLHZSfw3Hf6NbXznVXgjK9JHfqbLzAWOWrkU +eEQ5NcckPgmOinhD4VK7q/90sL5w0o9JnEmvlrbUSSTBWo3wvo6NsP2dZ1sEExQwy/t m9Q8BWww5ScpbKBexGvBl7csgtnra18BCSDe4sBHNRxpk6HqVdk7R984sfMMQSMEB5Pa XEiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9uAJ05zanPqqHga6gc1cbtRicJ+41ZEzyl25EkFLEk8=; b=lEhwi8uDclYsmU7i7CJvkIJZMXD0OT0RLM1aZjlPIIhR0EWViiPBuiG6umXCjhBku0 0kC8+BdD3TX6jo9BwRXfl4Jz1v9Ji4eTZVV4mYAP0I1W0EeoNT1Hhirrq0ZwEXnrlgF2 J0mFCPr6E+gP/Tczo/N3lChn2fAvy1HHbhbh5ozFJh5j+9eBe4mR911C9icFwwnTMdob WLUBLftvRU8FlZEnDalYfStLzIg54wvWAoQgdH8Fr+fqYh/hTD2QE9WMpgJd6zl710wd EW6MPsm27gN8UAt52OBfo8Cqul/dj1gL44kNL8330syMHx2jzopFeUTy0ypAYTAPm836 fLVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Sa9gfU/B"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bq8si349775ejb.670.2020.08.20.02.34.04; Thu, 20 Aug 2020 02:34:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Sa9gfU/B"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728423AbgHTJd1 (ORCPT + 99 others); Thu, 20 Aug 2020 05:33:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:44194 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728258AbgHTJb7 (ORCPT ); Thu, 20 Aug 2020 05:31:59 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4656322B43; Thu, 20 Aug 2020 09:31:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915918; bh=yXQvIeh6zMjicGaFl3Np+uvH08uFB6zeEjIw7UUyD0E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sa9gfU/BLaZXHb2ttuChyK8+VGNVnICfPl6ZMk2VIMETqt9WJMVotXPSZUSp6h2EU /uUu8PaVtqXrp2qANsb2tma8W6W8W9bKj2awrZXvXByG0VnNbQYx2ydAhYCDN8TOMt vKtyp/y2XxxnRESpQhTL7+wvlNktIeHnze3rJFNw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Jiang , Dan Williams , Jane Chu , Vishal Verma , Sasha Levin Subject: [PATCH 5.8 180/232] libnvdimm/security: ensure sysfs poll thread woke up and fetch updated attr Date: Thu, 20 Aug 2020 11:20:31 +0200 Message-Id: <20200820091621.523221974@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jane Chu [ Upstream commit 7f674025d9f7321dea11b802cc0ab3f09cbe51c5 ] 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. Link: https://lore.kernel.org/r/1596494499-9852-3-git-send-email-jane.chu@oracle.com Fixes: 7d988097c546 ("acpi/nfit, libnvdimm/security: Add security DSM overwrite support") Cc: Dave Jiang Cc: Dan Williams Reviewed-by: Dave Jiang Signed-off-by: Jane Chu Signed-off-by: Vishal Verma Signed-off-by: Sasha Levin --- 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 8f3971cf16541..4b80150e4afa7 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) -- 2.25.1