From patchwork Wed Feb 3 11:36:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 12064089 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C25ECC4332D for ; Wed, 3 Feb 2021 11:37:57 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 66D5064DDE for ; Wed, 3 Feb 2021 11:37:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 66D5064DDE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=1zsDIIxrNYljITqRTKaAfSjQuZ1fijZwuPGCd7odNXU=; b=q2u6vU748TpIQDixEFiFwQgnB gyA/AojUMHVdii5N8F9lwkh25Ky1uv9+XO6hQr+wR7aRyx27tgaoKgBnqxCpTXm4WVe5GsbqP03O6 Qkl8AZ0LyOsq8SXBR3xSuN9dHZAo8u4eCoCV4B4/tF5cOB6RR4U4O+wlcnr23utzm0ilDGDheFOas lRAuwyq4CkxoTC75aQjBfsAaq6svBp4ITPR6Jui4sfNBfjFSj6p4MkT077gNPcswTztJ4OQFAbjGw PVLxJ3RhToQQx/1QZLNg7B8ZZXPGQRnXIy8w2989jrxR9bUj2mq6CJWgTPWolvsjIeI8iX4J/NiTM 2yqb8nfcQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l7GSk-00038N-58; Wed, 03 Feb 2021 11:36:46 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l7GSh-00037b-P8 for linux-arm-kernel@lists.infradead.org; Wed, 03 Feb 2021 11:36:44 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2292364F6A; Wed, 3 Feb 2021 11:36:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612352203; bh=Xc42wbe+fvjMDLso7dVj/MJDqK9qPTmqNYGr08Z/sw8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fJUqzRNao28ge92zSxTOSRmt1sP3jV+1lcSkdVXRjk3Oq2dwbCITthYFAMK+KQUqp ZvRdBX9nvSo9ml+dt12FRdkDBOZSGYKdvBR2jnNBDokCpkK4QStuor4FTk661TiKCE TTZj6xKk1tEX51ToFCwLElD9gt4aLz8t2YpaBtHzRVZT8jjKgnDLD2Tj+5tH6dL9Gp Go+xCDSwnYyCmE9/94Du7QPt7VK4Y+jkJa7QYnCCyt7ziUjw8ZwAQW2XR+5G/rVkaU BfJYrJjq2e/YCfJpcbWbrjHKzImaIgVvFGRTIt+R9RNS74Tkyd9xGAndbwIFGZA/Zy uqF85HUlkWMng== From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Subject: [PATCH v2 1/9] arm64: assembler: add cond_yield macro Date: Wed, 3 Feb 2021 12:36:18 +0100 Message-Id: <20210203113626.220151-2-ardb@kernel.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210203113626.220151-1-ardb@kernel.org> References: <20210203113626.220151-1-ardb@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210203_063643_921063_46FD794C X-CRM114-Status: GOOD ( 12.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, herbert@gondor.apana.org.au, Eric Biggers , catalin.marinas@arm.com, Dave Martin , will@kernel.org, Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a macro cond_yield that branches to a specified label when called if the TIF_NEED_RESCHED flag is set and decreasing the preempt count would make the task preemptible again, resulting in a schedule to occur. This can be used by kernel mode SIMD code that keeps a lot of state in SIMD registers, which would make chunking the input in order to perform the cond_resched() check from C code disproportionately costly. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/assembler.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index bf125c591116..27b1ea721c2d 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -745,6 +745,22 @@ USER(\label, ic ivau, \tmp2) // invalidate I line PoU .Lyield_out_\@ : .endm + /* + * Check whether preempt-disabled code should yield as soon as it + * is able. This is the case if re-enabling preemption a single + * time results in a preempt count of zero, and the TIF_NEED_RESCHED + * flag is set. (Note that the latter is stored negated in the + * top word of the thread_info::preempt_count field) + */ + .macro cond_yield, lbl:req, tmp:req +#ifdef CONFIG_PREEMPTION + get_current_task \tmp + ldr \tmp, [\tmp, #TSK_TI_PREEMPT] + sub \tmp, \tmp, #PREEMPT_DISABLE_OFFSET + cbz \tmp, \lbl +#endif + .endm + /* * This macro emits a program property note section identifying * architecture features which require special handling, mainly for