Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2529428rdb; Mon, 5 Feb 2024 09:12:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IHOUfbJxFoqV9aa9MZ7KEgRfJaWFpnEYYGSrjrOJfJUvcvsVz8DPiqsCigPwHt29F+iStoz X-Received: by 2002:aa7:d893:0:b0:55f:e543:b006 with SMTP id u19-20020aa7d893000000b0055fe543b006mr305933edq.13.1707153146724; Mon, 05 Feb 2024 09:12:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707153146; cv=pass; d=google.com; s=arc-20160816; b=MOxPCCy/jgVyzR77WqLz2lAbzjdvIF2gj34PurVOLQLZI0UAnB4wsgDxbphBjcUucC CYcje9Efa8nk01nwmamVw4l6MtGKq4AZIuTA+t6lL0SemS77L65EEIzhqmcpWnCFLL6N Ugru8+MGpmZY5mGE3voWE+7V04BvF10TTsx6ZcVULMyXcH9aGamO/gzWyQ5a1g5nf+gw tmNtaylTtW8rBRcV7JwHexk+yTlrTo8/5hhUGF4vJBHhtMzLOy7i3XVKgcY+WfwRsCyh SkqzxImWdZgrbB91nwrN3MRbFyFcrA6D9szvTnTE87TLqxmoWyHei21E/FvJ1V5JWKeg lTAQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=KRq0Cd2MeaCvdPEVRKXqgcR41z9udOEdSOsBWFzqpFM=; fh=+uU5/eJJkXkm2xh96LliPk4TDxoWX1XqwYYTnyCGKN8=; b=cwiBwUPDs1WrJnSm50OMk4ktaPwUfU84tOXUUSsVL2RF0v3xtPdzH4INpWVWf33L2a C6irj8iYOrzkTp+OW7Uzg5mj4gO22tmYy04IVzb/pxaJSSPKoejZAqzsM1ZVKt4vpk7c ZTS0PCYHqzkW0Z7I87zHGBx6Nre7iy4xc+/AJNzgZdOPUuc2RBZoRQtYRN8PZQLLPXYy sZzLN5z2g4FxJ/0Y/e2JLlBkQHOhOh6tG6Jzvd2ykCFrfhPbY6a5ZZRI/fDa0A2t07O1 tnJISiSbICxDD3qIS3MEVp2l6e34wUvdQJyT7+QqdHd/Dpmw7ISGGX0gb2WKL4cP3D35 qAaQ==; 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-53071-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53071-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=1; AJvYcCUDqLWQ5gPueW2wpfRzWHrnJOV0w6SOUGQmXQgUpm+UK8mCRv+OxoJVBTJsbuYL7Xxe+iPAaOuJfhEqLvJc8MlmoF4SGtOejdriBc76jg== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id c61-20020a509fc3000000b0055fa7f90391si89599edf.23.2024.02.05.09.12.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 09:12:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53071-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-53071-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53071-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 7B4231F22C5F for ; Mon, 5 Feb 2024 17:12:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 555353FE5F; Mon, 5 Feb 2024 17:12:06 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3AD13FE5B for ; Mon, 5 Feb 2024 17:12:03 +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=1707153125; cv=none; b=GzIjVLKQQgaT2h9NPlXlM317J3eVUOwZ3FyBs0BWuFNIyBlNmaMsmOpFF3HKUvut8CjwSkRj6z7WK+yRCrdVG91RdIcWUqWaaKxEM8OcW0sTcZdqqS41oP5+OeRf3sH1l9J0WqyZ5Yy8lLmo9RCDIKF1tYIPRD5l/WhSlL8EiHQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707153125; c=relaxed/simple; bh=bi2p0U5H3l/JGdhwUZBQJnQDpvA0TfMCPc6RnXD0HTo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=h3wDKrDD1Ea6/u2nBvNodWfRxKDGfxF8CpxKLQNgycwzzl+MH0rIgwKjoidCKuCt1DmQw7UerIvtV+CyfmwTRuu2GkLBvIt1vMmiBoF+9mSfsbDjZ+e6KvGEh79Yh1WS+k/kw75Z24N6IvD+EDfQtvseegVuvCokX0hAu+dxtMo= 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 3D5E01FB; Mon, 5 Feb 2024 09:12:45 -0800 (PST) Received: from e133380.arm.com (e133380.arm.com [10.1.197.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 812EB3F5A1; Mon, 5 Feb 2024 09:12:01 -0800 (PST) Date: Mon, 5 Feb 2024 17:11:59 +0000 From: Dave Martin To: Mark Brown Cc: Will Deacon , Catalin Marinas , Oleg Nesterov , Al Viro , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Doug Anderson Subject: Re: [PATCH] arm64/sve: Lower the maximum allocation for the SVE ptrace regset Message-ID: References: <20240203-arm64-sve-ptrace-regset-size-v1-1-2c3ba1386b9e@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240203-arm64-sve-ptrace-regset-size-v1-1-2c3ba1386b9e@kernel.org> On Sat, Feb 03, 2024 at 12:16:49PM +0000, Mark Brown wrote: > Doug Anderson observed that ChromeOS crashes are being reported which > include failing allocations of order 7 during core dumps due to ptrace > allocating storage for regsets: > > chrome: page allocation failure: order:7, > mode:0x40dc0(GFP_KERNEL|__GFP_COMP|__GFP_ZERO), > nodemask=(null),cpuset=urgent,mems_allowed=0 > ... > regset_get_alloc+0x1c/0x28 > elf_core_dump+0x3d8/0xd8c > do_coredump+0xeb8/0x1378 > > with further investigation showing that this is: > > [ 66.957385] DOUG: Allocating 279584 bytes > > which is the maximum size of the SVE regset. As Doug observes it is not > entirely surprising that such a large allocation of contiguous memory might > fail on a long running system. > > The SVE regset is currently sized to hold SVE registers with a VQ of > SVE_VQ_MAX which is 512, substantially more than the architectural maximum > of 16 which we might see even in a system emulating the limits of the > architecture. Since we don't expose the size we tell the regset core > externally let's define ARCH_SVE_VQ_MAX with the actual architectural > maximum and use that for the regset, we'll still overallocate most of the > time but much less so which will be helpful even if the core is fixed to > not require contiguous allocations. > > We could also teach the ptrace core about runtime discoverable regset sizes > but that would be a more invasive change and this is being observed in > practical systems. This is not hard at all: see 27e64b4be4b8 ("regset: Add support for dynamically sized regsets") But since this is precisely what was ripped out, I guess adding it back may be controversial (?) > > Reported-by: Doug Anderson > Signed-off-by: Mark Brown > --- > We should probably also use the actual architectural limit for the > bitmasks we use in the VL enumeration code, though that's both a little > bit more involved and less immediately a problem. Since these masks are 64 bytes each and rarely accessed, it seemed pointless complexity to make them resizeable... > --- > arch/arm64/include/asm/fpsimd.h | 10 +++++----- > arch/arm64/kernel/ptrace.c | 3 ++- > 2 files changed, 7 insertions(+), 6 deletions(-) > > diff --git a/arch/arm64/include/asm/fpsimd.h b/arch/arm64/include/asm/fpsimd.h > index 50e5f25d3024..cf5f31181bc8 100644 > --- a/arch/arm64/include/asm/fpsimd.h > +++ b/arch/arm64/include/asm/fpsimd.h > @@ -62,12 +62,12 @@ static inline void cpacr_restore(unsigned long cpacr) > * When we defined the maximum SVE vector length we defined the ABI so > * that the maximum vector length included all the reserved for future > * expansion bits in ZCR rather than those just currently defined by > - * the architecture. While SME follows a similar pattern the fact that > - * it includes a square matrix means that any allocations that attempt > - * to cover the maximum potential vector length (such as happen with > - * the regset used for ptrace) end up being extremely large. Define > - * the much lower actual limit for use in such situations. > + * the architecture. Using this length to allocate worst size buffers > + * results in excessively large allocations, and this effect is even > + * more pronounced for SME due to ZA. Define more suitable VLs for > + * these situations. > */ > +#define ARCH_SVE_VQ_MAX 16 > #define SME_VQ_MAX 16 Ack, though part of the reason for not doing this was to discourage people from allocating statically sized buffers in general. If the kernel is now juggling two #defines for the maximum vector size, this feels like it may seed bitrot... > > struct task_struct; > diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c > index dc6cf0e37194..e3bef38fc2e2 100644 > --- a/arch/arm64/kernel/ptrace.c > +++ b/arch/arm64/kernel/ptrace.c > @@ -1500,7 +1500,8 @@ static const struct user_regset aarch64_regsets[] = { > #ifdef CONFIG_ARM64_SVE > [REGSET_SVE] = { /* Scalable Vector Extension */ > .core_note_type = NT_ARM_SVE, > - .n = DIV_ROUND_UP(SVE_PT_SIZE(SVE_VQ_MAX, SVE_PT_REGS_SVE), > + .n = DIV_ROUND_UP(SVE_PT_SIZE(ARCH_SVE_VQ_MAX, > + SVE_PT_REGS_SVE), > SVE_VQ_BYTES), > .size = SVE_VQ_BYTES, > .align = SVE_VQ_BYTES, > > --- > base-commit: 41bccc98fb7931d63d03f326a746ac4d429c1dd3 > change-id: 20240202-arm64-sve-ptrace-regset-size-21b0928969e1 > > Best regards, > -- > Mark Brown This looks reasonable, but patching the .n fields doesn't look too bad either; I'll post a patch separately for comparison. [...] Cheers ---Dave