Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2393146pxb; Tue, 23 Feb 2021 06:10:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJzkNe8XX9YQQ3pmzyokWxtJTI9sLEs9P5jNPUEL+grfin3bZK+mJrH0GlP0IJVuRcQaW6hy X-Received: by 2002:a17:906:8a5c:: with SMTP id gx28mr18819373ejc.51.1614089435114; Tue, 23 Feb 2021 06:10:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614089435; cv=none; d=google.com; s=arc-20160816; b=cO6qm2WwWFYKFq2X+9fJNufzIveZ8xPCRSKOZ3BYTW3G8gWrVpJWhFyH1S68qQggRk nQBrmY38J/uH1OVkpIO1vnBxf9dJdJX0Sbh07y30MXOybwKoFVuFzNsOQWRHtOOk95Sw OHgofvJwbU8uceWK9s7FPletgHy78rmLm8s9DrAARy/B7YTV9vqYVn0uM57NeUEguV4e MynHHFGZLW5b8Kd1svavPKs6W0XLiexyIVf/b+IHL6msfnZ90xaXD1+PatiWNYt6gQkz fwW1mdiN2u2KUkf/4NL/Ey6vMiUFA81jWzapvZ7ObNwygeHO2gi0E4SKPmPJJ5NTZpT8 L+vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=aCK1D2XoK3ZNpKwOYYHYBBPzNLPmHz17ljO1cfKu9pg=; b=vacjdHhkPJrBtmjMSMSi1MoB3UwgFeM6QVUQMiCTawWnZJ4kXCsALtpk1+ZoifeLkk CdQh13WenbzlcVTFOippftI5TACWtTLyTpx92x35bJDPRsJNl2/c7aqcuSkeBVcvW1AI /jVsnwWmkvEnmjjzvB0rcwWG5i+B86U3EI5ASqem+OhVUygWJYZdDsBt7JYecRHcvw6j qw0KjoxzoVC+h1AVwX8XCy4Q30RoeDOJgWKOlXM8NM3NSwyIF4cUAXfMZTrmh6AUPemY 1G8GXD1TctDrUlrepJ2zSZR0pZ8cda1JDSLiMuHg4i/rvX+Z0+kb1VtlHJZWPYD6dU+r RXOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k14si3405262ejp.62.2021.02.23.06.10.10; Tue, 23 Feb 2021 06:10:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232267AbhBWKyx (ORCPT + 99 others); Tue, 23 Feb 2021 05:54:53 -0500 Received: from foss.arm.com ([217.140.110.172]:42674 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231776AbhBWKxm (ORCPT ); Tue, 23 Feb 2021 05:53:42 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4786F31B; Tue, 23 Feb 2021 02:52:33 -0800 (PST) Received: from [10.37.8.9] (unknown [10.37.8.9]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4D57E3F70D; Tue, 23 Feb 2021 02:52:31 -0800 (PST) Subject: Re: [PATCH v13 4/7] arm64: mte: Enable TCO in functions that can read beyond buffer limits To: Catalin Marinas Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Andrew Morton , Will Deacon , Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Branislav Rankov , Andrey Konovalov , Lorenzo Pieralisi References: <20210211153353.29094-1-vincenzo.frascino@arm.com> <20210211153353.29094-5-vincenzo.frascino@arm.com> <20210212172128.GE7718@arm.com> <20210222175825.GE19604@arm.com> From: Vincenzo Frascino Message-ID: <6111633c-3bbd-edfa-86a0-be580a9ebcc8@arm.com> Date: Tue, 23 Feb 2021 10:56:46 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20210222175825.GE19604@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/22/21 5:58 PM, Catalin Marinas wrote: > That's because cpu_hotplug_lock is not a spinlock but a semaphore which > implies sleeping. I don't think avoiding taking this semaphore > altogether (as in the *_cpuslocked functions) is the correct workaround. > Thinking at it a second time I agree, it is not a good idea avoiding to take the semaphore in this case. > The mte_enable_kernel_async() function is called on each secondary CPU > but we don't really need to attempt to toggle the static key on each of > them as they all have the same configuration. Maybe do something like: > > if (!static_branch_unlikely(&mte_async_mode))) > static_branch_enable(&mte_async_mode); > > so that it's only set on the boot CPU. > This should work, maybe with a comment that if we plan to introduce runtime switching in between async and sync in future we need to revisit our strategy. > The alternative is to use a per-CPU mask/variable instead of static > branches but it's probably too expensive for those functions that were > meant to improve performance. > I would not go for this approach because the reason why we introduced static branches instead of having a normal variable saving the state was performances. > We'll still have an issue with dynamically switching the async/sync mode > at run-time. Luckily kasan doesn't do this now. The problem is that > until the last CPU have been switched from async to sync, we can't > toggle the static label. When switching from sync to async, we need > to do it on the first CPU being switched. > I totally agree on this point. In the case of runtime switching we might need the rethink completely the strategy and depends a lot on what we want to allow and what not. For the kernel I imagine we will need to expose something in sysfs that affects all the cores and then maybe stop_machine() to propagate it to all the cores. Do you think having some of the cores running in sync mode and some in async is a viable solution? Probably it is worth to discuss it further once we cross that bridge. > So, I think currently we can set the mte_async_mode label to true in > mte_enable_kernel_async(), with the 'if' check above. For > mte_enable_kernel_sync(), don't bother with setting the key to false but > place a WARN_ONCE if the mte_async_mode is true. We can revisit it if > kasan ever gains this run-time switch mode. Indeed, this should work for now. -- Regards, Vincenzo