From patchwork Mon Jul 12 06:09:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 472843 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp2644203jao; Sun, 11 Jul 2021 23:23:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBLusOeIxdm4TRm46YirhZrj1ocpmSKAmlmhBDjoQKWm5ZgewKDOTmJQlH/fqRf8lUGtiu X-Received: by 2002:a17:906:f751:: with SMTP id jp17mr28105966ejb.105.1626070952504; Sun, 11 Jul 2021 23:22:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626070952; cv=none; d=google.com; s=arc-20160816; b=kAqKDxxoAZ/TKpuzWS7wC4DMWLyqVnIxelSOtSNNG5MbtBfjkQ4Mh9TwNS3BDVuxrL 9z7sHdOJaO1a0Vq48E773WmY/ySohC4ACopFTcTmCBsC391YpiZ3Q/+WYgt5O0UNlG2o ZRwc0B2q9zEP8gk27tPDQ1fFd7khXM36w5OfcLCdbTSYeYn8X2coVCJg4f79rLeSRS6S uFSsf64p134VdvzK5Ayt7lqTeZRSVavRpI9DutqlA5YmE4ClgeHjzPaWffhh6u5iuemR Qqfx2tzwKW29opfqXSWeVCOjcJkcrKb7uVG7iXEe/Myd/7PTU+hFd+XYlFcDWhfbOCZk GzTA== 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=Onskc4Z+0zVMFWrkS4MC0k5SbVTc5KNFZU0yfCYpNYQ=; b=UAaTEIl0ZBlseXtFA7icUlGb/ZBqkG8Zf7weOom99/b7BlSU7SBPHQu0k5StzlRVwE xTPQ2n0jFsn1UvWWWsLfL0F2oSy+s8vr8K6Yi6cKof/wiJA/hKZhPzopHmOVt0J6f8z9 5jPY08sOSdf8xS77GWGQQB0bK9o40G6uRTIsNujd7OmbH5d06dCy2a86NDq7eLXnpqCi lyCMNm2398BLk/4Y5l80Fnyt0DBPKl5uSUVQ0f+lb8HGt1xz3hrEfYpZlSpxCwhw24W/ htCQZ+st7Ifo6TYdTSKN+jwATCEAPeawI7mcQfXsC38GVRm4uyOH6kgrEtNHCRd9p3L3 1gFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dpJCWSGx; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 dn7si8190642ejc.635.2021.07.11.23.22.32; Sun, 11 Jul 2021 23:22:32 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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=dpJCWSGx; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S234421AbhGLGZO (ORCPT + 12 others); Mon, 12 Jul 2021 02:25:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:38730 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235153AbhGLGYd (ORCPT ); Mon, 12 Jul 2021 02:24:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F20E9610CA; Mon, 12 Jul 2021 06:21:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626070880; bh=w7CfMYTFz6LkQrEyImXPHHBUegV6pBdKCltI4bcHC9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dpJCWSGxcJB2Cf+6jefvqbYtLZaPHR+YvLb/AQ5MibOVhoZBGM/WW09xEPKVvfo7P 43AEaaCMRjNQExO8+zTg6FbGKSKSS/EIHVjhWUQunYq0+6wMZ7nslSA0w0donkkYRn ubD0tRBzwhbBCqN2r3D3dKY9hzQuJqfYT3Jc7Amw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , James Morse , linux-arm-kernel@lists.infradead.org, Anshuman Khandual , Sasha Levin Subject: [PATCH 5.4 163/348] arm64/mm: Fix ttbr0 values stored in struct thread_info for software-pan Date: Mon, 12 Jul 2021 08:09:07 +0200 Message-Id: <20210712060722.570590411@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060659.886176320@linuxfoundation.org> References: <20210712060659.886176320@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Anshuman Khandual [ Upstream commit 9163f01130304fab1f74683d7d44632da7bda637 ] When using CONFIG_ARM64_SW_TTBR0_PAN, a task's thread_info::ttbr0 must be the TTBR0_EL1 value used to run userspace. With 52-bit PAs, the PA must be packed into the TTBR using phys_to_ttbr(), but we forget to do this in some of the SW PAN code. Thus, if the value is installed into TTBR0_EL1 (as may happen in the uaccess routines), this could result in UNPREDICTABLE behaviour. Since hardware with 52-bit PA support almost certainly has HW PAN, which will be used in preference, this shouldn't be a practical issue, but let's fix this for consistency. Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Cc: James Morse Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Fixes: 529c4b05a3cb ("arm64: handle 52-bit addresses in TTBR") Signed-off-by: Anshuman Khandual Reviewed-by: Catalin Marinas Link: https://lore.kernel.org/r/1623749578-11231-1-git-send-email-anshuman.khandual@arm.com Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- arch/arm64/include/asm/mmu_context.h | 4 ++-- arch/arm64/kernel/setup.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) -- 2.30.2 diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h index 1355205e5da5..fb564de90aa7 100644 --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -184,9 +184,9 @@ static inline void update_saved_ttbr0(struct task_struct *tsk, return; if (mm == &init_mm) - ttbr = __pa_symbol(reserved_pg_dir); + ttbr = phys_to_ttbr(__pa_symbol(reserved_pg_dir)); else - ttbr = virt_to_phys(mm->pgd) | ASID(mm) << 48; + ttbr = phys_to_ttbr(virt_to_phys(mm->pgd)) | ASID(mm) << 48; WRITE_ONCE(task_thread_info(tsk)->ttbr0, ttbr); } diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 203a0c31f260..f55f4a15a905 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -356,7 +356,7 @@ void __init setup_arch(char **cmdline_p) * faults in case uaccess_enable() is inadvertently called by the init * thread. */ - init_task.thread_info.ttbr0 = __pa_symbol(reserved_pg_dir); + init_task.thread_info.ttbr0 = phys_to_ttbr(__pa_symbol(reserved_pg_dir)); #endif #ifdef CONFIG_VT