From patchwork Tue Jan 30 19:04:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 194282 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1437173dyb; Tue, 30 Jan 2024 11:06:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IF4ssautMbIbZwVzlfi7MLkKUbp96ADWjIZe9IFjNKHrrj2+Khjfl9DuHQb2JQAN7vAHQD6 X-Received: by 2002:a17:906:f9c3:b0:a30:8d46:4cac with SMTP id lj3-20020a170906f9c300b00a308d464cacmr6689629ejb.67.1706641588762; Tue, 30 Jan 2024 11:06:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706641588; cv=pass; d=google.com; s=arc-20160816; b=Oxe8OzQdzsu+X+gxNVQkJ0mLI4uGB7S6y5r9UlAYDYePK0Q2awF3SAKdsPojtlccXg S+miQOGS+ptuLtfNmkcRN5zxINBAfmg8s74trhdt+PltX8x/Dqw/inbWKjuuQ4ng9ukm mVbNkC9yagd5JhOoobeJ4f2zJNnkaliDhAfWQB/CHb7Oor9a0QgBE+H3qHFzh/PtCxsg rAtU3VISzXwoWFR6/1IgswAQ8HV3F6koUsy22oCU71flabjKuRjJjKGqGu7pgV4iM9ss 5FEKWCSZlC59qVaGGOEm7zmEp0iL/90+1ygufUUqND/F0hx9507C5xY17UpNph8+Kycf JfGg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=yR39BQnx5CuM7HVAKBGyTLeOeO2w4fzgWq8LHVFIrGc=; fh=7OMQEv0P764ZztaL3To0S3R+SjKnWi0V++sb/jsafLY=; b=hDnVYeEDbMXz4ctjD+BdRbEyxAl8IY7UElIQneB1thisxvAUPsbJxHJS8tbKP1f6nK LpLc55bOkb15grnw7zV71JL55q9KWo6GsY3+cH1+kqETthMP92sP3U8cuAQsXgxed3GJ ZRxC103ZwjPjh46q/vvz4XrLEnIAMxixoHOXklQtMZPxTo8yUzjwU0sXYiSH+zmpKb3P +AldkEf6SRC9v/kQRgdOLaiKIMu29jxG/qLSJTcKueYIhh/4YK4WFsKypkOCGXWqssYw L97RrIAQR9Hog3/0LIYJw8tXWVfDetiQF3b/T2lAuN9WcTSmSvhVHbOTN5oEYWskk6Bd N3Jg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=pZU2Fhzv; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-45161-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45161-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id gy26-20020a170906f25a00b00a35a0184878si2459371ejb.195.2024.01.30.11.06.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 11:06:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45161-ouuuleilei=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; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=pZU2Fhzv; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-45161-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45161-ouuuleilei=gmail.com@vger.kernel.org" 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 2EB821F21130 for ; Tue, 30 Jan 2024 19:06:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 73D396A009; Tue, 30 Jan 2024 19:04:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="pZU2Fhzv" Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D61E7995F for ; Tue, 30 Jan 2024 19:04:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706641477; cv=none; b=kEGU0f0eOf889WG/MFxy/kDvaju5411izyuFyGPXp/wUsxh28x7TeF3Mu6/N7L9v9/iA32OjjYVxmAk5EVlLNOdWt800UX7wtaK/ZT+pLcZI0YcCa43QXS1jLngwY87FeiKBvCI+maSvPwiuLtlT9IEhA7/x4f3K1olaSCRQGVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706641477; c=relaxed/simple; bh=nYPj/fyg4PYV9oZH+Numr3TDNqlT2v60F+fZG4ppm6A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aPQmMYouzxbE4urTG4AyUB1jU2DZsPvuCaU5EfBznhdR6V3B7f+wXnZM3M1UUszucfU3HTlDGA6J/Q/VAhjNcbmEn3BHHxesuGeFLjFZL69LuzAFOaw8jrj9auLaBj/LafAHozdDNAkqn2Yy8o/JIWKDSvjKebFqR92VwlrtRWs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=pZU2Fhzv; arc=none smtp.client-ip=209.85.216.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-29026523507so3399063a91.0 for ; Tue, 30 Jan 2024 11:04:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1706641474; x=1707246274; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=yR39BQnx5CuM7HVAKBGyTLeOeO2w4fzgWq8LHVFIrGc=; b=pZU2FhzvR1dDjf8g9kUgB26AA0jhd7S+JnyIybHVEw91/vZuOwk/f6pbMeDUrFDMIT F/RBafodH/FI30TwRkZ6Qh/Td60oM1XOOBG0FSdyTxLs5UK9M1fCF3yArE3bIaoHC1GO zlOUTJQMYcctJB//I7FonxUJKPiEX++6MbRgl0Vqm2ixVw4nVU/J4LzE/yA7xOJVGCU0 8hO2IkGnkthpufymXQe7r/bS12DMSNwT8kNjdTDEo+VpJtLd9z65o0Ii9pAOjtXYs7kO 0e1W7uTCzBFijUDTvq0MplTfDayRz3opIeK+jjtIshOavcXwsfOD1Fyega+WwETBJGFg qOWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706641474; x=1707246274; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yR39BQnx5CuM7HVAKBGyTLeOeO2w4fzgWq8LHVFIrGc=; b=VK3mPM/pYBb1E2Rx18o0K4spiZC1nBekxBGNVJK5iwwcNQIyVSTa4GvtCG+q0M6HYx 1Imnas8DH9JO2S93v2TE5X07pc+yij4lRq+BEMHpLSd5wTQECxZO2s0tUtUdxUtj/90c jBELts9iJIgFnC7Stlvnjbtjk40D7OYvdNkWLS68+N8Wm8uXQ6YaTnF7NUtvVI6fB2V5 FB5DZ3TtG06eS6faaFlmS37zSdBYwxUeYcg2Qhj89RgVfn49h79KK7alk+fHNtyXvWu6 iAL1UL31+LEHiYbBNLK2to5bgzAYXOQwuUYxPOl0OqCl25qusgEjLXk+jj4oDD4+NcLl JyEg== X-Gm-Message-State: AOJu0YzeZ3rm27DmDVgdV936CQJUtoCahBgZu//2m8OuaEB+EwvVu23D cbFiWtTl5Ds4qhEvMtQ83pSSbWdLIEsqIuGX+UCel45FOL5oVkMG/WK0T4sijOs= X-Received: by 2002:a17:90b:1d82:b0:293:e466:e82b with SMTP id pf2-20020a17090b1d8200b00293e466e82bmr6560721pjb.38.1706641473865; Tue, 30 Jan 2024 11:04:33 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id f6-20020a17090aec8600b00295c3bb9318sm1196541pjy.54.2024.01.30.11.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 11:04:33 -0800 (PST) From: Charlie Jenkins Date: Tue, 30 Jan 2024 11:04:30 -0800 Subject: [PATCH v2 1/3] riscv: mm: Use hint address in mmap if available Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240130-use_mmap_hint_address-v2-1-f34ebfd33053@rivosinc.com> References: <20240130-use_mmap_hint_address-v2-0-f34ebfd33053@rivosinc.com> In-Reply-To: <20240130-use_mmap_hint_address-v2-0-f34ebfd33053@rivosinc.com> To: Alexandre Ghiti , Paul Walmsley , Palmer Dabbelt , Albert Ou , Shuah Khan , Jonathan Corbet , Yangyu Chen Cc: linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706641471; l=2717; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=nYPj/fyg4PYV9oZH+Numr3TDNqlT2v60F+fZG4ppm6A=; b=8TpBPUYlMpe99Wy4MtFO+G5FMsAU594qBMLjaPbbTQaF/l0GF2Rgz5PEarXQGUC7U59m+QmVJ rouYGXoseN8DFOk/KglyX6LbcysJhd8mJLV8BDu96je7w6S40qMm4Tt X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789543385081252373 X-GMAIL-MSGID: 1789543410914949124 On riscv it is guaranteed that the address returned by mmap is less than the hint address. Allow mmap to return an address all the way up to addr, if provided, rather than just up to the lower address space. This provides a performance benefit as well, allowing mmap to exit after checking that the address is in range rather than searching for a valid address. It is possible to provide an address that uses at most the same number of bits, however it is significantly more computationally expensive to provide that number rather than setting the max to be the hint address. There is the instruction clz/clzw in Zbb that returns the highest set bit which could be used to performantly implement this, but it would still be slower than the current implementation. At worst case, half of the address would not be able to be allocated when a hint address is provided. Signed-off-by: Charlie Jenkins --- arch/riscv/include/asm/processor.h | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index f19f861cda54..5d966ae81a58 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -22,14 +22,12 @@ ({ \ unsigned long mmap_end; \ typeof(addr) _addr = (addr); \ - if ((_addr) == 0 || (IS_ENABLED(CONFIG_COMPAT) && is_compat_task())) \ - mmap_end = STACK_TOP_MAX; \ - else if ((_addr) >= VA_USER_SV57) \ - mmap_end = STACK_TOP_MAX; \ - else if ((((_addr) >= VA_USER_SV48)) && (VA_BITS >= VA_BITS_SV48)) \ - mmap_end = VA_USER_SV48; \ + if ((_addr) == 0 || \ + (IS_ENABLED(CONFIG_COMPAT) && is_compat_task()) || \ + ((_addr + len) > BIT(VA_BITS - 1))) \ + mmap_end = STACK_TOP_MAX \ else \ - mmap_end = VA_USER_SV39; \ + mmap_end = (_addr + len); \ mmap_end; \ }) @@ -39,14 +37,12 @@ typeof(addr) _addr = (addr); \ typeof(base) _base = (base); \ unsigned long rnd_gap = DEFAULT_MAP_WINDOW - (_base); \ - if ((_addr) == 0 || (IS_ENABLED(CONFIG_COMPAT) && is_compat_task())) \ + if ((_addr) == 0 || \ + (IS_ENABLED(CONFIG_COMPAT) && is_compat_task()) || \ + ((_addr + len) > BIT(VA_BITS - 1))) \ mmap_base = (_base); \ - else if (((_addr) >= VA_USER_SV57) && (VA_BITS >= VA_BITS_SV57)) \ - mmap_base = VA_USER_SV57 - rnd_gap; \ - else if ((((_addr) >= VA_USER_SV48)) && (VA_BITS >= VA_BITS_SV48)) \ - mmap_base = VA_USER_SV48 - rnd_gap; \ else \ - mmap_base = VA_USER_SV39 - rnd_gap; \ + mmap_base = (_addr + len) - rnd_gap; \ mmap_base; \ }) From patchwork Tue Jan 30 19:04:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 194284 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1437286dyb; Tue, 30 Jan 2024 11:06:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IGv2lObjCulyRC2sZuI9Z7/MfoqzzP+uxHdTIh3LDKvXDSUylAUCzWNGHzKISQ3ti/y6KJd X-Received: by 2002:a2e:920e:0:b0:2d0:4c0b:b469 with SMTP id k14-20020a2e920e000000b002d04c0bb469mr4330669ljg.52.1706641601729; Tue, 30 Jan 2024 11:06:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706641601; cv=pass; d=google.com; s=arc-20160816; b=yBqFfW7ff2SwN2UGCDsLtEh2PLmxO5pYTmPP4a6+NtnA2g4TK5jDQpHH2E/hTuSefu BMH3PGUEoD0UQ2YWN7nGZChjVwymBOBfnrZWic44nGoaDwNdfJnG1zWlqAg2gOujrSl9 ujJ5cJS+0gLy7gh469FtapX5i6glqMTsVfelQoIPyCGP2FpTGYmSdq656/whaXQivzd5 Gnefef4uYeRiqAqN3mDY7LEGilQqQjvHdpPRLie8ob0XFZyXE/x3PKldb/3X+DLemd/1 YU9ozFrkkVQtDPezUqH+2rhoWqebrefOmgNNUpiB625pf+4DpmnFYA8Iw/Kttp2Qrfmm p0Lw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=f4k3XgG6Vs4V2eymg6847wUAtUHshLOeTHqeR5jZPT4=; fh=7OMQEv0P764ZztaL3To0S3R+SjKnWi0V++sb/jsafLY=; b=bmXHlFHCU6SRLARni3CAZDz8I6+cmG58Xzlpggvz1DC5y3ez8QbBO4pQeKIDPPP7jF DGDVDEO6dN9wzDF9OeOj42O8L9aWiZxfBENdpabguRNjz9qadftjCl6uD/R7s3sSo5rd UMS4Q6YajW1WmPUws2XfCxKbUFn/I+R3cfiNaJXeIrwkCFVeUqv2/KrFoDZ2caa6C3sC 7Lei4MTtSDbtMnH/Aa4Er/nnQ+0CT31/S6MzFjywRtuYXclils+TiPA3iOGY9CAEhmoY V6/RNB8z+x/Cs3Pba0HSdXEenP1BUjetToLcK7wJSrAmy/Jz3MW1INAERxqN2iTPPXM+ ApDA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=P6S4PoqF; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-45162-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45162-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id er11-20020a056402448b00b0055ec060fa0fsi3486421edb.19.2024.01.30.11.06.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 11:06:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45162-ouuuleilei=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; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=P6S4PoqF; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-45162-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45162-ouuuleilei=gmail.com@vger.kernel.org" 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 2591D1F21379 for ; Tue, 30 Jan 2024 19:06:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C9BEB7AE4D; Tue, 30 Jan 2024 19:04:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="P6S4PoqF" Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB8AB6997A for ; Tue, 30 Jan 2024 19:04:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706641477; cv=none; b=QHUJrl5LeFT+hheTckbEtJ1NkM/oP25I36vFEOASIPHdUzLQOYYSSkT7BL3zlsGckmo1o3Hjsz4e6joy+M4chB/RP1g8wOjoQVeFxz7K3vLkpwmJLTRCUKu8hh4x8x1XCnTYjmsl6opJvyBt3wLptjqkvuZvLDpdH0i2TL8yZiw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706641477; c=relaxed/simple; bh=FRDzzVwyS7nuVapUvX+XBqyYOrJdFna/LWspy9EPMlc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ddoEG4sZIQOiKmUB8Jz+Mgvgq30Hw3wZ+HFgTCmiCDFUtAR0Ig828pJMqvdpGtap5qxpU67PwlUwuvMD9/HRc3DU2rHeC18U3qHe8eiPvROmW+034ABU51u6aWBlEtQvZmFBxXNjunRJpzSY29vq6vk8+pWlnpb5i/K6JHyPG9A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=P6S4PoqF; arc=none smtp.client-ip=209.85.216.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-290b9f83037so90108a91.1 for ; Tue, 30 Jan 2024 11:04:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1706641475; x=1707246275; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=f4k3XgG6Vs4V2eymg6847wUAtUHshLOeTHqeR5jZPT4=; b=P6S4PoqFAW4DWIyBC02xOoR8PYEQ3oUSFwVEacf7w9HEBy8VmTDkHa0gsJfGpewsjz k2Gt8Rs0HI1IbTTybSRU3HpYI17esm0qyWzMu/fzR+dP1CqvfFzKsuxKxboNHIffy3LA cX3KYJnuTADR8OkgMc9kCohxlpdl4SRRJsbjWM4R3wgVY/EqZhlREip6q4i50BB6VUHb yv6NDUcL0HEt2Nw2tzu/6VqLOyPuSb/jpEO0gJTXf3ZlfrIg+PWF7T608+e0ZwaXPct9 SAilWlQi5LQ4Y9c4C+YkKB4QxqDZwtnxCSuFdoev9dcC3OwiGXkVhn0UTeIKx2ers2uM +ZJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706641475; x=1707246275; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f4k3XgG6Vs4V2eymg6847wUAtUHshLOeTHqeR5jZPT4=; b=dtN4vhCKjLaG4cb0cRdDc4moFrZKqPqw6YDmPx/Q4QOk8l32Z+rJkE7MnYXNv1ywNX xrBmqz6QjIB/9Af6cC6zNs+YKk03Ix7VlsU8xbUI2jk69ckHAxpqOOC7aqRVps2TDZWT cJjgwsj6KOM8HrfzjHAQBmmnyPyg9JskYeqiiJoan4Vvm1z4NJBcOWaILyh5v9KkKpgf 9akG9x3JOaWC6KVJLourriIjfYOBDIEKCycEVZsP/CYx6Hhe7M0VIBV9NQGVVEQXmPWO dAxaI2tT2wSo/ubwTm3drmXVF2wlECnnkQkgi9VXGJKi2nSZq1o64S/ux+X6icskhU6u 0rtA== X-Gm-Message-State: AOJu0Yw0IMxUW+/PvaaRj95FkXK+xIdZh1TMwQOD4m+cpkScvt1irwHB oo7+oXpy1i/jC4D29IJGWw+KrpDaRoxy+1E0m3OJQtXZl5atNp86NlS0Rc/eAPlY1LPRMiL1csk s X-Received: by 2002:a17:90b:38e:b0:295:4b25:212b with SMTP id ga14-20020a17090b038e00b002954b25212bmr2367613pjb.4.1706641475147; Tue, 30 Jan 2024 11:04:35 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id f6-20020a17090aec8600b00295c3bb9318sm1196541pjy.54.2024.01.30.11.04.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 11:04:34 -0800 (PST) From: Charlie Jenkins Date: Tue, 30 Jan 2024 11:04:31 -0800 Subject: [PATCH v2 2/3] selftests: riscv: Generalize mm selftests Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240130-use_mmap_hint_address-v2-2-f34ebfd33053@rivosinc.com> References: <20240130-use_mmap_hint_address-v2-0-f34ebfd33053@rivosinc.com> In-Reply-To: <20240130-use_mmap_hint_address-v2-0-f34ebfd33053@rivosinc.com> To: Alexandre Ghiti , Paul Walmsley , Palmer Dabbelt , Albert Ou , Shuah Khan , Jonathan Corbet , Yangyu Chen Cc: linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706641471; l=8041; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=FRDzzVwyS7nuVapUvX+XBqyYOrJdFna/LWspy9EPMlc=; b=rSHBvYDxfdS3K26d2oaN4+tX7NILBW5lAv4B0A2eQz8EBV0f0LtHqjJKt61QbdAbheOm3eOie DHnjVcEZiPTCMJdRG/c7TW+3+fDluHKlANMAtpDO0C6sTPtDfef+wRW X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789543424212181587 X-GMAIL-MSGID: 1789543424212181587 The behavior of mmap on riscv is defined to not provide an address that uses more bits than the hint address, if provided. Make the tests reflect that. Signed-off-by: Charlie Jenkins --- tools/testing/selftests/riscv/mm/mmap_bottomup.c | 20 +---- tools/testing/selftests/riscv/mm/mmap_default.c | 20 +---- tools/testing/selftests/riscv/mm/mmap_test.h | 93 +++++++++++++----------- 3 files changed, 53 insertions(+), 80 deletions(-) diff --git a/tools/testing/selftests/riscv/mm/mmap_bottomup.c b/tools/testing/selftests/riscv/mm/mmap_bottomup.c index 1757d19ca89b..bad8e854263d 100644 --- a/tools/testing/selftests/riscv/mm/mmap_bottomup.c +++ b/tools/testing/selftests/riscv/mm/mmap_bottomup.c @@ -8,27 +8,9 @@ TEST(infinite_rlimit) { // Only works on 64 bit #if __riscv_xlen == 64 - struct addresses mmap_addresses; - EXPECT_EQ(BOTTOM_UP, memory_layout()); - do_mmaps(&mmap_addresses); - - EXPECT_NE(MAP_FAILED, mmap_addresses.no_hint); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_37_addr); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_38_addr); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_46_addr); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_47_addr); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_55_addr); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_56_addr); - - EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.no_hint); - EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_37_addr); - EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_38_addr); - EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_46_addr); - EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.on_47_addr); - EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.on_55_addr); - EXPECT_GT(1UL << 56, (unsigned long)mmap_addresses.on_56_addr); + TEST_MMAPS; #endif } diff --git a/tools/testing/selftests/riscv/mm/mmap_default.c b/tools/testing/selftests/riscv/mm/mmap_default.c index c63c60b9397e..a3874778d795 100644 --- a/tools/testing/selftests/riscv/mm/mmap_default.c +++ b/tools/testing/selftests/riscv/mm/mmap_default.c @@ -8,27 +8,9 @@ TEST(default_rlimit) { // Only works on 64 bit #if __riscv_xlen == 64 - struct addresses mmap_addresses; - EXPECT_EQ(TOP_DOWN, memory_layout()); - do_mmaps(&mmap_addresses); - - EXPECT_NE(MAP_FAILED, mmap_addresses.no_hint); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_37_addr); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_38_addr); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_46_addr); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_47_addr); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_55_addr); - EXPECT_NE(MAP_FAILED, mmap_addresses.on_56_addr); - - EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.no_hint); - EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_37_addr); - EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_38_addr); - EXPECT_GT(1UL << 38, (unsigned long)mmap_addresses.on_46_addr); - EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.on_47_addr); - EXPECT_GT(1UL << 47, (unsigned long)mmap_addresses.on_55_addr); - EXPECT_GT(1UL << 56, (unsigned long)mmap_addresses.on_56_addr); + TEST_MMAPS; #endif } diff --git a/tools/testing/selftests/riscv/mm/mmap_test.h b/tools/testing/selftests/riscv/mm/mmap_test.h index 9b8434f62f57..93face2b3118 100644 --- a/tools/testing/selftests/riscv/mm/mmap_test.h +++ b/tools/testing/selftests/riscv/mm/mmap_test.h @@ -4,60 +4,69 @@ #include #include #include +#include +#include "../../kselftest_harness.h" #define TOP_DOWN 0 #define BOTTOM_UP 1 -struct addresses { - int *no_hint; - int *on_37_addr; - int *on_38_addr; - int *on_46_addr; - int *on_47_addr; - int *on_55_addr; - int *on_56_addr; +uint64_t random_addresses[] = { + 0x19764f0d73b3a9f0, 0x016049584cecef59, 0x3580bdd3562f4acd, + 0x1164219f20b17da0, 0x07d97fcb40ff2373, 0x76ec528921272ee7, + 0x4dd48c38a3de3f70, 0x2e11415055f6997d, 0x14b43334ac476c02, + 0x375a60795aff19f6, 0x47f3051725b8ee1a, 0x4e697cf240494a9f, + 0x456b59b5c2f9e9d1, 0x101724379d63cb96, 0x7fe9ad31619528c1, + 0x2f417247c495c2ea, 0x329a5a5b82943a5e, 0x06d7a9d6adcd3827, + 0x327b0b9ee37f62d5, 0x17c7b1851dfd9b76, 0x006ebb6456ec2cd9, + 0x00836cd14146a134, 0x00e5c4dcde7126db, 0x004c29feadf75753, + 0x00d8b20149ed930c, 0x00d71574c269387a, 0x0006ebe4a82acb7a, + 0x0016135df51f471b, 0x00758bdb55455160, 0x00d0bdd949b13b32, + 0x00ecea01e7c5f54b, 0x00e37b071b9948b1, 0x0011fdd00ff57ab3, + 0x00e407294b52f5ea, 0x00567748c200ed20, 0x000d073084651046, + 0x00ac896f4365463c, 0x00eb0d49a0b26216, 0x0066a2564a982a31, + 0x002e0d20237784ae, 0x0000554ff8a77a76, 0x00006ce07a54c012, + 0x000009570516d799, 0x00000954ca15b84d, 0x0000684f0d453379, + 0x00002ae5816302b5, 0x0000042403fb54bf, 0x00004bad7392bf30, + 0x00003e73bfa4b5e3, 0x00005442c29978e0, 0x00002803f11286b6, + 0x000073875d745fc6, 0x00007cede9cb8240, 0x000027df84cc6a4f, + 0x00006d7e0e74242a, 0x00004afd0b836e02, 0x000047d0e837cd82, + 0x00003b42405efeda, 0x00001531bafa4c95, 0x00007172cae34ac4, + 0x0000002732f06b2b, 0x00000012cbf8fd0b, 0x0000001fcc6af0e8, }; -static inline void do_mmaps(struct addresses *mmap_addresses) -{ - /* - * Place all of the hint addresses on the boundaries of mmap - * sv39, sv48, sv57 - * User addresses end at 1<<38, 1<<47, 1<<56 respectively - */ - void *on_37_bits = (void *)(1UL << 37); - void *on_38_bits = (void *)(1UL << 38); - void *on_46_bits = (void *)(1UL << 46); - void *on_47_bits = (void *)(1UL << 47); - void *on_55_bits = (void *)(1UL << 55); - void *on_56_bits = (void *)(1UL << 56); - int prot = PROT_READ | PROT_WRITE; - int flags = MAP_PRIVATE | MAP_ANONYMOUS; +#define PROT (PROT_READ | PROT_WRITE) +#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS) + +/* mmap must return a value that doesn't use more bits than the hint address. */ +static inline unsigned long get_max_value(unsigned long input) +{ + unsigned long max_bit = (1UL << (ffsl(input) - 1)); - mmap_addresses->no_hint = - mmap(NULL, 5 * sizeof(int), prot, flags, 0, 0); - mmap_addresses->on_37_addr = - mmap(on_37_bits, 5 * sizeof(int), prot, flags, 0, 0); - mmap_addresses->on_38_addr = - mmap(on_38_bits, 5 * sizeof(int), prot, flags, 0, 0); - mmap_addresses->on_46_addr = - mmap(on_46_bits, 5 * sizeof(int), prot, flags, 0, 0); - mmap_addresses->on_47_addr = - mmap(on_47_bits, 5 * sizeof(int), prot, flags, 0, 0); - mmap_addresses->on_55_addr = - mmap(on_55_bits, 5 * sizeof(int), prot, flags, 0, 0); - mmap_addresses->on_56_addr = - mmap(on_56_bits, 5 * sizeof(int), prot, flags, 0, 0); + return max_bit + (max_bit - 1); } +#define TEST_MMAPS \ + ({ \ + void *mmap_addr; \ + for (int i = 0; i < ARRAY_SIZE(random_addresses); i++) { \ + mmap_addr = mmap((void *)random_addresses[i], \ + 5 * sizeof(int), PROT, FLAGS, 0, 0); \ + EXPECT_NE(MAP_FAILED, mmap_addr); \ + EXPECT_GE((void *)get_max_value(random_addresses[i]), \ + mmap_addr); \ + mmap_addr = mmap((void *)random_addresses[i], \ + 5 * sizeof(int), PROT, FLAGS, 0, 0); \ + EXPECT_NE(MAP_FAILED, mmap_addr); \ + EXPECT_GE((void *)get_max_value(random_addresses[i]), \ + mmap_addr); \ + } \ + }) + static inline int memory_layout(void) { - int prot = PROT_READ | PROT_WRITE; - int flags = MAP_PRIVATE | MAP_ANONYMOUS; - - void *value1 = mmap(NULL, sizeof(int), prot, flags, 0, 0); - void *value2 = mmap(NULL, sizeof(int), prot, flags, 0, 0); + void *value1 = mmap(NULL, sizeof(int), PROT, FLAGS, 0, 0); + void *value2 = mmap(NULL, sizeof(int), PROT, FLAGS, 0, 0); return value2 > value1; } From patchwork Tue Jan 30 19:04:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 194283 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1437257dyb; Tue, 30 Jan 2024 11:06:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IEQI6c0ktSjaBphjABZxdWsL6u1OIUloLLsd087G7MuK45ryvj++vrCjuT1OM4S8fXNHlCs X-Received: by 2002:a9d:7482:0:b0:6e1:34d7:27b1 with SMTP id t2-20020a9d7482000000b006e134d727b1mr4566542otk.8.1706641598403; Tue, 30 Jan 2024 11:06:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706641598; cv=pass; d=google.com; s=arc-20160816; b=rT1u2jt4d//g4yUddt0NKslwdlxrjNjeCpwWuoNJJ5mvGIcEHcrwsVRo6mU//uaS1K yU8ZMYnPgJj56qbgfD+NkYMi1QDIRznI/v+5JXMBTssEYGH6Ffcx7PU+hns3i3iCqgcD soWEkIPCfOq7oSccf/u0psAoICrLLNTiQsstXBsjTMWu4briaT1fAV28MZaMa+ArPRlg 4thxGrXoUn+Hzb9TcWMoMgAxDFSKEJIBSUboMm04f4kOWZW5COlf3Dx4HevNb6soNeeZ HQwNNi6gQO+OViRHgweTAJNgFJs7wASaqL/nQvinWY9ygn7vW49+bkhKfFo45jjdG8ma Gc7w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=GGh1y1t0UhB5LcXiFRn0m1YgEny22RmTe/CDN12WiLQ=; fh=7OMQEv0P764ZztaL3To0S3R+SjKnWi0V++sb/jsafLY=; b=Ka7GcWWFnZpfikripfGTSdBtZGFc3GDbkqs+ahT6SOcbOZ9jkySOT2iCZA9SKj2XUp 7LcnyEiQB4F4pzE+Xcmj9geU+XH7omXEWGBzZzxf7RKCNo9DZUlL5AJEZTUfgqXCWYDX /t3AA/1087IlJ3uif1k2TC5BoqZ4VsS85y17lcVUh0NjTDt+AE9ZcXcfsBfh9Cuwl7Hk qqnEVzqrqDpnYKOLtKixLSdMqS8q/Iup8G+V/gukGPiI+x7Flud4XmDjmSj98jUDC6r8 lmolG9BlVflZWXRZUfjwc0gcUWXMKTx2wzcwvZTMgMGHhKeLwGrrqEp79fc7l2c0+HUg fi0A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=PLyqFGIv; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-45163-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45163-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g43-20020a05610215ab00b0046b1b13faecsi1487612vsv.558.2024.01.30.11.06.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 11:06:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45163-ouuuleilei=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; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=PLyqFGIv; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-45163-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45163-ouuuleilei=gmail.com@vger.kernel.org" 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 1ECBE1C228CE for ; Tue, 30 Jan 2024 19:06:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 915757AE47; Tue, 30 Jan 2024 19:04:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="PLyqFGIv" Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DCA6155300 for ; Tue, 30 Jan 2024 19:04:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706641478; cv=none; b=glAWh+E7SrC/7XzFKPQGWKjfv7VjPg3MKMU3MtSd0I1ZvVO1pPlXJfD3IgK+eVNnYIoiciDCu9eewEbSdDtblU/eG7yzqM2OiAUvIFzTwAWwFoGbFT/v/dDNe13pSo5+LGRdxy7TvYjThjxo2nPNLBkOJDJwTcFtynvRGImqDso= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706641478; c=relaxed/simple; bh=2lxtSNzBMdkYqwC90W41TvLPqjzE8CkjIf8iMq/P7L4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HQ8bo35+JhD/8UD0Ix74Mo8jutAS5aAuct/+MEZ8NrpQxjssRxg9lQZvDzmLo+B6I6DC6hPf0w0DulQWLLqkwBS03k5mgvvlUD1owgU3Az5HQgzGyu+AXMHdLtrvhGJdR3aEvlL46liEFVB00aJTiUMLiu9J+zsu2zx9GB1M6Vg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=PLyqFGIv; arc=none smtp.client-ip=209.85.216.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-29359a09b1bso2125656a91.2 for ; Tue, 30 Jan 2024 11:04:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1706641476; x=1707246276; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=GGh1y1t0UhB5LcXiFRn0m1YgEny22RmTe/CDN12WiLQ=; b=PLyqFGIvHAlPl4Yrl/jQ0Z16cIRm5QfhAS3D9eCjPLxVptJlGtb81Pga/JxrlKJWc9 URW/m2V9zr333LLc8pY+lFQYY07kNpXDSwtiT8DPavJYsECUCIe6RuJ0L4pJxB3BCPps xorLihVSD5zMahpo1hVb9ZhFyoqZDyexOJ65pkCASDGJLuUPM8dhMmm6JVOuyEf/k7mt 8SkQs5aPhgqq7F5JlTAfhdalcg1ZThijz05y3WYFL6rplywcH4bXGr0dC6Zrjxo9Olnw xMQWn5uAjVt5+lWdlMdPh8B8l+z/PG68ZmwswK7VF4qtIxzU/d8cqz7Y/2WiDT51NYvL dHcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706641476; x=1707246276; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GGh1y1t0UhB5LcXiFRn0m1YgEny22RmTe/CDN12WiLQ=; b=ZDVVlNUSPwT2TVRYMZVz1+ljlbxxDaQETTu/r1EnEKiMe0iwz5AtPL1pC2TKz3SdbF gBAuFvt8zyuNmid+JwRuJHPgUXC04XSXCaAOpazhRxxDvgelKmWKtwkzv7Wx3Nf4fG+q ANHc8Z3T862XVQzUt2zh5NHFMhY5I4KnePIHqHJiTOvahuXm3ECj9DHpC8+s3YYAZYYg CcICvCe51rnthr5DBdcmLM7R0lStsp/UzOGfb56tZyPWxKXwszlOitBiB2lb6dkEQ1ad auXYDKIUt+heJFGNt+vS5ZowGQRRV3bdBGho5Cz7EoDNuEwwEQq4U+WUK5UYu3Dxs4Hv JNrA== X-Gm-Message-State: AOJu0YxjAxfMEQvkKk6h0hnPoacpdcj2Ky6d1z3wGlkiWszVlb3GBWSg 4em5ZrUDyZX22A2sxxTPQK0mMNXYOydhjaeQvFoVe9u32jjegt/tziu59YFwb2BJ+GYieQ84Rlb 3 X-Received: by 2002:a17:90a:3dc3:b0:290:6878:db67 with SMTP id i61-20020a17090a3dc300b002906878db67mr5117026pjc.9.1706641476461; Tue, 30 Jan 2024 11:04:36 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id f6-20020a17090aec8600b00295c3bb9318sm1196541pjy.54.2024.01.30.11.04.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 11:04:35 -0800 (PST) From: Charlie Jenkins Date: Tue, 30 Jan 2024 11:04:32 -0800 Subject: [PATCH v2 3/3] docs: riscv: Define behavior of mmap Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240130-use_mmap_hint_address-v2-3-f34ebfd33053@rivosinc.com> References: <20240130-use_mmap_hint_address-v2-0-f34ebfd33053@rivosinc.com> In-Reply-To: <20240130-use_mmap_hint_address-v2-0-f34ebfd33053@rivosinc.com> To: Alexandre Ghiti , Paul Walmsley , Palmer Dabbelt , Albert Ou , Shuah Khan , Jonathan Corbet , Yangyu Chen Cc: linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1706641471; l=1848; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=2lxtSNzBMdkYqwC90W41TvLPqjzE8CkjIf8iMq/P7L4=; b=94N9u6Dy7xw5qCDQS+0vjMBDMNCSUN+BRd4o21tz6vC6lNovWVUFsgXKvGka/gJHpv0qpikoL uaW/c0J2VbkCXqP7svfJ7tYuinSlvY7wIe5t7X3qvAN/WmnM2V6JlUj X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789543420601643805 X-GMAIL-MSGID: 1789543420601643805 Define mmap on riscv to not provide an address that uses more bits than the hint address, if provided. Signed-off-by: Charlie Jenkins --- Documentation/arch/riscv/vm-layout.rst | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Documentation/arch/riscv/vm-layout.rst b/Documentation/arch/riscv/vm-layout.rst index 69ff6da1dbf8..e476b4386bd9 100644 --- a/Documentation/arch/riscv/vm-layout.rst +++ b/Documentation/arch/riscv/vm-layout.rst @@ -144,14 +144,8 @@ passing 0 into the hint address parameter of mmap. On CPUs with an address space smaller than sv48, the CPU maximum supported address space will be the default. Software can "opt-in" to receiving VAs from another VA space by providing -a hint address to mmap. A hint address passed to mmap will cause the largest -address space that fits entirely into the hint to be used, unless there is no -space left in the address space. If there is no space available in the requested -address space, an address in the next smallest available address space will be -returned. - -For example, in order to obtain 48-bit VA space, a hint address greater than -:code:`1 << 47` must be provided. Note that this is 47 due to sv48 userspace -ending at :code:`1 << 47` and the addresses beyond this are reserved for the -kernel. Similarly, to obtain 57-bit VA space addresses, a hint address greater -than or equal to :code:`1 << 56` must be provided. +a hint address to mmap. When a hint address is passed to mmap, the returned +address will never use more bits than the hint address. For example, if a hint +address of `1 << 40` is passed to mmap, a valid returned address will never use +bits 41 through 63. If no mappable addresses are available in that range, mmap +will return `MAP_FAILED`.