Received: by 2002:ab2:7041:0:b0:1f4:bcc8:f211 with SMTP id x1csp10827lql; Fri, 12 Apr 2024 01:49:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVAw3eYybf4fm/hC7IJHzPDm/BccklYy8MrKgxw5lAWVbnO2AVGOqLfIrrM1XzMb+HnR3Tx5dHAoPTHVJeZK0xShdJJFFP8lqXx9UBKUA== X-Google-Smtp-Source: AGHT+IESUa7xG/oGk1hguCUGdj5wzzAonAfmyga7zDlYU8W3b9De2c5Vmcpp/+6t2FOhPwqafF/s X-Received: by 2002:a17:902:d88f:b0:1e2:7d3b:353c with SMTP id b15-20020a170902d88f00b001e27d3b353cmr1712688plz.18.1712911750570; Fri, 12 Apr 2024 01:49:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712911750; cv=pass; d=google.com; s=arc-20160816; b=eK1GsmGx9jEZJCtj2/3oHdPBX9W86GxBA5vDJc7/B3QKRKD7wc3/pQh35YSaD6fv3q 3mwPjCh0lrHTB8JPRBAyl246pARxnVVFe7L/jeLfpICIsG1MYgzK7us21e9J7lFlSG6f RGK2pbslWQdNP0nXtZcxDV5t7CSIXGZBBJGTxocmGvqkBGrP4tAmPDdQsbMlHV+ABfE+ PEL9H+fHc/3cy6ONWDKgp88xz9m/8sSqYFTNdT/TgXedbtABclTPhXyh0NQu3z5NycpG H1RMa3tLS5BukU5Dl7KLGkxLwnU+L5SXymLf5EodQk4xE9t9YI0dT08pdKdnXDvlDqT2 RHNw== 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:references:in-reply-to:message-id :date:subject:cc:to:from; bh=V4QV6V9C0ozbubJs4ynDDe9zlKAlLKhHxs5w4VDXj3s=; fh=NDCPdPn2hiqHaiIRDYQAzsW9PK20CTia4nECGof6enU=; b=RlkZ1RhFSzVGPElX8DTTJ1uaiL/PfT/9f5xlrChgECzWMy2/rCg6BZZvJl2qZylh6i lGUvYQFmDIULnuY0KHLrkHw4v4rOd5XW/NqbikmI9LfeiRgdIg2B3GFnkvOEZHm3wuJz QQCJ2HkDdMEoFHp7iBfH766xHHil2TC4y/VHC1UWSlS/1Uw5C0HRhGDOM/ioL75+UDFA KA8duHCm5+psMBGinZeOnsKI0IEH0PNrSUKg3NN8eLaL0hK65o8+Kw0datOfBYFEaiNE j0A8W8UMDjWzS/A1WSEYfRKA/tDQ1TgiEFvH0qBjfrvV8bDny6gMd2VjARmvxJJ513m9 I7uw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-142272-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142272-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i17-20020a170902c95100b001e2624072dfsi2937664pla.616.2024.04.12.01.49.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 01:49:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142272-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-142272-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142272-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 42B69285EDD for ; Fri, 12 Apr 2024 08:48:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B54E55EE80; Fri, 12 Apr 2024 08:43:29 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF76F5D75F; Fri, 12 Apr 2024 08:43:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712911409; cv=none; b=I8NQ2kieeelhFz8hLE88VUSX+bK2c51a/XtGgd3SNG3pRsicT94vtKAiAqVn6buxogd1dmclspdYffQAiIF2/dSkSmcRmoozTSUiVE0UFpc3JlzY+VN9t/bmQZ/FDoN+LAii6n0+/aV0FTQesPOO1/dj5L6PgK+TiwZ7fMtUCFs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712911409; c=relaxed/simple; bh=Ox6SOG38reckBpTmGjgfYv4eHrY8DM+Y27fncDbNbcc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Myc8Qbg8Wh/2OkN99/1UIAXL660Z6PRmACTe+l87dOcbOmHl11OcrtSWjCm3SgGLO312LaHlFMt5k5YCK47UPOYc/roLykrnPyfOLxqAmfVTvlPpR2s8luDWFN2VzlJdlqqOt4wD3k3++fnH5Uj2bwcQfshmkR3Apdxp2aH6fng= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A33FC1596; Fri, 12 Apr 2024 01:43:56 -0700 (PDT) Received: from e112269-lin.cambridge.arm.com (e112269-lin.cambridge.arm.com [10.1.194.51]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 473FC3F6C4; Fri, 12 Apr 2024 01:43:25 -0700 (PDT) From: Steven Price To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Steven Price , Catalin Marinas , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , Suzuki K Poulose , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev, Ganapatrao Kulkarni Subject: [PATCH v2 04/43] arm64: RME: Handle Granule Protection Faults (GPFs) Date: Fri, 12 Apr 2024 09:42:30 +0100 Message-Id: <20240412084309.1733783-5-steven.price@arm.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240412084309.1733783-1-steven.price@arm.com> References: <20240412084056.1733704-1-steven.price@arm.com> <20240412084309.1733783-1-steven.price@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit If the host attempts to access granules that have been delegated for use in a realm these accesses will be caught and will trigger a Granule Protection Fault (GPF). A fault during a page walk signals a bug in the kernel and is handled by oopsing the kernel. A non-page walk fault could be caused by user space having access to a page which has been delegated to the kernel and will trigger a SIGBUS to allow debugging why user space is trying to access a delegated page. Signed-off-by: Steven Price --- arch/arm64/mm/fault.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 8251e2fea9c7..91da0f446dd9 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -765,6 +765,25 @@ static int do_tag_check_fault(unsigned long far, unsigned long esr, return 0; } +static int do_gpf_ptw(unsigned long far, unsigned long esr, struct pt_regs *regs) +{ + const struct fault_info *inf = esr_to_fault_info(esr); + + die_kernel_fault(inf->name, far, esr, regs); + return 0; +} + +static int do_gpf(unsigned long far, unsigned long esr, struct pt_regs *regs) +{ + const struct fault_info *inf = esr_to_fault_info(esr); + + if (!is_el1_instruction_abort(esr) && fixup_exception(regs)) + return 0; + + arm64_notify_die(inf->name, regs, inf->sig, inf->code, far, esr); + return 0; +} + static const struct fault_info fault_info[] = { { do_bad, SIGKILL, SI_KERNEL, "ttbr address size fault" }, { do_bad, SIGKILL, SI_KERNEL, "level 1 address size fault" }, @@ -802,11 +821,11 @@ static const struct fault_info fault_info[] = { { do_alignment_fault, SIGBUS, BUS_ADRALN, "alignment fault" }, { do_bad, SIGKILL, SI_KERNEL, "unknown 34" }, { do_bad, SIGKILL, SI_KERNEL, "unknown 35" }, - { do_bad, SIGKILL, SI_KERNEL, "unknown 36" }, - { do_bad, SIGKILL, SI_KERNEL, "unknown 37" }, - { do_bad, SIGKILL, SI_KERNEL, "unknown 38" }, - { do_bad, SIGKILL, SI_KERNEL, "unknown 39" }, - { do_bad, SIGKILL, SI_KERNEL, "unknown 40" }, + { do_gpf_ptw, SIGKILL, SI_KERNEL, "Granule Protection Fault at level 0" }, + { do_gpf_ptw, SIGKILL, SI_KERNEL, "Granule Protection Fault at level 1" }, + { do_gpf_ptw, SIGKILL, SI_KERNEL, "Granule Protection Fault at level 2" }, + { do_gpf_ptw, SIGKILL, SI_KERNEL, "Granule Protection Fault at level 3" }, + { do_gpf, SIGBUS, SI_KERNEL, "Granule Protection Fault not on table walk" }, { do_bad, SIGKILL, SI_KERNEL, "level -1 address size fault" }, { do_bad, SIGKILL, SI_KERNEL, "unknown 42" }, { do_translation_fault, SIGSEGV, SEGV_MAPERR, "level -1 translation fault" }, -- 2.34.1