From patchwork Wed Aug 26 11:32:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 52720 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by patches.linaro.org (Postfix) with ESMTPS id EE46722E9E for ; Wed, 26 Aug 2015 11:32:15 +0000 (UTC) Received: by wicja10 with SMTP id ja10sf4981153wic.2 for ; Wed, 26 Aug 2015 04:32:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mime-version:in-reply-to:references :date:message-id:subject:from:to:cc:content-type:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe; bh=/zFLEuW93X7hgUurLZuPV36rYoqc0OG3IvuhyIo2DZI=; b=MLmeAd3aefFB3hcUMChwBwpijfItNK1rxRSUdmQhuZOxxQHsxROBh756Qb4CH/BWem cPQcbVTo1yvVlmFylYxdYPPzsS9usWjo3ku1t9jKSaPd/YXkGGoOUTH8mNkEA6IF2z/i xSRQmWFnD6ZkaLmKLuzg9X8CfSYZI5Njr3E0e7QhABz7cROkF/U20E7pkraW6YigsM2K PpOsufmAD1ya110OY+wRQktotovb4AM+/jaAzCpOnV0289xjlZib7H4Z93Izm6/pgL+2 nM0JgH1NVgR+IiYGAQRfCvaK+untHABI8ibg144Kdp9qhWj5WwGhUrefC157RgTCR4Tw Tlpg== X-Gm-Message-State: ALoCoQlR4QPyhHKfIkPzhUi6i55sd2C2uHQku95AYTYy8c/z+MPvLszok1SSkTtME0Dxa6ca1Psh X-Received: by 10.180.89.104 with SMTP id bn8mr2371046wib.4.1440588735252; Wed, 26 Aug 2015 04:32:15 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.207.38 with SMTP id lt6ls824174lac.50.gmail; Wed, 26 Aug 2015 04:32:15 -0700 (PDT) X-Received: by 10.112.204.162 with SMTP id kz2mr30509645lbc.115.1440588735029; Wed, 26 Aug 2015 04:32:15 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id kx10si18542261lac.157.2015.08.26.04.32.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Aug 2015 04:32:15 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by lalv9 with SMTP id v9so116981726lal.0 for ; Wed, 26 Aug 2015 04:32:15 -0700 (PDT) X-Received: by 10.152.203.134 with SMTP id kq6mr30546002lac.106.1440588734844; Wed, 26 Aug 2015 04:32:14 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.162.200 with SMTP id yc8csp3856494lbb; Wed, 26 Aug 2015 04:32:13 -0700 (PDT) X-Received: by 10.68.182.3 with SMTP id ea3mr68047376pbc.126.1440588733469; Wed, 26 Aug 2015 04:32:13 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e5si38165236pds.29.2015.08.26.04.32.08; Wed, 26 Aug 2015 04:32:13 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756394AbbHZLcG (ORCPT + 28 others); Wed, 26 Aug 2015 07:32:06 -0400 Received: from mail-io0-f170.google.com ([209.85.223.170]:32830 "EHLO mail-io0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753504AbbHZLcE (ORCPT ); Wed, 26 Aug 2015 07:32:04 -0400 Received: by iods203 with SMTP id s203so14648730iod.0 for ; Wed, 26 Aug 2015 04:32:03 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.107.16.33 with SMTP id y33mr2610473ioi.183.1440588723583; Wed, 26 Aug 2015 04:32:03 -0700 (PDT) Received: by 10.36.138.69 with HTTP; Wed, 26 Aug 2015 04:32:03 -0700 (PDT) In-Reply-To: <20150826111205.GD30466@arm.com> References: <1440556841-17219-1-git-send-email-chunyan.zhang@spreadtrum.com> <20150826111205.GD30466@arm.com> Date: Wed, 26 Aug 2015 13:32:03 +0200 Message-ID: Subject: Re: [PATCH] arm64: fix bug for reloading FPSIMD state after execve on cpu 0. From: Ard Biesheuvel To: Will Deacon Cc: Chunyan Zhang , Catalin Marinas , "linux-arm-kernel@lists.infradead.org" , "jianhua.ljh@gmail.com" , "orson.zhai@spreadtrum.com" , "xiongshan.an@spreadtrum.com" , "linux-kernel@vger.kernel.org" Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On 26 August 2015 at 13:12, Will Deacon wrote: > Hello, > > [adding Ard] > > On Wed, Aug 26, 2015 at 03:40:41AM +0100, Chunyan Zhang wrote: >> From: Janet Liu >> >> If process A is running on CPU 0 and do execve syscall and after sched_exec, >> dest_cpu is 0, fpsimd_state.cpu is 0. If at the time Process A get scheduled >> out and after some kernel threads running on CPU 0, process A is back in CPU 0, >> A's fpsimd_state.cpu is current cpu id "0", and per_cpu(fpsimd_last_state) >> points A's fpsimd_state, TIF_FOREIGN_FPSTATE will be clear, kernel will not >> reload the context during it return to userspace. so set the cpu's >> fpsimd_last_state to NULL to avoid this. > > AFAICT, this is only a problem if one of the kernel threads uses the fpsimd > registers, right? However, kernel_neon_begin_partial clobbers > fpsimd_last_state, so I'm struggling to see the problem. > I think the problem is real, but it would be better to set the fpsimd_state::cpu field to an invalid value like we do in fpsimd_flush_task_state() (note the memset erroneously initializes that field to CPU 0) This more accurately reflects the state of the process after forking, i.e., that its FPSIMD state has never been loaded into any CPU. diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index 44d6f7545505..c56956a16d3f 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -158,6 +158,7 @@ void fpsimd_thread_switch(struct task_struct *next) void fpsimd_flush_thread(void) { memset(¤t->thread.fpsimd_state, 0, sizeof(struct fpsimd_state)); + fpsimd_flush_task_state(current); set_thread_flag(TIF_FOREIGN_FPSTATE); }