Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp330124pxb; Mon, 16 Aug 2021 06:28:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYWuaUvxMG7hFwtNkWslWRoSyiSeRY8gJk/dm/rjxhGR3pCm9akiVtFKHcemYIRUw4lF4x X-Received: by 2002:aa7:c519:: with SMTP id o25mr20485802edq.305.1629120512894; Mon, 16 Aug 2021 06:28:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629120512; cv=none; d=google.com; s=arc-20160816; b=0H6pIAE0iv2ZnZRJq3Fs6tmnOR8j+eSMJbeI9V6oYHLHzlEwkfpu8SMTP68BMVVjuR 0E8Kqhy4hObI5CAFOiQiBxIIHKnfNIpTeIu3RN5F5z4+vQdQFFkwsRv0RMeattGEbIU8 t/MW1AdMFfylbQ1L1cxRdvDMyYLH1q5eQNNubfZiIiGFoL2kGqqn7p+pyskLVbS+Zf9z ZAYq+GkDgrbhLt+ZXueo+EWNHdue7f4GUoVj5/LiTEiSzWBMxpmaryBx4cMrIj4NGEmK 91kS+C6NffDvryZwmhWjccGHeEsf33+GL9h9Z5VqMX+cdGlbD+PdSu8dKAx80+uinNEv rbqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NL2sI0ZvSQumuhHuK5gAmT8SamLfJHclevoKkOmtyfs=; b=HmVDac+METMubQNrB6rwyC45l2YopHO8PXPK8dW6UIKOrWzv6YOci3ZNwSX+xptJMf kwaoKAAw6LuZ0qVr8/+1ljiCEdM/eSol8xDpedMH3QGBsiFuUGOCY/xwWjS2CK9JQ1Vj H4SG1rQNuqiiFaP/UpsgARm3Z45xygyLxmRJ/4gVXV8Qd2aYR9b2BZjNlsyuM6t/LdO5 B/skBpJVdtXXMrrNMZriCAm3jzDM8YUE69hiEi26dw98gTorV1aXjN9ygJhm+4tXAB3j K2OPB17fKPfBkgfSvA85JuI/rY8yPFCXSA5sBnEaqWoWIhuYwKsCeUStN0B3gmNBfmb4 kB/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bSPlyrIK; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ga2si10955121ejc.213.2021.08.16.06.28.09; Mon, 16 Aug 2021 06:28:32 -0700 (PDT) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bSPlyrIK; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240914AbhHPNYm (ORCPT + 99 others); Mon, 16 Aug 2021 09:24:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:37182 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240257AbhHPNPC (ORCPT ); Mon, 16 Aug 2021 09:15:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 06EB5632D0; Mon, 16 Aug 2021 13:12:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1629119521; bh=ZZE+JhIRF95IGfF6gSywIH6p3aLm9Qh8DaaV98Yq+zk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bSPlyrIKSSWausNqY5t3ciXpDkWZEP63CPAJWqtsHEaES1IgVDlP7bFvhzvyq/hz8 uke5nIDX6rp6whwwamuIIWGVnQLJtTbVEdElBBnydiloryMgyy445CAbT2ez03hp0+ fuMsOMEIEamcLGexRa8YshKsS3IegjsLJ41NPmKo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vineet Gupta Subject: [PATCH 5.13 025/151] ARC: fp: set FPU_STATUS.FWE to enable FPU_STATUS update on context switch Date: Mon, 16 Aug 2021 15:00:55 +0200 Message-Id: <20210816125444.904803352@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210816125444.082226187@linuxfoundation.org> References: <20210816125444.082226187@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vineet Gupta commit 3a715e80400f452b247caa55344f4f60250ffbcf upstream. FPU_STATUS register contains FP exception flags bits which are updated by core as side-effect of FP instructions but can also be manually wiggled such as by glibc C99 functions fe{raise,clear,test}except() etc. To effect the update, the programming model requires OR'ing FWE bit (31). This bit is write-only and RAZ, meaning it is effectively auto-cleared after write and thus needs to be set everytime: which is how glibc implements this. However there's another usecase of FPU_STATUS update, at the time of Linux task switch when incoming task value needs to be programmed into the register. This was added as part of f45ba2bd6da0dc ("ARCv2: fpu: preserve userspace fpu state") which missed OR'ing FWE bit, meaning the new value is effectively not being written at all. This patch remedies that. Interestingly, this snafu was not caught in interm glibc testing as the race window which relies on a specific exception bit to be set/clear is really small specially when it nvolves context switch. Fortunately this was caught by glibc's math/test-fenv-tls test which repeatedly set/clear exception flags in a big loop, concurrently in main program and also in a thread. Fixes: https://github.com/foss-for-synopsys-dwc-arc-processors/linux/issues/54 Fixes: f45ba2bd6da0dc ("ARCv2: fpu: preserve userspace fpu state") Cc: stable@vger.kernel.org #5.6+ Signed-off-by: Vineet Gupta Signed-off-by: Greg Kroah-Hartman --- arch/arc/kernel/fpu.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/arch/arc/kernel/fpu.c +++ b/arch/arc/kernel/fpu.c @@ -57,23 +57,26 @@ void fpu_save_restore(struct task_struct void fpu_init_task(struct pt_regs *regs) { + const unsigned int fwe = 0x80000000; + /* default rounding mode */ write_aux_reg(ARC_REG_FPU_CTRL, 0x100); - /* set "Write enable" to allow explicit write to exception flags */ - write_aux_reg(ARC_REG_FPU_STATUS, 0x80000000); + /* Initialize to zero: setting requires FWE be set */ + write_aux_reg(ARC_REG_FPU_STATUS, fwe); } void fpu_save_restore(struct task_struct *prev, struct task_struct *next) { struct arc_fpu *save = &prev->thread.fpu; struct arc_fpu *restore = &next->thread.fpu; + const unsigned int fwe = 0x80000000; save->ctrl = read_aux_reg(ARC_REG_FPU_CTRL); save->status = read_aux_reg(ARC_REG_FPU_STATUS); write_aux_reg(ARC_REG_FPU_CTRL, restore->ctrl); - write_aux_reg(ARC_REG_FPU_STATUS, restore->status); + write_aux_reg(ARC_REG_FPU_STATUS, (fwe | restore->status)); } #endif