Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1255334lqp; Sun, 14 Apr 2024 23:54:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXcoFo5zVBb9VmopuhfJCGZ3IChubqdtt2+S/yhx669nCwjtrw4gD9kWneVU3+4jRmEYmfkgyK2T5OkHEVKgT5997x18asuO0M2PGykJA== X-Google-Smtp-Source: AGHT+IHw4TwR6jGKUJE5IFgEbGUw438BEekwPvY9i40jv9CSFkTvo8Gc9cBNIj1vegSUPl8He3pb X-Received: by 2002:ac8:5d41:0:b0:436:f90c:f47b with SMTP id g1-20020ac85d41000000b00436f90cf47bmr2956923qtx.56.1713164072194; Sun, 14 Apr 2024 23:54:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713164072; cv=pass; d=google.com; s=arc-20160816; b=h7dIrNlWiDxvTpsy76n7Wo8Mx/zAgx9J/KftvLAuIT90nP4yQLeUfwGkLLOAi2bldD ZYyPPi2ybzKKIQyIOq9+e41fqNOFPUCMhtMI23bgL7il/TPrL+mYqGSYk5wiWSSff4ns 3wDG+F/oNL9tVeDaiLwgHIGpFJH9UU4IhpGe8NN3v01weVZ3FDLFfYEsEW0C4C4C14mK RgciFgq5BxSOonsbqeP/W19KpI8UeWOYbMxDLQlAd5KO30mJ3/AssgsTOh/mxs1ogZG+ dMlzWH18Ok91RECx74Jh71O1sr/BBzGVAKc6sCL345LVMA5jfh7lmb5FCv6xmLnMT2BT wi6A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=eGKlfeforlB9N6fqhDhyYKSzFnwARjqAnEA2CmxC89M=; fh=ACDzcgbaNdVZh5rYGX5uvjuD7vJOIVWNQkRf+hZhqPI=; b=r950NDwKgUxF+jl8hnNMXh0RT6YWaVAfgMiSM68MkGhbyWkUvUFJzDpm6mu2DV3Yra VKi2PM85X3BYfZGcZ6KPJKJ39o5ilk1sBi7QQJPENq13YF09J7DRh5P34t2vhd7U8CPi yxKPXFY3ytsAeZVMfBrKSNxUhN3P3c2dsXk06RBo4XFI43SyE6MU4NRyBaHAY9PwfFR7 Yi4eWvkcJCrthgsxZeC5R8lN967miHIU9jDH4HTn1PDUzX1ttyNenXMq0PTBU3AEgv1z Ma23H2pBGz2MvOCsMEXjAH/ikgPTltkkRt5Hq7HJJ2vtyRRxCJfDVQgb9RWzPSlo/Jm9 gJvA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-144613-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144613-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id o16-20020ac87c50000000b0043670e46857si8894137qtv.387.2024.04.14.23.54.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Apr 2024 23:54:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-144613-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-144613-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144613-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D65811C220D5 for ; Mon, 15 Apr 2024 06:54:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3DED1200D2; Mon, 15 Apr 2024 06:54:26 +0000 (UTC) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 176E61EB36 for ; Mon, 15 Apr 2024 06:54:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713164065; cv=none; b=uVWmOvaiMV7MYCS2OctcxrleveKQBsSOZ+CW4GTF59qSSl3k0ci+3JlV7mTi62sAC4hhZpyxQxnAKd44z50IglzuedLJYM2pGvCKa/esRBxgdKdwEh6bIWT4CF1NW4DYJXFCKfSq3H9E8rqOakoO7ZZdzFNqVAfLPMH00i+/KeA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713164065; c=relaxed/simple; bh=0RnzDr/VZ8xCydjZEczq565X/Ecb9JlD2VkomYimNoU=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=IlW/3h5lZWvKDouLYf9sribwNR/iTIuhrIschzQPavzYM3mmbW3yx5xD237CYITO4bDbq5Ip0sbmdIe0XAXvDNtBbIQtKa0gIhaFEpF3ZGpMnL8mbmG1E3Jrp3SYrqiQd2QdDrQJ7FwshZbvibk3USSqupalvJWVTZpBFzlHce8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4VHyVw32NlzXlJt; Mon, 15 Apr 2024 14:51:04 +0800 (CST) Received: from kwepemd200013.china.huawei.com (unknown [7.221.188.133]) by mail.maildlp.com (Postfix) with ESMTPS id F33521400CD; Mon, 15 Apr 2024 14:54:19 +0800 (CST) Received: from huawei.com (10.67.174.28) by kwepemd200013.china.huawei.com (7.221.188.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 15 Apr 2024 14:54:18 +0800 From: Liao Chang To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , Subject: [PATCH v3 0/8] Rework the DAIF mask, unmask and track API Date: Mon, 15 Apr 2024 06:47:50 +0000 Message-ID: <20240415064758.3250209-1-liaochang1@huawei.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemd200013.china.huawei.com (7.221.188.133) This patch series reworks the DAIF mask, unmask, and track API for the upcoming FEAT_NMI extension added in Armv8.8. As platform and virtualization[1] supports for FEAT_NMI is emerging, and Mark Brown's FEAT_NMI patch series[2] highlighted the need for clean up the existing hacking style approach about DAIF management code before adding NMI functionality, furthermore, we discover some subtle bugs during 'perf' and 'ipi_backtrace' transition from PSEUDO_NMI to FEAT_NMI, in summary, all of these emphasize the importance of rework. This series of reworking patches follows the suggestion from Mark Rutland mentioned in Mark Brown's patchset. In summary, he think the better way for DAIF manangement look likes as following: (a) Adding entry-specific helpers to manipulate abstract exception masks covering DAIF + PMR + ALLINT. Those need unmask-at-entry and mask-at-exit behaviour, and today only need to manage DAIF + PMR. It should be possible to do this ahead of ALLINT / NMI support. (b) Adding new "logical exception mask" helpers that treat DAIF + PMR + ALLINT as separate elements. This patches cherry-pick a part of Mark Brown' FEAT_NMI series, in order to pass compilation and basic testing, includes perf and ipi_backtrace. [1] https://lore.kernel.org/all/20240407081733.3231820-1-ruanjinjie@huawei.com/ [2] https://lore.kernel.org/linux-arm-kernel/Y4sH5qX5bK9xfEBp@lpieralisi/ v3->v2: 1. Squash two commits that address two minor issues into Mark Brown's origin patch for detecting FEAT_NMI. 2. Add one patch resolves the kprobe reenter panic while testing FEAT_NMI on QEMU. v2->v1: Add SoB tags following the origin author's SoBs. Liao Chang (5): arm64: daifflags: Add logical exception masks covering DAIF + PMR + ALLINT arm64: Unify exception masking at entry and exit of exception arm64: Deprecate old local_daif_{mask,save,restore} irqchip/gic-v3: Improve the maintainability of NMI masking in GIC driver arm64: kprobe: Keep NMI maskabled while kprobe is stepping xol Mark Brown (3): arm64/sysreg: Add definitions for immediate versions of MSR ALLINT arm64/cpufeature: Detect PE support for FEAT_NMI arm64/nmi: Add Kconfig for NMI arch/arm64/Kconfig | 17 ++ arch/arm64/include/asm/cpufeature.h | 6 + arch/arm64/include/asm/daifflags.h | 298 ++++++++++++++++++++++----- arch/arm64/include/asm/nmi.h | 27 +++ arch/arm64/include/asm/sysreg.h | 2 + arch/arm64/include/uapi/asm/ptrace.h | 1 + arch/arm64/kernel/acpi.c | 10 +- arch/arm64/kernel/cpufeature.c | 58 +++++- arch/arm64/kernel/debug-monitors.c | 7 +- arch/arm64/kernel/entry-common.c | 96 +++++---- arch/arm64/kernel/entry.S | 2 - arch/arm64/kernel/hibernate.c | 6 +- arch/arm64/kernel/irq.c | 2 +- arch/arm64/kernel/machine_kexec.c | 2 +- arch/arm64/kernel/probes/kprobes.c | 4 +- arch/arm64/kernel/setup.c | 2 +- arch/arm64/kernel/smp.c | 6 +- arch/arm64/kernel/suspend.c | 6 +- arch/arm64/kvm/hyp/vgic-v3-sr.c | 6 +- arch/arm64/kvm/hyp/vhe/switch.c | 4 +- arch/arm64/mm/mmu.c | 6 +- arch/arm64/tools/cpucaps | 2 + drivers/irqchip/irq-gic-v3.c | 6 +- 23 files changed, 442 insertions(+), 134 deletions(-) create mode 100644 arch/arm64/include/asm/nmi.h -- 2.34.1