From patchwork Wed Sep 14 06:49:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 12975687 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13DDBECAAD8 for ; Wed, 14 Sep 2022 06:49:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 303DF8D0002; Wed, 14 Sep 2022 02:49:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B2238D0001; Wed, 14 Sep 2022 02:49:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A1098D0002; Wed, 14 Sep 2022 02:49:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 0BD7A8D0001 for ; Wed, 14 Sep 2022 02:49:55 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D6B0914087C for ; Wed, 14 Sep 2022 06:49:54 +0000 (UTC) X-FDA: 79909765908.13.BB66BA7 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by imf09.hostedemail.com (Postfix) with ESMTP id 284931400B5 for ; Wed, 14 Sep 2022 06:49:52 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R771e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=xueshuai@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0VPm6Tzt_1663138188; Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0VPm6Tzt_1663138188) by smtp.aliyun-inc.com; Wed, 14 Sep 2022 14:49:50 +0800 From: Shuai Xue To: naoya.horiguchi@nec.com, linmiaohe@huawei.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, cuibixuan@linux.alibaba.com, baolin.wang@linux.alibaba.com, zhuo.song@linux.alibaba.com, xueshuai@linux.alibaba.com Subject: [PATCH] mm,hwpoison: check mm when killing accessing process Date: Wed, 14 Sep 2022 14:49:35 +0800 Message-Id: <20220914064935.7851-1-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of xueshuai@linux.alibaba.com designates 115.124.30.132 as permitted sender) smtp.mailfrom=xueshuai@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663138194; a=rsa-sha256; cv=none; b=iMNP+/GaaE0Hjxl5L3V2dBUGpChqCYpprQaYCRDPt497aB/Blv3xNbUWLKg9Py54My3p7k OrFHvDIQh3XTXM6p9dtpBFjGdGOL2W9HIE7E0rjHeysQ4NkedknrHn0vwKSBL3TiBkRvq+ qBHdZdjhfXB0IGh8tg2twIGzSS9YuJg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663138194; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=zZe4h0wLpt+pXU0OQRZGNYFVRFIInr3IX6Ap7Vpq9V8=; b=jQVcGufXO/CdFnX7ZFMgM3+21Gw1d0D3OmHg24eW1HrqbYKbbyrMegsXsalp9J0w5qTPWS PIEETArzRpDXDCMnVF0XwTuf/KyCNVEiFRZziWhRTKNF9m0+6OpSYQAVmMt8BElfvI3gHi L2nFyp16QO9LHoyHCVL8VdsdiflV3V8= X-Rspam-User: X-Stat-Signature: ezik7dmqaf48jzohww696whpusgdqjx4 X-Rspamd-Queue-Id: 284931400B5 X-Rspamd-Server: rspam05 Authentication-Results: imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of xueshuai@linux.alibaba.com designates 115.124.30.132 as permitted sender) smtp.mailfrom=xueshuai@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com X-HE-Tag: 1663138192-505177 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The GHES code calls memory_failure_queue() from IRQ context to queue work into workqueue and schedule it on the current CPU. Then the work is processed in memory_failure_work_func() by kworker and calls memory_failure(). When a page is already poisoned, commit a3f5d80ea401 ("mm,hwpoison: send SIGBUS with error virutal address") make memory_failure() call kill_accessing_process() that: - holds mmap locking of current->mm - does pagetable walk to find the error virtual address - and sends SIGBUS to the current process with error info. However, the mm of kworker is not valid. Therefore, check mm when killing accessing process. Fixes: a3f5d80ea401 ("mm,hwpoison: send SIGBUS with error virutal address") Signed-off-by: Shuai Xue Reviewed-by: Miaohe Lin Acked-by: Naoya Horiguchi --- mm/memory-failure.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 14439806b5ef..7553917ce820 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -743,6 +743,9 @@ static int kill_accessing_process(struct task_struct *p, unsigned long pfn, }; priv.tk.tsk = p; + if (!p->mm) + return -EFAULT; + mmap_read_lock(p->mm); ret = walk_page_range(p->mm, 0, TASK_SIZE, &hwp_walk_ops, (void *)&priv); @@ -751,6 +754,7 @@ static int kill_accessing_process(struct task_struct *p, unsigned long pfn, else ret = 0; mmap_read_unlock(p->mm); + return ret > 0 ? -EHWPOISON : -EFAULT; }