From mboxrd@z Thu Jan 1 00:00:00 1970 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 BE37BC433EF for ; Thu, 21 Apr 2022 22:07:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1DFDB6B0073; Thu, 21 Apr 2022 18:07:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 18E1E6B0074; Thu, 21 Apr 2022 18:07:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0554D6B0075; Thu, 21 Apr 2022 18:07:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id E89156B0073 for ; Thu, 21 Apr 2022 18:07:49 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id B1DF8819BD for ; Thu, 21 Apr 2022 22:07:49 +0000 (UTC) X-FDA: 79382274258.05.341276A Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf27.hostedemail.com (Postfix) with ESMTP id 35DC040015 for ; Thu, 21 Apr 2022 22:07:48 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3E40461E2F; Thu, 21 Apr 2022 22:07:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61277C385A7; Thu, 21 Apr 2022 22:07:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1650578867; bh=I/y6oOj7Cgwu++f5BI+q+wJEZ/y1EIcrQV1iyYFhfgM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=fAHKB5NS6TUUgG/fPwvW64fCyMd7wN06IX2YWbRZ/UY5SxFYkb+NuC981FjzhnP5k pSOYiO8c14AzHfRbwFrOI9xSnFeXYrm+h8kWwHkZXgkv24/NraOAZfX3A9v3NdkQtW bHR6tkRGCLRko7/s+7RaHW0A0g6WlAoVzNx+71yw= Date: Thu, 21 Apr 2022 15:07:46 -0700 From: Andrew Morton To: Zqiang Cc: ryabinin.a.a@gmail.com, dvyukov@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Alexander Potapenko , Andrey Konovalov , kasan-dev Subject: Re: [PATCH] kasan: Prevent cpu_quarantine corruption when CPU offline and cache shrink occur at same time Message-Id: <20220421150746.627e0f62363485d65c857010@linux-foundation.org> In-Reply-To: <20220414025925.2423818-1-qiang1.zhang@intel.com> References: <20220414025925.2423818-1-qiang1.zhang@intel.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 35DC040015 X-Rspam-User: Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=fAHKB5NS; spf=pass (imf27.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Stat-Signature: yjzawmarkdh5xa3cq8jpmjrec6wh7eqy X-HE-Tag: 1650578868-646399 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, 14 Apr 2022 10:59:25 +0800 Zqiang wrote: > 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(). > > ... > Could we please have some reviewer input here? > --- 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); It might be helpful to have a little comment which explains why we're doing this?