From patchwork Wed Jun 9 15:56:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xu, Yanfei" X-Patchwork-Id: 12310623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4AAFC48BCD for ; Wed, 9 Jun 2021 15:57:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3E05060FEB for ; Wed, 9 Jun 2021 15:57:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3E05060FEB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=windriver.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 53F7A6B0036; Wed, 9 Jun 2021 11:57:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4EFDB6B006C; Wed, 9 Jun 2021 11:57:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F4A16B0070; Wed, 9 Jun 2021 11:57:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0130.hostedemail.com [216.40.44.130]) by kanga.kvack.org (Postfix) with ESMTP id F27E06B0036 for ; Wed, 9 Jun 2021 11:57:20 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 857AF998F for ; Wed, 9 Jun 2021 15:57:20 +0000 (UTC) X-FDA: 78234639840.27.83BE364 Received: from mx0b-0064b401.pphosted.com (mx0b-0064b401.pphosted.com [205.220.178.238]) by imf03.hostedemail.com (Postfix) with ESMTP id F1E08C00F783 for ; Wed, 9 Jun 2021 15:57:14 +0000 (UTC) Received: from pps.filterd (m0250811.ppops.net [127.0.0.1]) by mx0a-0064b401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 159FnHRs009309; Wed, 9 Jun 2021 15:57:15 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2169.outbound.protection.outlook.com [104.47.57.169]) by mx0a-0064b401.pphosted.com with ESMTP id 3927fn16f2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 09 Jun 2021 15:57:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WTlUX5SwwYXi0O4PW29YXaqUzKbOarsO4bGfeyhpLfVChtrQjiDlCooLCUNkdWmiSvd5TfvqMAqItbke/pRgfSDUf2qj0CmrPmPTPbF2o8yR8BwhhMari89vBqAezcrfvn2/qWR0WQgyy0UotCM0CMGVwSHxScvEthfg0BicHU54i39zvTOcBiVW3IPTQQxSLp2CNRLvaUBIcVdJnuq42kGz44lo1lTIxfebxmz+tbMq5nF5kpE6/ANaIRo098xyIK72Az9kUo0383fG9QTdcl7TKjvlKcDMWp6u+GG4y8S2PbmFvxBX7diwCVEE7of4FAJbDcxOSCzmLUPOdojiEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v5ebSAbdI+qMccM8+a20mfjE0DaWX0iGXJNa2TRYPao=; b=emZIjIuAN2Ykrh1XpBpiF5IY/zrX+t+1v+7353ivATV/4fdvliM4he1Six11A8ALbnKshPRPgMlD1vuNtRPphvxqEBerg+4SodTLm+TeBv64Y7t1lLvNL9YW0YQRe0JlXbwobcF2UfWDUzj6tfYmKJ7R1RIYqeIaJKC9BWFpeIPBRHIM9bvYtxpuLP66R3B4GDYCZj+ydEFjiDYm+PTFsiN21Fy5/tg4/IsdSHyH4DwPze+Hoo1NhNvWeE5j86FaqOswY4UehKMYWwCqiRQ0TfNbhkdYYP0H7aZlnYftuWn6vPAJ1PZyolsV+xk7DSHZZx/JKDZROftdUYTL8sE5Ew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v5ebSAbdI+qMccM8+a20mfjE0DaWX0iGXJNa2TRYPao=; b=Z1wF7WtnNCrk2bOBFHDYGVF2w0OtQS5lfXTd2IsGdhAdNyeZrQ5GFw+nIMD8IHNDaJdxDbJLZSSZo1va8M8WWHPnssnNNcnerAE/S6VMXvy3iQ6oVPcUTKhLg/mIQPj/2VsmgVzA8pM2imN939oIbgNnJ7o9wPf3Qt+Emxcxgps= Received: from BY5PR11MB4241.namprd11.prod.outlook.com (2603:10b6:a03:1ca::13) by BYAPR11MB3557.namprd11.prod.outlook.com (2603:10b6:a03:b4::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.22; Wed, 9 Jun 2021 15:57:12 +0000 Received: from BY5PR11MB4241.namprd11.prod.outlook.com ([fe80::34b3:17c2:b1ad:286c]) by BY5PR11MB4241.namprd11.prod.outlook.com ([fe80::34b3:17c2:b1ad:286c%5]) with mapi id 15.20.4195.030; Wed, 9 Jun 2021 15:57:12 +0000 From: Yanfei Xu To: catalin.marinas@arm.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/kmemleak: use READ_ONCE() for accessing jiffies_scan_wait Date: Wed, 9 Jun 2021 23:56:57 +0800 Message-Id: <20210609155657.26972-1-yanfei.xu@windriver.com> X-Mailer: git-send-email 2.27.0 X-Originating-IP: [60.247.85.82] X-ClientProxiedBy: HK2PR0401CA0013.apcprd04.prod.outlook.com (2603:1096:202:2::23) To BY5PR11MB4241.namprd11.prod.outlook.com (2603:10b6:a03:1ca::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from pek-lpggp1.wrs.com (60.247.85.82) by HK2PR0401CA0013.apcprd04.prod.outlook.com (2603:1096:202:2::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.21 via Frontend Transport; Wed, 9 Jun 2021 15:57:10 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a4d9debd-ab2d-46f2-d267-08d92b5f3e33 X-MS-TrafficTypeDiagnostic: BYAPR11MB3557: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: w4YCiz2IFhtbe/SHRJS6BijHFQA5GgvF1IpU2XRlHQJIeDyQdu+kfL9V0skqaVWWpxjoh59Nrmyvah4bYKDSLviAlnGXnvs++YyfYRBpuNATS3t0QLvzEWPdkEMXxii09uUSW0o981bLRbym9twqjjgYjipPvu4knzw1IHFW+zZCtc3tz+VMoJCizaFRrwfjYtyFItKMHgz4+yBbHyglxU/a3fxI/iCyIqanYOszvlQ2BTTnFb4d/endiTqCIbgqX15RBYGkKmhBGkmgeOD1VYgw+ngX+52epw6frBMZFyRR2vO8TnUmf/XfrygFqIs2XCUyqn4IcO27Vp449oFWtnMaKepIDqCnS/zA8Q0YG6Mc8i7rYohX8cp88lkCHZtCYzNvFvIntEflMym40SJlbLYwOSY9OkjyaHVdlDl9wXz8ac7DtjXlf5TeaVpfBys2z6y+a+wPMTotVGXhLm50tVsPB67YYftC//OoscXwJ/JRT96KOIDLX7sd2XewaZS4hFyOwRjcsvLPowFWSqZnYj69yTSER61gpvA6zbihlazBKQ+/MAUKM2S9DBeJ+cvCWdA63SAfMxjagAXeBQm9XOz/5BIyK7iki1fbhg9llFSAbciOjMwtD1X/4yOT+xseuu6u8A3c9YkoE7w45L2prx/tt2qA258CLa1cUPx8u78= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR11MB4241.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(366004)(396003)(136003)(346002)(39850400004)(86362001)(36756003)(186003)(2906002)(316002)(6666004)(66556008)(66476007)(956004)(8936002)(83380400001)(4326008)(66946007)(478600001)(6506007)(38100700002)(38350700002)(1076003)(16526019)(6512007)(52116002)(26005)(44832011)(5660300002)(6486002)(8676002)(2616005)(21314003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QCXOQOQQJ9fDop+OkBw6dxTkL+czva9jOEcrOhT8YIrxw8HZtFL1JmnvMoSh/HWay90n/G0ln6OBa+/0xvPMDpa8tN0A0e9fD/0FKzcRLcr4MmRi5tgUrydIi2qAcLSanTG3Iq25BkRhpqaYMVKcdqfdsI9dH/tPs03fBAs7CGM4VxFUFh8ft0Fj3gJaR8pXaxS042JdgaZ0vhhU5WIr2TL2PF+lweUvkme066S/4flxsLEc42RfTfSAQ1wkthtQlscmbw8VCmHvejV3FnCXZQs2sEETJCqiqNZmmkGta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message-Id: a4d9debd-ab2d-46f2-d267-08d92b5f3e33 X-MS-Exchange-CrossTenant-AuthSource: BY5PR11MB4241.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2021 15:57:11.8455 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: EfmYNlSzxO/p9nTVUqOV67Wh1KaTRRZocBh5zHSFvSMjO09vrDBZ5p3CctPGiko1o+ydrFWqoNVVlIiEQoufdg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB3557 X-Proofpoint-GUID: 5bgaLrs1G6t0IjDPtJuC2jxWFYsWjE3a X-Proofpoint-ORIG-GUID: 5bgaLrs1G6t0IjDPtJuC2jxWFYsWjE3a X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-06-09_04:2021-06-04,2021-06-09 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 mlxscore=0 clxscore=1011 adultscore=0 suspectscore=0 spamscore=0 bulkscore=0 priorityscore=1501 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2106090077 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: F1E08C00F783 Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=windriversystems.onmicrosoft.com header.s=selector2-windriversystems-onmicrosoft-com header.b=Z1wF7Wtn; spf=pass (imf03.hostedemail.com: domain of "prvs=1794bfb6c6=yanfei.xu@windriver.com" designates 205.220.178.238 as permitted sender) smtp.mailfrom="prvs=1794bfb6c6=yanfei.xu@windriver.com"; dmarc=pass (policy=none) header.from=windriver.com X-Stat-Signature: 1jx6a8qtm5bfsuf8if9kdcy9kkpqofxb X-HE-Tag: 1623254234-406679 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 stop_scan_thread() and start_scan_thread() cannot really solve the problem of concurrent accessing the global jiffies_scan_wait. kmemleak_write kmemleak_scan_thread while (!kthread_should_stop()) stop_scan_thread jiffies_scan_wait = xxx timeout = jiffies_scan_wait start_scan_thread We could replace these with a READ_ONCE() when reading jiffies_scan_wait. It also can prevent compiler from reordering the jiffies_scan_wait which is in while loop. Signed-off-by: Yanfei Xu --- mm/kmemleak.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 92a2d4885808..5ccf3969b7fe 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1567,7 +1567,7 @@ static int kmemleak_scan_thread(void *arg) } while (!kthread_should_stop()) { - signed long timeout = jiffies_scan_wait; + signed long timeout = READ_ONCE(jiffies_scan_wait); mutex_lock(&scan_mutex); kmemleak_scan(); @@ -1812,11 +1812,8 @@ static ssize_t kmemleak_write(struct file *file, const char __user *user_buf, ret = kstrtoul(buf + 5, 0, &secs); if (ret < 0) goto out; - stop_scan_thread(); - if (secs) { + if (secs) jiffies_scan_wait = msecs_to_jiffies(secs * 1000); - start_scan_thread(); - } } else if (strncmp(buf, "scan", 4) == 0) kmemleak_scan(); else if (strncmp(buf, "dump=", 5) == 0)