Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp956601pxb; Fri, 22 Apr 2022 15:16:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxX5s8BIRCwPGLapcjyytIXxpqwX5QtcsE8g1Om6RsSnHwaHY2chnhipXpVUWoR0KwdK450 X-Received: by 2002:a17:90b:4c8f:b0:1d2:90e4:26ef with SMTP id my15-20020a17090b4c8f00b001d290e426efmr18251597pjb.120.1650665804083; Fri, 22 Apr 2022 15:16:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650665804; cv=none; d=google.com; s=arc-20160816; b=LHhMYR3L3D+7Kdome2gBgkpYGo4ES/VgIDjC7P6A6KdiESClbF1Wvtf3MobvcFgGAH cPkakgsPHhp0Bs8p2xu9b+5X3CE9NJ20foqPdDmhm527QXSj1QE+go+1NjTiEI3EdDBT wPSlQXX6v1Qdf6xjugNl9Zr774T2eiPvpLwcNmyDEKp2oQ9LHLsTDGDXdPMS0Z8pjRY/ BEGCE/zwBGMeEnpwR6IxENNTH+776F9zEuK/9xUBMwH7x+Wrfs9GV5zyuWLKs92g3GbA /oM8i0DHJdktfcGFrlpzJJDlDlpKkg9QVgN9J09KSRX17+dx1eLm9PIq2PuDYMes6BIv y8LA== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=9PTUHp3ha/u1SZ/ogRhtmV5nZ5ipDzuxSu1S8cX/k50=; b=U0cL45HaIyLq9xQ0U7ymuN099LBfqLODw2ClLvKlj0RV8z7QzB+790FgG6xsGOyzez 3+yNRyr1KeJkMFLaKu/0tWce6NX3pvExQoqJfKFjmpO4k6cabULVCw3ZrytL5StMiL3F u+Ub5kALJO26s5QjKl8OI8AX1KZX2VDyr2Z3OFPJhAukiI6gREkJcxUTKucIHPg5Zp4q G+mm6Z3ipaDtTn4UUkhE3yY+IWOTn49Hvo4mcBIWPev84KqBcrWRAQi5vBUiJnCWAD8U QHhNu2CsUe5jg5hLFxGl/hEsyeIoe00oZNQyOQIh2B0/ZQal6Bj6f+MCf7jcgEx9Z5fH hPhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=fAHKB5NS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s2-20020a170902b18200b00153b2d1664bsi8265425plr.595.2022.04.22.15.16.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 15:16:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=fAHKB5NS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DDFFF258D5C; Fri, 22 Apr 2022 13:21:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442343AbiDUWKp (ORCPT + 99 others); Thu, 21 Apr 2022 18:10:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442340AbiDUWKl (ORCPT ); Thu, 21 Apr 2022 18:10:41 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10FB44D63F for ; Thu, 21 Apr 2022 15:07:51 -0700 (PDT) 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 sin.source.kernel.org (Postfix) with ESMTPS id 5E348CE265F for ; Thu, 21 Apr 2022 22:07:49 +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-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE autolearn=unavailable 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 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?