Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp712067ybl; Wed, 29 Jan 2020 08:23:06 -0800 (PST) X-Google-Smtp-Source: APXvYqwhu2RNGJL7UKjClv4KFR2BU2B0Frpkv/kNMeA7U/I0oHbkz6gOt8FS8W1/E7uW389WsE7J X-Received: by 2002:aca:b7c5:: with SMTP id h188mr7061098oif.100.1580314986215; Wed, 29 Jan 2020 08:23:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580314986; cv=none; d=google.com; s=arc-20160816; b=qRNJov3ASZ2INM/SLbhcm2FR7biCrRmYoiZ4C+iz9D5KhXclTBfB5Lv8M5R2z6/qID 4Z/xpGMc4FvPezwFO2I3SMDRWLvcg5jaLBWKmAJ3j/tah8LqMZbFKcwMyD2s+vgQfZ1v IXY7ZGWoIyZ0M1PemexG24RtGjtq0mPKp8qQvMBnbflqSAgmgO52nPTR1qUtQszHOPel JOoz1MYSVBR2332wpwkaKbKypdGT8uAsFdR2vFNiZbVZqiD47P2WzDbSwkNQWqWvCUwW n+4zp398tUAWkhZGVqN4ZncNTZ3QPEB7VsqUtGAsJqDyI9W2H+rUyXgHlHLXqBxDxtTv 96ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=xrgbbXZByQKFakJi0krsgsnHcL6vOC56gMP4fwCGMjM=; b=AM+iJz+qIooanNJvZFwcSXrQ0DV8EqXCBThxK6guuVnrA5aS6mHUzusMxFSHsElS4o 4cP9qhn7s1XQmSGUXdvrPa0jASudt/oF8KYDVuMu0I97vbqF+v4qC3Uo8Er7Rm57m3ur iKUOU7DpLvuDlpysHZEqkvrVfkQQ38C+qVoC+lQkVLu+s8X/kDxdOkbTaGLfQopnjKy/ hoBtwBRNEm9FRzZKvxBSwlCwRb2q/boZKT94ePhoB7bTHkiPxGrnYsXJFuw6bApHqKFI AnuZ+U5oCKR0+OMj2lHbYynb0H1SwkhZo1xPu5fHvwWNNCFnexJo3ei5/jk6EoV+nRrY AsjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NDoLZjcm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j17si1279631otl.278.2020.01.29.08.22.54; Wed, 29 Jan 2020 08:23:06 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=NDoLZjcm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726922AbgA2QNr (ORCPT + 99 others); Wed, 29 Jan 2020 11:13:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:37306 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726679AbgA2QNq (ORCPT ); Wed, 29 Jan 2020 11:13:46 -0500 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E7BB32070E; Wed, 29 Jan 2020 16:13:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580314426; bh=e1Wn9NnIjMDIS6BdQ81ViUrFBu9BQanXV+r3mteDX/8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NDoLZjcmTgTmmUvwERtMDcO6tlEHh3Q96S5jpo96owMURxgnSb9sBIeTNQPAGKcHp cE+e+lfn02eON+YzD4l3aiAm9xF6mEaBfMtZRHuJc8Dcam+do9KbQWv8q8T5EnlvSV qZ8ZLXHEB8aAb5Urm61xCkyDmLnJNpzsG8g8fJLI= Date: Wed, 29 Jan 2020 16:13:41 +0000 From: Will Deacon To: Srinivas Ramana Cc: Catalin Marinas , maz@kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org Subject: Re: [PATCH] arm64: Set SSBS for user threads while creation Message-ID: <20200129161341.GA32275@willie-the-truck> References: <1577106146-8999-1-git-send-email-sramana@codeaurora.org> <20200102180145.GE27940@arrakis.emea.arm.com> <0c5cd234-5cfb-d093-06e4-a0edb5c68bf8@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0c5cd234-5cfb-d093-06e4-a0edb5c68bf8@codeaurora.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 29, 2020 at 05:18:53PM +0530, Srinivas Ramana wrote: > On 1/2/2020 11:31 PM, Catalin Marinas wrote: > > On Mon, Dec 23, 2019 at 06:32:26PM +0530, Srinivas Ramana wrote: > > > Current SSBS implementation takes care of setting the > > > SSBS bit in start_thread() for user threads. While this works > > > for tasks launched with fork/clone followed by execve, for cases > > > where userspace would just call fork (eg, Java applications) this > > > leaves the SSBS bit unset. This results in performance > > > regression for such tasks. > > > > > > It is understood that commit cbdf8a189a66 ("arm64: Force SSBS > > > on context switch") masks this issue, but that was done for a > > > different reason where heterogeneous CPUs(both SSBS supported > > > and unsupported) are present. It is appropriate to take care > > > of the SSBS bit for all threads while creation itself. > > > > > > Fixes: 8f04e8e6e29c ("arm64: ssbd: Add support for PSTATE.SSBS rather than trapping to EL3") > > > Signed-off-by: Srinivas Ramana > > > > I suppose the parent process cleared SSBS explicitly. Isn't the child > > Actually we observe that parent(in case of android, zygote that launches the > app) does have SSBS bit set. However child doesn't have the bit set. On which SoC? Your commit message talks about heterogeneous systems (wrt SSBS) as though they don't apply in your case. Could you provide us with a reproducer? > > after fork() supposed to be nearly identical to the parent? If we did as > > you suggest, someone else might complain that SSBS has been set in the > > child after fork(). > > I am also wondering why would a userspace process clear SSBS bit loosing the > performance benefit. I guess it could happen during sigreturn if the signal handler wasn't careful about preserving bits in pstate, although it doesn't feel like something you'd regularly run into. But hang on a sec -- it looks like the context switch logic in cbdf8a189a66 actually does the wrong thing for systems where all of the CPUs implement SSBS. I don't think it explains the behaviour you're seeing, but I do think it could end up in situations where SSBS is unexpectedly *set*. Diff below. Will --->8 diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index bbb0f0c145f6..e38284c9fb7b 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -466,6 +466,13 @@ static void ssbs_thread_switch(struct task_struct *next) if (unlikely(next->flags & PF_KTHREAD)) return; + /* + * If all CPUs implement the SSBS instructions, then we just + * need to context-switch the PSTATE field. + */ + if (cpu_have_feature(cpu_feature(SSBS))) + return; + /* If the mitigation is enabled, then we leave SSBS clear. */ if ((arm64_get_ssbd_state() == ARM64_SSBD_FORCE_ENABLE) || test_tsk_thread_flag(next, TIF_SSBD))