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 75EFBC6FD1D for ; Wed, 15 Mar 2023 16:15:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232830AbjCOQP3 (ORCPT ); Wed, 15 Mar 2023 12:15:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233087AbjCOQPE (ORCPT ); Wed, 15 Mar 2023 12:15:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C101113D8 for ; Wed, 15 Mar 2023 09:14:17 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 7327961DBF for ; Wed, 15 Mar 2023 16:14:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CCC9C433D2; Wed, 15 Mar 2023 16:14:11 +0000 (UTC) Date: Wed, 15 Mar 2023 16:14:08 +0000 From: Catalin Marinas To: Andrey Konovalov Cc: Peter Collingbourne , =?utf-8?B?6KKB5biFKFNodWFpIFl1YW4p?= , Dmitry Vyukov , =?utf-8?B?5qyn6Ziz54Kc6ZKKKFdlaXpoYW8gT3V5YW5nKQ==?= , Andrey Ryabinin , Alexander Potapenko , Vincenzo Frascino , Andrew Morton , "kasan-dev@googlegroups.com" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Weizhao Ouyang , =?utf-8?B?5Lu756uL6bmPKFBlbmcgUmVuKQ==?= Subject: Re: [PATCH v2] kasan: fix deadlock in start_report() Message-ID: References: <93b94f59016145adbb1e01311a1103f8@zeku.com> <2b57491a9fab4ce9a643bd0922e03e73@zeku.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Mar 11, 2023 at 12:42:20AM +0100, Andrey Konovalov wrote: > On Wed, Mar 1, 2023 at 6:00 PM Catalin Marinas wrote: > > Yes. I'm including Vincenzo's patch below (part of fixing some potential > > strscpy() faults with its unaligned accesses eager reading; we'll get to > > posting that eventually). You can add some arch_kasan_enable/disable() > > macros on top and feel free to include the patch below. > > Ah, perfect! I'll send a patchset soon. Thanks! > > > Now, I wonder whether we should link those into kasan_disable_current(). > > These functions only deal with the depth for KASAN_SW_TAGS but it would > > make sense for KASAN_HW_TAGS to enable tag-check-override so that we > > don't need to bother with a match-all tags on pointer dereferencing. > > Using these TCO routines requires having (at least) migration disabled, right? Not necessarily. The TCO is set per CPU and disabling preemption (I don't think migration is sufficient) would work but these routines are also called on a uaccess fault path, so it needs to be preemptible. We used to clear TCO on exception entry prior to commit 38ddf7dafaea ("arm64: mte: avoid clearing PSTATE.TCO on entry unless necessary") but we restore it anyway on exception return. I think the only problem is if between these routines, we invoke cond_resched() directly. Not sure what the kasan code does but disabling preemption should avoid a reschedule. Another option is for mte_thread_switch() to context switch the TCO state. -- Catalin