Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2050913imm; Mon, 16 Jul 2018 00:57:48 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeVZQtlRxkV9Es7tAE9IhzyYawY1rdGvF8A/MWJIbt74CaOs75ypyUmqicjVM0dt0Pq82Za X-Received: by 2002:a17:902:2864:: with SMTP id e91-v6mr15356167plb.240.1531727868401; Mon, 16 Jul 2018 00:57:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531727868; cv=none; d=google.com; s=arc-20160816; b=ppMlKEjY8KpNOakNqgaqPc97Tcen4YuZH5wjh3eKRhjuxntiaqePrFUfEbhercrdbm XhKPqnHi3KQYTnDA6FMrOzw3USvkr5zwm9Z7JJYKaKs08rjITOezO5U650+v4LCpxyht yn02ArdZBNq60Mm9qHmiFt9xB4azKvLykew4+qBzk3Vw2nhv8NJmi74evnN2eZmEq50V 8VE8Mwe5jBLA94nNrPM0PY6s90mxpi7sv1GylQH1YZ/ZuCE/fMYDT2BKUKRnHIWtGe03 3XWbb7+OdbqlblWt71/R09zI8QrdVqw6CCxjgZJHPCx3HmG9xQ/I+rErZkRyILAIr2XV EpNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Bi3VON6PCs4jsYxtniwMcbjpZILcdG5Q9llPrir2mY4=; b=jb+xej4zYYJpOqFw18HptHxjiFp8Vrn1uOVHjGa6hg1gddHLFn6McWe/BnyNVO1Tgi AQv9gmuKNknWjZWqW+Kzec0fsZeHUKiez7lQGgDndcVvTTuU3E/AHLbpXOjNcvu6z4Tm fOsRqI2ZlDvI03z8LHeXvePoYasx7S8oGdkuu0e8xScAke1UOVoZJjt8dwllq40I1+BN gzfxrWyM4VICsPo0qBc6ThqbkYkYDxFbyinLzcrvU6Yep+dBWRmjGXgdpAP15dk56ZTn Iw2z0n7aj1FaSGOdqfJm2LJDYMgoKNfmtt+op5bRJYpjNBKw6T1M+jj9rcV2Fjc/3Z10 qBeA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l26-v6si24626024pfj.188.2018.07.16.00.57.33; Mon, 16 Jul 2018 00:57:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732099AbeGPIEK (ORCPT + 99 others); Mon, 16 Jul 2018 04:04:10 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46848 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728460AbeGPIEJ (ORCPT ); Mon, 16 Jul 2018 04:04:09 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 2E860CA0; Mon, 16 Jul 2018 07:38:08 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ard Biesheuvel , Dave Martin , Mark Rutland , Yandong Zhao , Will Deacon Subject: [PATCH 4.17 43/67] arm64: neon: Fix function may_use_simd() return error status Date: Mon, 16 Jul 2018 09:35:12 +0200 Message-Id: <20180716073449.988372943@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180716073443.294323458@linuxfoundation.org> References: <20180716073443.294323458@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.17-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yandong Zhao commit 2fd8eb4ad87104c54800ef3cea498c92eb15c78a upstream. It does not matter if the caller of may_use_simd() migrates to another cpu after the call, but it is still important that the kernel_neon_busy percpu instance that is read matches the cpu the task is running on at the time of the read. This means that raw_cpu_read() is not sufficient. kernel_neon_busy may appear true if the caller migrates during the execution of raw_cpu_read() and the next task to be scheduled in on the initial cpu calls kernel_neon_begin(). This patch replaces raw_cpu_read() with this_cpu_read() to protect against this race. Cc: Fixes: cb84d11e1625 ("arm64: neon: Remove support for nested or hardirq kernel-mode NEON") Acked-by: Ard Biesheuvel Reviewed-by: Dave Martin Reviewed-by: Mark Rutland Signed-off-by: Yandong Zhao Signed-off-by: Will Deacon Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/simd.h | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) --- a/arch/arm64/include/asm/simd.h +++ b/arch/arm64/include/asm/simd.h @@ -29,20 +29,15 @@ DECLARE_PER_CPU(bool, kernel_neon_busy); static __must_check inline bool may_use_simd(void) { /* - * The raw_cpu_read() is racy if called with preemption enabled. - * This is not a bug: kernel_neon_busy is only set when - * preemption is disabled, so we cannot migrate to another CPU - * while it is set, nor can we migrate to a CPU where it is set. - * So, if we find it clear on some CPU then we're guaranteed to - * find it clear on any CPU we could migrate to. - * - * If we are in between kernel_neon_begin()...kernel_neon_end(), - * the flag will be set, but preemption is also disabled, so we - * can't migrate to another CPU and spuriously see it become - * false. + * kernel_neon_busy is only set while preemption is disabled, + * and is clear whenever preemption is enabled. Since + * this_cpu_read() is atomic w.r.t. preemption, kernel_neon_busy + * cannot change under our feet -- if it's set we cannot be + * migrated, and if it's clear we cannot be migrated to a CPU + * where it is set. */ return !in_irq() && !irqs_disabled() && !in_nmi() && - !raw_cpu_read(kernel_neon_busy); + !this_cpu_read(kernel_neon_busy); } #else /* ! CONFIG_KERNEL_MODE_NEON */