Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5438131imm; Wed, 12 Sep 2018 06:08:14 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZB8XAlLbtbXx0xYSTXQt+NZLVLM0rFivJ8itiHvGBXbWfZVUOj41VboySKZkDSDgtJrBd4 X-Received: by 2002:a17:902:3081:: with SMTP id v1-v6mr2238426plb.58.1536757694881; Wed, 12 Sep 2018 06:08:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536757694; cv=none; d=google.com; s=arc-20160816; b=Ses7ElbGMskuOlR70XvLpSurrqpQ9TqixtY93XrHSESakjdMYru7ddjLGTgrq62zoI SmHC+TGAKFy6i0HDPX2LHtBgEqWPe44T7NWlBZMsSDyHr96Rr+lPenCBrmOysTOBEC9x KFyQxirOwWVBu6jLRetu8pcZ8qlQs/LhY/RCfrhQdaSbiWm1aMxM2bYi4c3LflazCTU9 ZxrP3fTKiucEqz0y6WfgTxsdnt2jVVr8cFyJG9qFGA7vb/88g5flejvMVGlJXdTkp5bI Sb4ebvX4Pij72aeRHCTYLE0iN9qYijVDXpPrRUvNXWySgY11CbiJqY7sniTMxAO+5tT8 mvdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=wBjTiNq5DsxZE0wwjx7D7uXkeFYhwZ7Gvy4Yly7Z7H4=; b=IOH1vo5TX2VrZxaHsFrXeDP3lISWum6vxoqFtR57XgIYpYT2ud7YSicZMgWBu7rKa+ VkiH6m7hjvYrG7zBpRWOCuNZsf8SMR3/yh1BY6Lw5NxPntZtZRWqrhkvF8gYeqlbf+ra WkCmCSIGllTXgaD8aZ8wipG1MbTEcnPbx2vDR1ZUZUvgLnIPdTvAEOsTSo7JzypIw9hu FNQZFWxFZtjq1haVUnGvp+erVuzdt3KyH2yBZQ6BQ/nx7mL6WrtG5vG+WEI0tDelDTmQ jC2AgilHhd8pp9lpZaS8zU+gysj3hnSFfmDenNn8ptkLF3gs/2V7xnheJV+9K2YOAWS1 R71A== 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 s7-v6si889159pfm.217.2018.09.12.06.07.59; Wed, 12 Sep 2018 06:08:14 -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 S1727122AbeILSLq (ORCPT + 99 others); Wed, 12 Sep 2018 14:11:46 -0400 Received: from foss.arm.com ([217.140.101.70]:59304 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726712AbeILSLq (ORCPT ); Wed, 12 Sep 2018 14:11:46 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EA54D80D; Wed, 12 Sep 2018 06:07:19 -0700 (PDT) Received: from [10.4.13.92] (e112298-lin.Emea.Arm.com [10.4.13.92]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 49B3E3F703; Wed, 12 Sep 2018 06:07:18 -0700 (PDT) Subject: Re: [PATCH v5 06/27] arm64: Delay daif masking for user return To: James Morse Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, daniel.thompson@linaro.org, joel@joelfernandes.org, marc.zyngier@arm.com, mark.rutland@arm.com, christoffer.dall@arm.com, catalin.marinas@arm.com, will.deacon@arm.com References: <1535471497-38854-1-git-send-email-julien.thierry@arm.com> <1535471497-38854-7-git-send-email-julien.thierry@arm.com> <59fa96d5-6bfa-c3aa-94d6-5941a7576bfa@arm.com> From: Julien Thierry Message-ID: Date: Wed, 12 Sep 2018 14:07:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <59fa96d5-6bfa-c3aa-94d6-5941a7576bfa@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi James, On 12/09/18 11:31, James Morse wrote: > Hi Julien, > > On 28/08/18 16:51, Julien Thierry wrote: >> Masking daif flags is done very early before returning to EL0. >> >> Only toggle the interrupt masking while in the vector entry and mask daif >> once in kernel_exit. > > I had an earlier version that did this, but it showed up as a performance > problem. commit 8d66772e869e ("arm64: Mask all exceptions during kernel_exit") > described it as: > | Adding a naked 'disable_daif' to kernel_exit causes a performance problem > | for micro-benchmarks that do no real work, (e.g. calling getpid() in a > | loop). This is because the ret_to_user loop has already masked IRQs so > | that the TIF_WORK_MASK thread flags can't change underneath it, adding > | disable_daif is an additional self-synchronising operation. > | > | In the future, the RAS APEI code may need to modify the TIF_WORK_MASK > | flags from an SError, in which case the ret_to_user loop must mask SError > | while it examines the flags. > > > We may decide that the benchmark is silly, and we don't care about this. (At the > time it was easy enough to work around). > > We need regular-IRQs masked when we read the TIF flags, and to stay masked until > we return to user-space. > I assume you're changing this so that psuedo-NMI are unmasked for EL0 until > kernel_exit. > Yes. > I'd like to be able to change the TIF flags from the SError handlers for RAS, > which means masking SError for do_notify_resume too. (The RAS code that does > this doesn't exist today, so you can make this my problem to work out later!) > I think we should have psuedo_NMI masked if SError is masked too. > Yes, my intention in the few daif changes was that PseudoNMI would have just a little bit more priority than interrupt: Debug > Abort > FIQ (not used) > NMI (PMR masked, PSR.I == 0) > IRQ (daif + PMR cleared) So if at any point I break this just shout. (I did that change because currently el0_error has everything enabled before returning). > > Is there a strong reason for having psuedo-NMI unmasked during > do_notify_resume(), or is it just for having the maximum amount of code exposed? > As you suspected, this is to have the maximum amount of code exposed to Pseudo-NMIs. Since it is not a strong requirement for Pseudo-NMI, if the perf issue is more important I can drop the patch for now. Although it would be useful to have other opinions to see what makes the most sense. Thanks, > > Thanks, > > James > >> diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S >> index 09dbea22..85ce06ac 100644 >> --- a/arch/arm64/kernel/entry.S >> +++ b/arch/arm64/kernel/entry.S >> @@ -259,9 +259,9 @@ alternative_else_nop_endif >> .endm >> >> .macro kernel_exit, el >> - .if \el != 0 >> disable_daif >> >> + .if \el != 0 >> /* Restore the task's original addr_limit. */ >> ldr x20, [sp, #S_ORIG_ADDR_LIMIT] >> str x20, [tsk, #TSK_TI_ADDR_LIMIT] >> @@ -896,7 +896,7 @@ work_pending: >> * "slow" syscall return path. >> */ >> ret_to_user: >> - disable_daif >> + disable_irq // disable interrupts >> ldr x1, [tsk, #TSK_TI_FLAGS] >> and x2, x1, #_TIF_WORK_MASK >> cbnz x2, work_pending >> > -- Julien Thierry