From patchwork Mon Oct 28 22:39:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854246 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4494AD5B845 for ; Mon, 28 Oct 2024 22:41:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=o4FvxagpzjxZSStnbXoR4/Vp7sTpyCwQgUO0IG3vegk=; b=w7K1+dsFZ2QpYs7bf21wBY414h RFrlWC4F8ssQ7tUsa8FwdM1rTKDdSldCD3/hJ+nq/xXm4FLQB9tQdWA5CmZ1fVTtTY2/Je/4OMip8 Dw27RipnDVCAOO6sM/Q/KjJurCDapf8DqaRSPrnwnu7gtB1uaqbOmUmVKKn2VgXBS6D/+4lvDKvGp F7W0iWt7VUNyaEzgunyG3YyXf6aEihCFvhyQigtzxXSR1EsSZ4hgZQbsoxeoVn8hxcO8AnczI22Yk 90YS6OvqHQ2xi93z+U/3RE6ta2wqxMiqEAzNb4q4d6VCZUjPIif69XfYxjh418eIprvjc+Wh95dfU 5DUdpKcQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5YQg-0000000CXwU-3iOm; Mon, 28 Oct 2024 22:41:42 +0000 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5YP3-0000000CXqP-3LCK for linux-arm-kernel@lists.infradead.org; Mon, 28 Oct 2024 22:40:03 +0000 Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2fb51e00c05so70296841fa.0 for ; Mon, 28 Oct 2024 15:40:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730155200; x=1730760000; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=o4FvxagpzjxZSStnbXoR4/Vp7sTpyCwQgUO0IG3vegk=; b=DhkFLEEEuXhwukDkenKAK4kosDyi2jAa7Rb9RLxFKyQ2oguGQtc0EJGTVvUwjz6nfC ksLsLVviTOAOyvp1MjbTKK5IPOJEAGr94EiuCPCO2pcDi3nU6AlCeUWjlUZsrDc8Mjop 22oTHTuGRBp8yiu/qNC/XsPscc2rdRoceN62nzZ2ds/i/GpdG7p2SR0r9HwFMSThocoq jc4S4tczCr1ovNOr/e+2qYue6EkbXOL1GuffxWsWbHctAHOojDmqQqo8oThd7MFU31Qp sSFObU1rmfI+jo2duY7U5Z2vUJhBR5wv8KeT2jMfszQRwntVh6bQ21CzdIecKcWSnzPL PVJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730155200; x=1730760000; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o4FvxagpzjxZSStnbXoR4/Vp7sTpyCwQgUO0IG3vegk=; b=bBML1cDpHouVWsZN1tE12cx5F/z5TbiR+KB+HbKwOci9zop9S4rEr0iSzyeb12Z8/V xt4V+5hf7Q+9J2hJFZOBl8+cwzZFkwcFhEMFOFzOVGmz+063W78A+oF6xhL4kQHZLr/y tU67J7kp/V/CRbu6+4McmSQ9+IPBRqvkUWhqCCuA7qJhkzAFl+iCjW6uysm6AZNsZL8F YsJfZ3rSQpA8588KXm5zXsGc+8YTyx+0EbCRfChrOddw/oay/sAkT61QGMgx0OPF9nhi YSBWNdCcooEUsd9VGtK6fYrpRJPirMGlozjNQ38RJ71gM4PPAvEc04LLvFGYNQQQLHAj 9yCg== X-Gm-Message-State: AOJu0YzhkZqUQE9jFyeWwOBMCbovb+H88LJEyZDTq75Nsvpwl/FTtSn7 NISXEjFPPT0I8Ce3ozKfDoaM7upLldcKuba3llF1adQ0Mf+HNjJi0us4SmFyLcU= X-Google-Smtp-Source: AGHT+IEqkiyR2pvRELICkbistcdpZC3pulGLc6gT6MbaAKcOnjYY7LJUVhv1Cjw5G5zRZ1aSLbUo9A== X-Received: by 2002:a2e:4609:0:b0:2fc:9674:60b5 with SMTP id 38308e7fff4ca-2fcbdfc9295mr56280631fa.25.1730155200002; Mon, 28 Oct 2024 15:40:00 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2fcb451caa2sm12648561fa.36.2024.10.28.15.39.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 15:39:59 -0700 (PDT) From: Linus Walleij Date: Mon, 28 Oct 2024 23:39:58 +0100 Subject: [PATCH 1/2] ARM: entry: Do a dummy read from VMAP shadow MIME-Version: 1.0 Message-Id: <20241028-comments-in-switch-to-v1-1-7280d09671a8@linaro.org> References: <20241028-comments-in-switch-to-v1-0-7280d09671a8@linaro.org> In-Reply-To: <20241028-comments-in-switch-to-v1-0-7280d09671a8@linaro.org> To: Russell King , Ard Biesheuvel Cc: linux-arm-kernel@lists.infradead.org, Linus Walleij , stable@vger.kernel.org, Clement LE GOFFIC X-Mailer: b4 0.14.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241028_154001_893939_20B74240 X-CRM114-Status: GOOD ( 12.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When switching task, in addition to a dummy read from the new VMAP stack, also do a dummy read from the VMAP stack's corresponding KASAN shadow memory to sync things up in the new MM context. Cc: stable@vger.kernel.org Fixes: a1c510d0adc6 ("ARM: implement support for vmap'ed stacks") Link: https://lore.kernel.org/linux-arm-kernel/a1a1d062-f3a2-4d05-9836-3b098de9db6d@foss.st.com/ Reported-by: Clement LE GOFFIC Suggested-by: Ard Biesheuvel Signed-off-by: Linus Walleij --- arch/arm/kernel/entry-armv.S | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S index 1dfae1af8e31..ef6a657c8d13 100644 --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -25,6 +25,7 @@ #include #include #include +#include #include "entry-header.S" #include @@ -561,6 +562,13 @@ ENTRY(__switch_to) @ entries covering the vmalloc region. @ ldr r2, [ip] +#ifdef CONFIG_KASAN_VMALLOC + @ Also dummy read from the KASAN shadow memory for the new stack if we + @ are using KASAN + mov_l r2, KASAN_SHADOW_OFFSET + add r2, r2, ip, lsr #KASAN_SHADOW_SCALE_SHIFT + ldr r2, [r2] +#endif #endif @ When CONFIG_THREAD_INFO_IN_TASK=n, the update of SP itself is what From patchwork Mon Oct 28 22:39:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13854250 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1CA73D5B846 for ; Mon, 28 Oct 2024 22:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=leKULRwFrUrUHl+gqC5TSoYb0TiNILSW4aeMxjzqon8=; b=B1VI4w9vYapuPMEM9x62XFyYKf LGVMN/GeBAqFF3pwXBbSkGFJUzuM10WPIn45cUE07jU4vyKgO6HnJ+soPySZiZ3gfOubvjt+YzHMQ 4+zrzx1N2TgJ+ldTndpvLdKed9PwGW2NfO4El3+CejRb5cM2EDEQZtdsbS745bE5ecJ6Xhbb3VyOc srd23ykgLaj/jiZvfnUDz4EJGP5I+rJ2PsN7CBsAwA1SMe3NqSCIXZOh81GC78+quto5BCg0nm/qc bkcu3GxVQKm1FzJjgb514dSUogz2J73j+HkQCOdcBxu4AXBRdr+ruhXwNVSjMOV+dSIiKjp4yQMog zWdqx8Ug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t5YTt-0000000CYiI-3hmQ; Mon, 28 Oct 2024 22:45:01 +0000 Received: from mail-lj1-x22f.google.com ([2a00:1450:4864:20::22f]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t5YP5-0000000CXqS-0Sl3 for linux-arm-kernel@lists.infradead.org; Mon, 28 Oct 2024 22:40:05 +0000 Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2fc96f9c41fso48077221fa.0 for ; Mon, 28 Oct 2024 15:40:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730155201; x=1730760001; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=leKULRwFrUrUHl+gqC5TSoYb0TiNILSW4aeMxjzqon8=; b=V5GOSJckJuzYIeIPkOvdHRljDMS56M/trIPEIUOxiqrE7b2JJQZOohmgPCm4vjB+MS f0ygIzS6tCQgzq5yK1YbkC2IHFQnJ3lNf1O/TwU8nc6BCfKrFlEN7hsW+YaTvvMKxr4v pWprHsJutmTaJwiIzE3Gb18dKlil3yggIWtpVTNcUTuD2OHbICkRn7AMsAcyEvBxUibT DULwyY+xDRy/bExyVv1/6TBoQTuDo0CuuCNIRC5+zX4h4cV9IlosxUP0xVn7yp/sAZXh yVJigi/WtvbLnqkGoEiQ7uj6cGbYKQ4R7NLGJR8VNTZ15uGn/r+hJIPGxDKzyNJ1d9Jc vMbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730155201; x=1730760001; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=leKULRwFrUrUHl+gqC5TSoYb0TiNILSW4aeMxjzqon8=; b=MSiJplxvL8TQa+Q54xkcoCLEX+FugLExtSbfMlvS18MjPYpMF0GsfBUJRiffKEd42E atxeriqKAf7kNs1vIKTY2uSwCICjM4owEH2D15rEHjUv/f9eu+vc3wQPXNLiw5kXZm4R Zn2EaKNvyXDS/Lhwu+WnzkYaFN0AVpFUp3yEZJBGo9ug+eitC/gXDbmAK4Ct6wyor15Y lcyTFHwdjVqPTkllHuDfWEpvwOOtj9kAFq4a9N5EzP3g470Ef1qRGpchwsZhn9erdlR+ LHPdP6it1plz/tJIbJiE6WyF+8xko78P/dhI4kh/ihb3mcFy8xqOQvXFNiU0j1DJI3f2 +xlA== X-Gm-Message-State: AOJu0Yx9cl1JuB9yUjsBwvIEgWOKym6B61mwBLXEEwpoyZrDOyLCHGar hPenNxlWeBv9efomtU+kKTyMsFMTcTnqGU/2gb164UYmF46Iszo1H9V779fM6WQ= X-Google-Smtp-Source: AGHT+IFonm/0d6VzeJyq2z2GBjua9udVbBmqU2gCcyAAFcnWLjIbIE7Nn3A6tdQNHkzfUmh4gEGnog== X-Received: by 2002:a2e:ab06:0:b0:2fa:c185:ac4e with SMTP id 38308e7fff4ca-2fcdc7ab519mr286331fa.13.1730155200651; Mon, 28 Oct 2024 15:40:00 -0700 (PDT) Received: from lino.lan ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2fcb451caa2sm12648561fa.36.2024.10.28.15.40.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2024 15:40:00 -0700 (PDT) From: Linus Walleij Date: Mon, 28 Oct 2024 23:39:59 +0100 Subject: [PATCH 2/2] ARM: entry: expand comment in __switch_to MIME-Version: 1.0 Message-Id: <20241028-comments-in-switch-to-v1-2-7280d09671a8@linaro.org> References: <20241028-comments-in-switch-to-v1-0-7280d09671a8@linaro.org> In-Reply-To: <20241028-comments-in-switch-to-v1-0-7280d09671a8@linaro.org> To: Russell King , Ard Biesheuvel Cc: linux-arm-kernel@lists.infradead.org, Linus Walleij , Mark Rutland X-Mailer: b4 0.14.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241028_154003_482283_6D5289BE X-CRM114-Status: GOOD ( 14.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org As per discussion between the developers in the mail thread linked, expand the comment in __switch_to so that readers of the code understand what is going on. Link: https://lore.kernel.org/linux-arm-kernel/ZxDh9biUbf9W8gNN@J2N7QTR9R3/ Suggested-by: Mark Rutland Signed-off-by: Linus Walleij --- arch/arm/kernel/entry-armv.S | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S index ef6a657c8d13..5c016c68b5a3 100644 --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -557,9 +557,16 @@ ENTRY(__switch_to) ldmia r4, {r4 - sl, fp, ip, lr} @ Load all regs saved previously #ifdef CONFIG_VMAP_STACK @ - @ Do a dummy read from the new stack while running from the old one so - @ that we can rely on do_translation_fault() to fix up any stale PMD - @ entries covering the vmalloc region. + @ For a non-lazy mm switch, check_vmalloc_seq() has ensured that + @ that the active mm's page tables have mappings for the prev + @ task's stack and the next task's stack. + @ + @ For a lazy mm switch the active mm's page tables have mappings + @ for the prev task's stack but might not have mappings for the + @ new taks stack. Do a dummy read from the new stack while + @ running from the old stack so that we can rely on + @ do_translation_fault() to fix up any stale PMD entries + @ covering the vmalloc region. @ ldr r2, [ip] #ifdef CONFIG_KASAN_VMALLOC