From patchwork Thu Apr 14 02:59:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zqiang X-Patchwork-Id: 12812864 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 3A4BCC433F5 for ; Thu, 14 Apr 2022 02:59:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 682446B0071; Wed, 13 Apr 2022 22:59:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 60B5E6B0073; Wed, 13 Apr 2022 22:59:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 484EC6B0074; Wed, 13 Apr 2022 22:59:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0127.hostedemail.com [216.40.44.127]) by kanga.kvack.org (Postfix) with ESMTP id 2F1F26B0071 for ; Wed, 13 Apr 2022 22:59:07 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id D3D4018337A17 for ; Thu, 14 Apr 2022 02:59:06 +0000 (UTC) X-FDA: 79353977892.22.6209378 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf29.hostedemail.com (Postfix) with ESMTP id C2E88120007 for ; Thu, 14 Apr 2022 02:59:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649905145; x=1681441145; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=PbAfj1r4A32EcIrxNdDaYDZ2NeJN6WT4A6qcNZBBano=; b=cV+9hcO6ovK0sDqXqacwOOMUtR5O+IZLwjqreV/A1padDFSxBN7WAzj+ Ae1A8nSxoHPU0MpTP55zBxxY0ywDMwycsjSMxssahqdlBTYGhqzaTBrY6 Z8ZzfY6hQSKdrrujL5DyG+jC4Rq7aNsvQBN4UJKqOSlaZkzJCEZf0oU3+ F90IW83kctVfESJmUjqlxiWpyk1jIXvz25/gd7KqlIDG1o46mHt+B7oMl K2NaEVrrUi79QxAQMFNXoxHkQ7im1ZG7cRjw2x+Y6hQ/LEunWjL5pyzv9 pX6bmErPPcxaLY3Tc4TxRwHqgb8iT3EaI5OC+iA/ODkRcf97T7CA8p1vc Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10316"; a="262270392" X-IronPort-AV: E=Sophos;i="5.90,258,1643702400"; d="scan'208";a="262270392" 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 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 4p6pqejsy8ewdojhfe4tg4woby7g33rr Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=cV+9hcO6; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf29.hostedemail.com: domain of qiang1.zhang@intel.com has no SPF policy when checking 134.134.136.24) smtp.mailfrom=qiang1.zhang@intel.com X-Rspamd-Queue-Id: C2E88120007 X-HE-Tag: 1649905145-657359 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Reviewed-by: Dmitry Vyukov --- 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);