From patchwork Wed May 31 09:09:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Chan X-Patchwork-Id: 101297 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2741890vqr; Wed, 31 May 2023 02:21:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6hzrjfzVqS3hXb0UPDjt5O0xywrAPvr0MWZP9RfCWAfIrIQoroo1mrkzjfbYd7XbO/bSBH X-Received: by 2002:ae9:e80a:0:b0:75b:23a0:dec2 with SMTP id a10-20020ae9e80a000000b0075b23a0dec2mr4876002qkg.64.1685524902964; Wed, 31 May 2023 02:21:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685524902; cv=none; d=google.com; s=arc-20160816; b=HwjBolmh0iZhUZ2zMcrQtYBZ6e6riN7SY26QEGyhtch51uShpmbb/VQoZzeJXRf4R4 4lriDIusiIltyac/AJICIHtyEwF9oyKaAFANlsbG8LXn9SGIwmFwrCLVHUkCv6riTkdL +fAP/X6Sf7+ELscLYT2Dd4xA1Jse9XYdsZrrhK3EgT41G0kEb48xE0AHQGYbCiyfHXLC Gve8mS/ypxTLil8WVSsTNXo6n7oX0MNnKNFpHg3i8W2qTJCPEBVTLMuszunOMdp+H13V IjgEw1n0DwMJw9a0E3C0mUuQdhL0ZxyY/hVgQNx07tqxNZzajsGiqCSOCvZTfMBiq5OY mynQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=uDyUEUKWPkyh/YNSCkrScqS2AVFO7CTNEmU88s6Pdgk=; b=tascNFT9cuAzS9ljAfAFRGjGOOZJ0dK/qnw/rJltQWlWnxn373tLnUMUONjLTe8TnW LLMJh04BxU7b2FEnHEzaegOkeeE5SrIiufIWVUTg9ZzZ8pMn5PdiRw9d7rPuHgRlA7D0 jiJdxi8V/inJbm0Isg+FMJ/LPos0mJDjTNMD4xhZj7DQXGT7j3M68R0XJLVoso9+IQSi R6ootrJXITX0U/I0vd1FlI8/2qoYCmPj/D8VYwlrt4vj9EFLxhEMXT5jlTVJwA7z1Ww7 wogAuaCzlyeG5r39yq4eyU4kNAM310bG5gsyLP3FWP2va7j3XmaQ5S90By67eTmCe5iz VOqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=IDvx1FzI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m30-20020a637d5e000000b005194eaa611csi628551pgn.397.2023.05.31.02.21.29; Wed, 31 May 2023 02:21:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=IDvx1FzI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235364AbjEaJKz (ORCPT + 99 others); Wed, 31 May 2023 05:10:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235388AbjEaJJs (ORCPT ); Wed, 31 May 2023 05:09:48 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E41EE58 for ; Wed, 31 May 2023 02:09:17 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-bad0f5d6a7dso10699684276.0 for ; Wed, 31 May 2023 02:09:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685524155; x=1688116155; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=uDyUEUKWPkyh/YNSCkrScqS2AVFO7CTNEmU88s6Pdgk=; b=IDvx1FzI0zs8uomF/kYtxD5FQiXlgdcTWFeLWPSIgoNW+QgeAKm6njvIMJovu2Sz70 g66SXYGQ3eUlS5rMixU7zaGHV9pdFknoG7XY4MvFFxwEVFZF1xznZm7tGSft5ICPRX+r OZEdaSr4LxdfMCZXXsXHlaY55zFdqeXmcb8ogZ05Z9QkGIkpatTc3d7ITMq3dZv1fbot Ob2vItvFSgI9vSODMQFQBgWEyN/zUlQXyXZAy5RN8xblQCv0h14kJXOzzEitjpmoOWmz uD13m7tTxjLkWL1CfCpNBr7eL1T0bhOS2ltLWbNaWdkRMhBJ9wHK+wYrKZT5SJ0mOOf4 lfxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685524155; x=1688116155; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=uDyUEUKWPkyh/YNSCkrScqS2AVFO7CTNEmU88s6Pdgk=; b=ZFws3rYWakFsLTSCnLffXbK+zhC39dpiQgaUnfmm5aIrGcBi+OWj+cJbhYRh58t/Te c3O8aq1FK0W1XdZ2eiO+sFNWn3batrdyosNkWMTZyekWKVrjkCgZgEgwgYb18Q2HEyBl f+g34qRZifoyZqeeJzD9VS15I33RG1N2NvEKtlE7jJUf4uxOUdkWt2nvB+C5i4kfovxK RfJogkYv7lvQRJDPNr//EYr89Eig32P+3GAysdKgRqYcBm1LeMcu0ZNg+ilB6CAorvfu q8tq9I21hrN0FRNvhF1qyCBo7btqlGtUOgC4FI13oiLO84JtADHV+IYsbGAguUR44oga qWvQ== X-Gm-Message-State: AC+VfDwGYP7rgcqQb6pP2Rw/0pIPHmr3aYTF+qLniY0Q3amzC0+ywm3R 1WlmhseXavd/6ceYzh08ZOIEqtNQu5HGIopX X-Received: from ericchancf.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:4139]) (user=ericchancf job=sendgmr) by 2002:a25:818e:0:b0:ba8:736a:5bec with SMTP id p14-20020a25818e000000b00ba8736a5becmr3012561ybk.6.1685524155765; Wed, 31 May 2023 02:09:15 -0700 (PDT) Date: Wed, 31 May 2023 09:09:09 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Message-ID: <20230531090909.357047-1-ericchancf@google.com> Subject: [PATCH v2] arm64: lockdep: enable checks for held locks when returning to userspace From: Eric Chan To: Catalin Marinas , Will Deacon , Mark Rutland Cc: "Paul E . McKenney" , Anshuman Khandual , Frederic Weisbecker , Mukesh Ojha , Josh Poimboeuf , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Eric Chan X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767400960258866908?= X-GMAIL-MSGID: =?utf-8?q?1767400960258866908?= Currently arm64 doesn't use CONFIG_GENERIC_ENTRY and doesn't call lockdep_sys_exit() when returning to userspace. This means that lockdep won't check for held locks when returning to userspace, which would be useful to detect kernel bugs. Call lockdep_sys_exit() when returning to userspace, enabling checking for held locks. At the same time, rename arm64's prepare_exit_to_user_mode() to exit_to_user_mode_prepare() to more clearly align with the naming in the generic entry code. Signed-off-by: Eric Chan Acked-by: Mark Rutland --- arch/arm64/kernel/entry-common.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c index 3af3c01c93a6..9d6827201b6c 100644 --- a/arch/arm64/kernel/entry-common.c +++ b/arch/arm64/kernel/entry-common.c @@ -126,7 +126,7 @@ static __always_inline void __exit_to_user_mode(void) lockdep_hardirqs_on(CALLER_ADDR0); } -static __always_inline void prepare_exit_to_user_mode(struct pt_regs *regs) +static __always_inline void exit_to_user_mode_prepare(struct pt_regs *regs) { unsigned long flags; @@ -135,11 +135,13 @@ static __always_inline void prepare_exit_to_user_mode(struct pt_regs *regs) flags = read_thread_flags(); if (unlikely(flags & _TIF_WORK_MASK)) do_notify_resume(regs, flags); + + lockdep_sys_exit(); } static __always_inline void exit_to_user_mode(struct pt_regs *regs) { - prepare_exit_to_user_mode(regs); + exit_to_user_mode_prepare(regs); mte_check_tfsr_exit(); __exit_to_user_mode(); }