Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp1304048lqb; Thu, 18 Apr 2024 06:19:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUt7iJUAKJF1u2uVGZUgmxgWs2AoQz/VJtqB3Iym2CcqGOUka2VqNliu/C4JnTz9w/uYb4nOVf1KY0c0SFye/D443+r06o59XA/p3p27w== X-Google-Smtp-Source: AGHT+IF/KKgI8aKLHhOpXYKeJmZMKLQpDn1TM6xcUP1emTub97gIu7fPUbBpEVMUjBPPrl5UvsFn X-Received: by 2002:a17:903:234e:b0:1e5:e664:9c12 with SMTP id c14-20020a170903234e00b001e5e6649c12mr3998554plh.0.1713446369251; Thu, 18 Apr 2024 06:19:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713446369; cv=pass; d=google.com; s=arc-20160816; b=rLsAZNHUHYVXNJXfbHWNHcZbQXaqBXPP7u1DDVKaotsZLZszb2cTO+vRrdP8knsfg9 U29yAcNW4wrcMmocPL6We+ebJXeNZrDaS3FuS6p+7VDmeVNrffbP/kG6/iB0QVmbkUbK fAsUHjP5bJ2by789hFUDCyApY1IXFFuHxFzv3Kl8narewJ9/WJIE9ml0z5ZcLsFtd468 DtqWbtOBEjYhP755IS9KVuOs2XJ67ACqKPanNDo7Ncgtcsw+bRg7R0NTapc0GESWQnd4 hfL+RbpUP/Q5mERk9TAB/yifV4h+28HQNAhPRL7hrzMcaXx31C4nDSC/cAq4LviUmXtr trSg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=vyFTMZOy8x0A0b1GwNKvJSlqBZ6wVxAWvpMCq1i5ve4=; fh=8akuJXVy1dlAnXUBkde1HaiIpT2OA048zzPHGl8mqpU=; b=lXShj+soWzT4IPbIpdQIavJfnnfazptyq0wkF6ES1p0P8U+V+G3TquclBzEf2494z1 ffsSkEt1W44q3kdXhSqsbr8wOXKtGiqe9jj9muWDy90lzkqRZc25X2fX0fbYmtfWiuuD 7zyG9UaQ1AbEkNskpHyWXHLtNjhTgRuxjTDE+5+vRAzlECvzQEIIimoWr6zvj+VLathy Rg0MVy9V4CWiQhQK8U3V6qDYdlTdFlPPPiC6TRrdzyZBYh/tDKvGFWLP2fYw8R8/c7Wu x3/zHAjKULVHWM9c40l/+01losY1ECmtYo+oSdhSST6uhKHL2wUitskK26nTycA/3klf lSrg==; 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-150146-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150146-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id w10-20020a1709027b8a00b001e2a5d98c4bsi1381147pll.396.2024.04.18.06.19.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 06:19:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150146-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; 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-150146-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150146-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 5B380B213A5 for ; Thu, 18 Apr 2024 13:17:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 122DD15F404; Thu, 18 Apr 2024 13:17:25 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 604E7EECF; Thu, 18 Apr 2024 13:17:21 +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=1713446244; cv=none; b=SFukHRGE72Qavj1AtjHhf+d6CuRfGmFQU1j64MUs2W6vZc8ZhrT8szd78Rix7J2c4d9hGEAFbNU22qIGpiDu9j8z5WkwZKB90svSUwCYikK09NXTaJPchUcB6cUQoqCSYCoGlej62VCJ7t34cP7BO4O/kIaUSXsL5da8dD3Y/gg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713446244; c=relaxed/simple; bh=JwQ6WKAgwkgGDjlwTjWbko4n+LA0bmKAxcEWpDK1XLo=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=C3Ul+Yi27QlK3zvrNijAVU+Jwc26HjMWxFpIQiwe1gcH9HT4X8YvPxKXKEJpPYRB/r0/llfj+lGpZ4GBwxS/zCYUaYgYLo6GxHyBYebWOTAm7kcUivsi/Kjsk7wB1o3OAP445/G3xxgudzzh+9RvoU6t+kMYH6jBts88Gxvx2F0= 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 97EC8339; Thu, 18 Apr 2024 06:17:48 -0700 (PDT) Received: from [10.1.35.34] (e122027.cambridge.arm.com [10.1.35.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DAEDF3F738; Thu, 18 Apr 2024 06:17:16 -0700 (PDT) Message-ID: Date: Thu, 18 Apr 2024 14:17:14 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 04/43] arm64: RME: Handle Granule Protection Faults (GPFs) To: Suzuki K Poulose , kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Catalin Marinas , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , 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 References: <20240412084056.1733704-1-steven.price@arm.com> <20240412084309.1733783-1-steven.price@arm.com> <20240412084309.1733783-5-steven.price@arm.com> From: Steven Price Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 16/04/2024 12:17, Suzuki K Poulose wrote: > On 12/04/2024 09:42, Steven Price wrote: >> 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"            }, > > Should this also be converted to do_gpf_ptw, "GPF at level -1", given we > support LPA2 ? Ah, yes I somehow missed that. Although something has gone majorly wrong if this triggers! ;) Steve >> -    { 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"    }, > > > Rest looks fine to me. > > Suzuki