From patchwork Mon Jul 12 06:06:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 472888 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp2655526jao; Sun, 11 Jul 2021 23:42:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVJgpiusmpWI3/XPctfq7wmphwFWto/XN7K57EFJUEqkFVws+U+yhfzwx/HM8z5t7wQLXp X-Received: by 2002:aa7:c550:: with SMTP id s16mr2112381edr.130.1626072131825; Sun, 11 Jul 2021 23:42:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626072131; cv=none; d=google.com; s=arc-20160816; b=Ou7yRpW6i6i+ZcE+O0D/BknUEvS1Um3EffhLWzYTIZPJhiJzEbGVB3yXxYgD1BCBS9 WNAFiC+oXo1OYlMLHt9NV1Kcw21W8UAdjbpB/7BS/7NIyFY43vyTQrUytp/N3Na2LHcc CdAMp75yq+6bdvLp92VL8z82W7ZLxmso0UJIEv4hCmAH+lBDr6VVi6166pttupDYR4Og PWrurDXcHpFGStFo3rUrH4bbmnMW3z/9qdhxy4MyfXPLnksW0A22GGhU/ZK1tg9AJsht X2AWuR2BycBReohNWaOEBYKGjg1QOrdIjLpCyz+qUiWMCvAsurkmZRRKFgP6WaEq05Nh aSXQ== 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=oIQoqQNp7YJZKYVaV7XOUB8cTTkuOwbyvsi9P1avW80=; b=RZqLxz806QT/dJTBEulb6gRaW1gomHIgOdax5ZQcC4K/+J9P+vZv8PIOLJlj31i4FW SyCMyqo7uWOxzGBJ4haGAhbgmXlu/UMKuuRyfi9IVIs2D45rPxrnDU1F9650izra8QdW OaojDf7KEayRPtj8gyy7jacnDi72lodsyx5zt+PSyaY/XqCz5qCySKB8ojIAmkjWYQTZ faDwjQJTxnC9XykWOGuBFEg37umgNVx3l1kzcEx2HzrzLXeaQCX8e5eWKJBh6KCZYn/W PlxQGmNY1a23fY53EOV2gvi0m4os3urZipACvwWdfQ/Cj7r4Q10Y5OUAc7kOHiZZMCyy si+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ksmYqP1l; 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 en10si16062540ejc.118.2021.07.11.23.42.11; Sun, 11 Jul 2021 23:42:11 -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=ksmYqP1l; 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 S237215AbhGLGnD (ORCPT + 12 others); Mon, 12 Jul 2021 02:43:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:34338 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237724AbhGLGl2 (ORCPT ); Mon, 12 Jul 2021 02:41:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 50419610CA; Mon, 12 Jul 2021 06:38:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626071913; bh=5SoCWH5JaG4EXaEbh41gL2yVFEpy/H4SD+E5JGSjuCI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ksmYqP1llZNJjUl784fVzw8RfrLTOM2qFUJDv8dkkcb01FoEEn+cL7GZA79WaHUJ7 0z/Bi4dwFYOzl8Wj5m0asnGwowClsSg84F4hfywNP3q2Dp4RZOfh7TQx1vh5+F1ECb BcMKQgEXjJeLw6hPh0o+IQ7aGGcsOWYayGsniG8I= 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.10 247/593] arm64/mm: Fix ttbr0 values stored in struct thread_info for software-pan Date: Mon, 12 Jul 2021 08:06:47 +0200 Message-Id: <20210712060910.080337535@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060843.180606720@linuxfoundation.org> References: <20210712060843.180606720@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 68028de06d18..5a54a5ab5f92 100644 --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -192,9 +192,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 c28a9ec76b11..eb4b24652c10 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -366,7 +366,7 @@ void __init __no_sanitize_address 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 if (boot_args[1] || boot_args[2] || boot_args[3]) {