Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp318951pxb; Thu, 14 Apr 2022 23:45:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxm53DCCsCtVSui2kOJoiaWsLN6R20Hb+hmWB9xxZssLVJnvfmLXvoO5FR5XfSq8REc8pST X-Received: by 2002:a63:5b0d:0:b0:39c:c393:7e7f with SMTP id p13-20020a635b0d000000b0039cc3937e7fmr5429425pgb.16.1650005135279; Thu, 14 Apr 2022 23:45:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650005135; cv=none; d=google.com; s=arc-20160816; b=JwVUfUlVoG7MO0KJFxrZCFcOFxlLQZeOyx4OsSdQhB1XfXOoKYp8OaXgi3o9jgW5b6 D+pwP/k+IeTYR4XbiMtSfpLTtTK3IXhGfjp6t8wdxGp9Rsx8VPuJ8sPTBggz+el1c9NS lab6HRT1VuFKj21AtBNqrU7kIOpL/zaPV6Bkd20UP3E29S/v3IkFPGLKDHfRVZVDBdan +JFtfCbSiSPpY7Gt+qEqmsaFuLuWn0Kf95a018y6N/A5tFL5VCim085B1ujxMgGxKTJA Hz1KDxPMrmsC+9ou95jac44YTIHDtVyBFtRrUgSgIMN0nRw7eWBoMF6ayw79smD/2q7L pq8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=db1TXG9EtjGxkvdcn38SPgr1CpxCiHT+numicnBzmnw=; b=ZzaOVsd5xVLXS77kBKHb1VOfEPgseefcYrmg/9lLBHC8V0lcLv9/Ta5k0g27NsiBSR Uig8keTPjCXLmqtsvc1/RBzvNiEYoMznP8ZoN/oAH8vGavKbyDeiiq9wMiP3Bx6zdcPr YL9660VzqNp6dsnqUlvzh6IuWsHHXg+C74CGAIQKR5RFjit0fMlTk1i/+fVK8fg6/hRC rHS90SQaPefHHIC98YWU0o/okjUDyNWvR4IKlXMuMhV/rFVZB7GhJzNNj6DlbwiRD4/i IZFiOiRjwf4Sw9o6kV1hOXesX9Ym1IcQKz5RITrKQLfNHCOXS7f5f/sVwJei07Wp3Ols DkOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CGssSyNH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t20-20020a635354000000b0039d15a1e26csi706490pgl.874.2022.04.14.23.45.22; Thu, 14 Apr 2022 23:45:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CGssSyNH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238950AbiDNDB3 (ORCPT + 99 others); Wed, 13 Apr 2022 23:01:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236004AbiDNDB1 (ORCPT ); Wed, 13 Apr 2022 23:01:27 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F8E24EF5B for ; Wed, 13 Apr 2022 19:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649905144; x=1681441144; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=PbAfj1r4A32EcIrxNdDaYDZ2NeJN6WT4A6qcNZBBano=; b=CGssSyNHMS6E3qd/GYBqYoIGe4GMw0vXN8zsmfdFlRdKk178fmtsRzuR cietMjBhLx08yQ2/MkZpnSsjxbbjdHmFigLe63PklWiKYn4tnMjiSNKeg s0axpIOBSkkqMYqPFMncLcZD9q3QYP48vc1OZ6A+iG/Yl+RHAeisNm2/7 LIOx0fBTxZqnmMbJkKpBZtycccKCz8Vb3j24cLIRHEhIxR6TBGOeoJuP3 I/G8CPeVDo08i/iLrMBBmLJqjI3jLaSPJivoZ1jHbU5zNosFA7vbtCiZy ZyAcKFR3nGFbflH36XHQfu3i3DBWIUB6r9aVamttCv7Tlwe4+JxuOyIMW g==; X-IronPort-AV: E=McAfee;i="6400,9594,10316"; a="262270391" X-IronPort-AV: E=Sophos;i="5.90,258,1643702400"; d="scan'208";a="262270391" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2022 19:59:04 -0700 X-IronPort-AV: E=Sophos;i="5.90,258,1643702400"; d="scan'208";a="573558777" Received: from zq-optiplex-7090.bj.intel.com ([10.238.156.125]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2022 19:59:02 -0700 From: Zqiang To: ryabinin.a.a@gmail.com, dvyukov@google.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] kasan: Prevent cpu_quarantine corruption when CPU offline and cache shrink occur at same time Date: Thu, 14 Apr 2022 10:59:25 +0800 Message-Id: <20220414025925.2423818-1-qiang1.zhang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The kasan_quarantine_remove_cache() is called in kmem_cache_shrink()/ destroy(), the kasan_quarantine_remove_cache() call is protected by cpuslock in kmem_cache_destroy(), can ensure serialization with kasan_cpu_offline(). however the kasan_quarantine_remove_cache() call is not protected by cpuslock in kmem_cache_shrink(), when CPU going offline and cache shrink occur at same time, the cpu_quarantine may be corrupted by interrupt(per_cpu_remove_cache operation). so add cpu_quarantine offline flags check in per_cpu_remove_cache(). Signed-off-by: Zqiang --- mm/kasan/quarantine.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c index 0e33d30abb8d..51a8192d49cf 100644 --- a/mm/kasan/quarantine.c +++ b/mm/kasan/quarantine.c @@ -330,6 +330,8 @@ static void per_cpu_remove_cache(void *arg) struct cpu_shrink_qlist *sq; #endif q = this_cpu_ptr(&cpu_quarantine); + if (READ_ONCE(q->offline)) + return; #ifndef CONFIG_PREEMPT_RT qlist_move_cache(q, &to_free, cache); qlist_free_all(&to_free, cache); -- 2.25.1