From patchwork Wed Apr 27 21:57:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 567118 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFE76C433F5 for ; Wed, 27 Apr 2022 21:57:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237710AbiD0WAl (ORCPT ); Wed, 27 Apr 2022 18:00:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237718AbiD0WAk (ORCPT ); Wed, 27 Apr 2022 18:00:40 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F49A266E; Wed, 27 Apr 2022 14:57:28 -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 ams.source.kernel.org (Postfix) with ESMTPS id D5992B82AE5; Wed, 27 Apr 2022 21:57:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C8E6C385A9; Wed, 27 Apr 2022 21:57:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1651096645; bh=svSXJuQCOhOk2lDCy9P5olT/52vQ0ZDU90V0CnnYfX0=; h=Date:To:From:Subject:From; b=Cp0hFF8Kih9ho3+5UnGTUWuLLDgewdqfk9742Dw2xhlq7emiHFFNk+Kqzbi915eOf vTcFugPDpk2DxuUm4S0dZB2yDgxmG/cSEvUHnnoZ7oQzmUfajUl1yhnFS8iBaA67e1 nnZjx2hKzBWRBFmKoOWLF3pc4evgy3dQc9KAAj0c= Date: Wed, 27 Apr 2022 14:57:24 -0700 To: mm-commits@vger.kernel.org, stable@vger.kernel.org, ryabinin.a.a@gmail.com, glider@google.com, dvyukov@google.com, andreyknvl@gmail.com, qiang1.zhang@intel.com, akpm@linux-foundation.org From: Andrew Morton Subject: [merged] kasan-prevent-cpu_quarantine-corruption-when-cpu-offline-and-cache-shrink-occur-at-same-time.patch removed from -mm tree Message-Id: <20220427215725.5C8E6C385A9@smtp.kernel.org> Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The patch titled Subject: kasan: prevent cpu_quarantine corruption when CPU offline and cache shrink occur at same time has been removed from the -mm tree. Its filename was kasan-prevent-cpu_quarantine-corruption-when-cpu-offline-and-cache-shrink-occur-at-same-time.patch This patch was dropped because it was merged into mainline or a subsystem tree ------------------------------------------------------ From: Zqiang Subject: kasan: prevent cpu_quarantine corruption when CPU offline and cache shrink occur at same time 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() to ensure serialization with kasan_cpu_offline(). However the kasan_quarantine_remove_cache() call is not protected by cpuslock in kmem_cache_shrink(). When a CPU is going offline and cache shrink occurs at same time, the cpu_quarantine may be corrupted by interrupt (per_cpu_remove_cache operation). So add a cpu_quarantine offline flags check in per_cpu_remove_cache(). [akpm@linux-foundation.org: add comment, per Zqiang] Link: https://lkml.kernel.org/r/20220414025925.2423818-1-qiang1.zhang@intel.com Signed-off-by: Zqiang Reviewed-by: Dmitry Vyukov Cc: Andrey Ryabinin Cc: Alexander Potapenko Cc: Andrey Konovalov Cc: Signed-off-by: Andrew Morton --- mm/kasan/quarantine.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/mm/kasan/quarantine.c~kasan-prevent-cpu_quarantine-corruption-when-cpu-offline-and-cache-shrink-occur-at-same-time +++ a/mm/kasan/quarantine.c @@ -315,6 +315,13 @@ static void per_cpu_remove_cache(void *a struct qlist_head *q; q = this_cpu_ptr(&cpu_quarantine); + /* + * Ensure the ordering between the writing to q->offline and + * per_cpu_remove_cache. Prevent cpu_quarantine from being corrupted + * by interrupt. + */ + if (READ_ONCE(q->offline)) + return; qlist_move_cache(q, &to_free, cache); qlist_free_all(&to_free, cache); }