From patchwork Wed Jan 31 01:07:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 194420 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1600272dyb; Tue, 30 Jan 2024 17:08:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IH7PXG0VDaEPezd7LsUquLSN2q+MhkupX0pMR6LCzNVAp61v/uQTlys3Lrx8vGEtPqMK5Zw X-Received: by 2002:a17:902:7408:b0:1d5:8bf4:c79b with SMTP id g8-20020a170902740800b001d58bf4c79bmr304556pll.39.1706663292671; Tue, 30 Jan 2024 17:08:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706663292; cv=pass; d=google.com; s=arc-20160816; b=UtD0tSu0/CnGH8LtrfBfRaWk9/DAkfSzOuO2eHPDyu8mlpBVYVQprBeNEuJ/D1x8C0 yOIt/LJXgh64Q8UVQPmKWJXMFd3BYywjsBIN7ZqGHtMPuTsQwSLN9lcQniuCaOy8XI5D d7RjYV/SEw+oUyqonR61xIQ21HJvxtv+SusVn7lXC1GzLOG/b8D6yCNRelBFNrvXNWIz /7mA//mIgKxl7HwT/OwugvtkFF+lNq6XKF623goNme6VrGe02Z7GGQZUr37Vr9+sEY0G +o9qpWdXl8Efwtkd6yWB6Ojb/S42QUzCUDvFT31p0biZu78VFSUsL6+W8z3qi6P5Z3Z8 e7yA== 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=ISQ44kMse6Lkn35EK9G7PdGD5a4TdSkkmzrVy/QiW8Y=; fh=tx69x9izaew9pU58lAVqxvEXvLeJaCKei6PesWq3Qy4=; b=M+CTss3eTwXQxP6w+vDinApk3L/ilEy2rTHhuwALLoHBbCLHnl+bPUtO7bnWlL9UaN wOAz4pepfUVgQIpj77o2O0oZvmJJQyM+4MddR3NnUKqoEw6mwsWaHjcyMRDU3IWk/2A8 6rhl7oidzYuwutCysMuEL0ancj4lZuJSA47jUkbyY4g+XxWW88IQQ+N2AaNwRodXwxV3 Vh4tjtCUX6VXpvi0Ikv4MXoVOw2cRGil7kljpF68tOS3i1xcMth+vE5monvY9ZPa5pBw jHu3HETdoFICGAi9BiLaOJ6kXrAcWxqNF20LoQmtyo0dxESx+TfiGH1t7L3vl4WqcZ0l E6fw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="s/LAlH4K"; 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-45567-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45567-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXJJ+knt2P4FxpECkEmM2J8ePCntMd4+XBFqlXSSQ5wuOPPoKqH++fdWlC4nfP1gG1O9s+5Kw8i+n6AbfTiStkoRL/fUg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id c9-20020a170902d48900b001d924d8a773si668978plg.234.2024.01.30.17.08.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 17:08:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45567-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="s/LAlH4K"; 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-45567-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45567-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id B60B4B23CE1 for ; Wed, 31 Jan 2024 01:08:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2816C538A; Wed, 31 Jan 2024 01:07:11 +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="s/LAlH4K" Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 3A83E17BC8 for ; Wed, 31 Jan 2024 01:07:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706663227; cv=none; b=e3BhrUlAG30UEAu/VKyin8tSJdgHknDGv3xXh/CVf06iCE0tMXUBnIkbzT5oD4SrZmc28QZ1qYUSxBlT2tup58lQAhUSFtFb77zdkKGPMEYpsZ2dWeWWvcwA5EZUMDHEv0v1dNPH1c8ffJlAV8/7+tq5XUE+lnSVJsofV8RgzDw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706663227; c=relaxed/simple; bh=3agc++PZjt4adgBO71Cp8EyaaOma0q0miHLEwYoM4tM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gdl0I0GzFHYEsn3hhKaccl1HTPeWh4jx9F+9TeAYXmFeDT5+OySfUyIhUw44vrTBPMVlA/WuRV/OLg+Eryky7q70O1sDAnMx98ID7tPqRAPMCx8iNr2CjmV2zNl10iHJvT4DqTsii9w0hA8OQ1MRhraLZGvrUK6s8zOE1L1Y1gI= 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=s/LAlH4K; arc=none smtp.client-ip=209.85.214.182 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-pl1-f182.google.com with SMTP id d9443c01a7336-1d746ce7d13so38369875ad.0 for ; Tue, 30 Jan 2024 17:07:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1706663225; x=1707268025; 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=ISQ44kMse6Lkn35EK9G7PdGD5a4TdSkkmzrVy/QiW8Y=; b=s/LAlH4KYfzIG9i7MUYQHqhOQHjIGC7nOFBc25lm1enz8pGDTqsVDCnRzNRt3kIeAk tMPGA9fDaJtSKKM02P35uzSvWqSo8eucod8Wh8DwiYSN96d1AHpvdwhHO8expevUO1cE 77LN669pNyFgJQ125KHOwgiBrBED542MRB61Syu/TmueG5dXrTBFFsFFiUgVu7yKxu2o uQ4dnfW3iSIj8hVIby5E4RWh2xVgQXkDH5BsEKVBGwyyuSZk2uc5gj9/vTdDs48QIp/t yboel+Ok+xlxtUGonkxysrg2rP1gIvOX7THZwCu1ka3quDXvvLtOmiDHgfGuFgYZk4/W FGmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706663225; x=1707268025; 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=ISQ44kMse6Lkn35EK9G7PdGD5a4TdSkkmzrVy/QiW8Y=; b=n3OUcq0SY3rVQZ4waiuRjGX+T5wpjE27cBAaKW+SeMGZHE7GmWTIHYxwf7W012XhJT OelMTLco8/fPTMHeUEudEAnPYPw+79wGOy1KffO/XEE6bNuMEGbsh2f5ksimQ3iHUby7 IFx3XRkoYelVsdgoF+7Blz2mIkFFmOExNeqMv55JwD/QbZkEr5AzJ426q8F0FZ1Cugkh 4+T1spyKYy6+IHI6f7gkd++iS3MNBXxWDuD2UbhPdC9H8R6yBKLHSU8FRCVgJ1Np2aAe rdpBCjcmIX620gSh+PuzKe2CVFioyqBYDs49n+EX1niJwbZU4en5mTKWKuAaqFsN8l6Q ItUQ== X-Gm-Message-State: AOJu0YxRe/45JrNT0cvuBCzYOeSO+Lk8unO/VVUMbw6XEp8iM36GSU3S NCziRGjpAFpXrWZupFeCwm6Otqw9a9fiS1qpe5o2LHiBVcIE5PtvOvnHhY9aSLM= X-Received: by 2002:a17:902:d891:b0:1d5:36e8:9ac0 with SMTP id b17-20020a170902d89100b001d536e89ac0mr323253plz.50.1706663225597; Tue, 30 Jan 2024 17:07:05 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id r12-20020a170903410c00b001d8d3c276c4sm4970822pld.35.2024.01.30.17.07.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 17:07:05 -0800 (PST) From: Charlie Jenkins Date: Tue, 30 Jan 2024 17:07:00 -0800 Subject: [PATCH v3 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-v3-1-8a655cfa8bcb@rivosinc.com> References: <20240130-use_mmap_hint_address-v3-0-8a655cfa8bcb@rivosinc.com> In-Reply-To: <20240130-use_mmap_hint_address-v3-0-8a655cfa8bcb@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=1706663222; l=3095; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=3agc++PZjt4adgBO71Cp8EyaaOma0q0miHLEwYoM4tM=; b=AIKMSezNvXcphAUCcNCg21BBdaXUpcacXo54uEbl2OdGKMHckPpGf4N0pTfpvOAZ+GZExeI6t yXu3KlulVP2CvsGt2kGidzgw5nA924NJE/B8ZORdKYgHBzunKKkQbuk X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789566168918659755 X-GMAIL-MSGID: 1789566168918659755 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 | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index f19f861cda54..8ece7a8f0e18 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -14,22 +14,16 @@ #include -#ifdef CONFIG_64BIT -#define DEFAULT_MAP_WINDOW (UL(1) << (MMAP_VA_BITS - 1)) -#define STACK_TOP_MAX TASK_SIZE_64 - #define arch_get_mmap_end(addr, len, flags) \ ({ \ unsigned long mmap_end; \ typeof(addr) _addr = (addr); \ - 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_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; \ else \ - mmap_end = VA_USER_SV39; \ + mmap_end = (_addr + len); \ mmap_end; \ }) @@ -39,17 +33,18 @@ 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; \ }) +#ifdef CONFIG_64BIT +#define DEFAULT_MAP_WINDOW (UL(1) << (MMAP_VA_BITS - 1)) +#define STACK_TOP_MAX TASK_SIZE_64 #else #define DEFAULT_MAP_WINDOW TASK_SIZE #define STACK_TOP_MAX TASK_SIZE From patchwork Wed Jan 31 01:07:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 194421 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1600360dyb; Tue, 30 Jan 2024 17:08:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IERxMYfGW6XuOm32/Ib357KQDVoSa/61CbUpfuLApOg1V6dqx8J2Q2GBHqrBhyrOT0VJC/A X-Received: by 2002:a05:620a:21d5:b0:783:e000:8312 with SMTP id h21-20020a05620a21d500b00783e0008312mr49444qka.64.1706663305717; Tue, 30 Jan 2024 17:08:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706663305; cv=pass; d=google.com; s=arc-20160816; b=sVFNv4cXT22+GTUigmA/iCwY+pLYccZ69tPazjejZBxR+70mBPjUrHt4dq14iGHn72 rK9I3e7aJmuwh9I5d0MXobPbP5qbs5EvGS3XgN1lrmHfGEQIRb02GMBw2uwPTv/SDpx9 fKIpSXa5p+OOFFS+1FLA1wvUsAzgwEVlJAc3pOB4K6wxTpRs1mWrTfdbgaPeRtiF4xrg SodwVX4NTr/6NIJWg1LNfX00Xk/RBqTELSUqvcLcvqwMVyo0fN3OxEUFtIGAPcR2Nsnu 6DVEouYAFdx5tHMwNh5eBbsVZdDBP0Aq82ZQEnO36Q7U50l6ql1TXu40YqdholXZTWGv hVig== 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=13+B6LdTKTjt05jiAPVkvvRHYs5geOTb+j5SNg+p/UA=; fh=qK/sM1WqKxHpm0JJL0z5jRKbxuD0LPplk8kdg7/fkIk=; b=rdCtFJSYppJn1DvVJjRJLTPxNTUnyYwWlaD/zjCD1ybKxGhgnBG8hxRsN7JBmO11rH qSc5ccEUgxfCpz7dlHsv9nNS+N8W1TMCA0ZTBSOfXs/KZSgRYFKtmrW4KiyewEfIWF00 ZjK/vg1q/xHwRjyPxINqVvGZY5p4ZpO70oc+lE8kBFagFAwdNoPVPElyBoneB47m9nCQ cMse51cOuhACY0lmn4xYanbAYkjYWqKXy4nU0iD2UdqmRB5K+DlcYpwFpgZuh+uJH8Zs D6VK3ATOyJaATFUow6Z0X/YIP98n0O36fnR/3w3V/JhahlxgTSNdtd9XR3ktxLSzjcVW zsVA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=AetxdBnL; 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-45569-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45569-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXcdnbBjoRu3CnzM5rLqfavHAUXWJjQJvc7RCf7AeGGnib8TQKKavg5i5ZVOP6GY+KCiSxSHNKifgAuJYRVAD37++EW9A== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id j16-20020a05620a0a5000b00783fa16e05bsi5705882qka.786.2024.01.30.17.08.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 17:08:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45569-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=AetxdBnL; 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-45569-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45569-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 735DB1C21851 for ; Wed, 31 Jan 2024 01:08:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AFB0E79E5; Wed, 31 Jan 2024 01:07:13 +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="AetxdBnL" Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 B271F7EB for ; Wed, 31 Jan 2024 01:07:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706663229; cv=none; b=JQhcgAf/J5GI7OCVeveQBTIYtFIXy7ANLiablXM1PvuHAZwKJd0tw6PEAMdlU2VJOnEg7hqeQbMjOmtdIaodwfCbP+etw8i4E5s9BQOaGMKsPeLSMBeoFmacmb5OeXT+wpll0YnNSB5imDr6IwFOwePV6f7EW0VidlAjystlB+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706663229; c=relaxed/simple; bh=O8gOkv0E1+A6kkia3nAEslnYUt3oCjYhoTGBKmBpp+k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=b9uYTudVVjOLLtuGhGW9Rym+NgwhV/8uA5hC1OkcV3iCAuBikzqcOuPC7ejVxOwFUdjCJULw9jpRx006Z+MtCIEB962Gp3NhvMQR2jUSP35rUNwpjaXMCkti5euqOKNHypXrU0uIhy5AEpq0YfXLj3YU7cS/IROvEWcdk0c2giw= 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=AetxdBnL; arc=none smtp.client-ip=209.85.214.180 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-pl1-f180.google.com with SMTP id d9443c01a7336-1d8f3966982so14823575ad.2 for ; Tue, 30 Jan 2024 17:07:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1706663227; x=1707268027; 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=13+B6LdTKTjt05jiAPVkvvRHYs5geOTb+j5SNg+p/UA=; b=AetxdBnLzV9bO2p4XF8L60ky4H9oUu3Sd3H/1MmTpRc7e7LzdB5gZ3zzr8mGvdV528 91rCTTsBuO4BIHgtF+NkmEqKAFmmWEG58gzcGZ5ZdtaO4WtoGJ6c+mTE6wWPTB2AtgGt s7C9+a81bANmPvT8q2xK5BczVK3IVKGhyWUuvP7A+top7JE4/4AFouGjSwPjpHLJgt8k IxnK5SO7BSkyBLAa3xEh4bJUxZXDOt7dBfmOByFSbg01xrguhsEgC/CEun1mBGMV/23u Vdao0r1tE2NQeNL0pQGgMATz0X6KiH45kXeTesq20mtkjazR6GTOtGVr/l+fhAihnMwB l7+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706663227; x=1707268027; 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=13+B6LdTKTjt05jiAPVkvvRHYs5geOTb+j5SNg+p/UA=; b=n1GMOuPMRXP9KftX828EjeI1tlqlmL34FU2+LViKcIh4avao5Ln/jXs/ObqGSccFOG kGlKeZaUA0tXrJj1hJ7LU4XE7h7sopUlRjT0O6tNToirgQH3rBmX0kJAyUcfwjTACUys N7jM536if7OM9sP8K5c8chm4AVlIZODc3wLignplpfaMWdlWXLAAqwLyICH62pPgxEaE xztpfWnZtREYbwJyqthjeVrsShUUYjFQQ6RzA9fGTUss8qAPIO1h1nYPyCQ3m+iG/J1u hEBjQW6ulkinHHLQWTT+WdcN0TS1lM8AdngJXQ73YKp4N0E+Ddo3lNf1/AVPbFO8UdW0 aAeQ== X-Gm-Message-State: AOJu0Yz7e+4kFV1/PJSpKRcCVU7ZmYMrsE06spe6S5LeUhJLcBhGNDhx /jZ45479SpIPX92GACvS4JOYtlHaNpXOHwh98dSFwokwYgujlmiMdrSFFMOaVlM= X-Received: by 2002:a17:902:d4d2:b0:1d8:ebdf:182a with SMTP id o18-20020a170902d4d200b001d8ebdf182amr328261plg.44.1706663226858; Tue, 30 Jan 2024 17:07:06 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id r12-20020a170903410c00b001d8d3c276c4sm4970822pld.35.2024.01.30.17.07.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 17:07:06 -0800 (PST) From: Charlie Jenkins Date: Tue, 30 Jan 2024 17:07:01 -0800 Subject: [PATCH v3 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-v3-2-8a655cfa8bcb@rivosinc.com> References: <20240130-use_mmap_hint_address-v3-0-8a655cfa8bcb@rivosinc.com> In-Reply-To: <20240130-use_mmap_hint_address-v3-0-8a655cfa8bcb@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=1706663222; l=8909; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=O8gOkv0E1+A6kkia3nAEslnYUt3oCjYhoTGBKmBpp+k=; b=WDJobdBUYFFYtVz4fM3mc2BW26h1VmQ6/aM6YFyqcKnkZdKdsSDlfHr/m8269BVavOJ6niR8o kbLZ7INj1slC1TxiJM+zGX+bV9o4qK/6r+wzMsvzUXhyAPr1DF8kVVD X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789566182233208220 X-GMAIL-MSGID: 1789566182233208220 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 | 23 +---- tools/testing/selftests/riscv/mm/mmap_default.c | 23 +---- tools/testing/selftests/riscv/mm/mmap_test.h | 107 ++++++++++++++--------- 3 files changed, 67 insertions(+), 86 deletions(-) diff --git a/tools/testing/selftests/riscv/mm/mmap_bottomup.c b/tools/testing/selftests/riscv/mm/mmap_bottomup.c index 1757d19ca89b..7f7d3eb8b9c9 100644 --- a/tools/testing/selftests/riscv/mm/mmap_bottomup.c +++ b/tools/testing/selftests/riscv/mm/mmap_bottomup.c @@ -6,30 +6,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); -#endif + TEST_MMAPS; } TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/riscv/mm/mmap_default.c b/tools/testing/selftests/riscv/mm/mmap_default.c index c63c60b9397e..2ba3ec990006 100644 --- a/tools/testing/selftests/riscv/mm/mmap_default.c +++ b/tools/testing/selftests/riscv/mm/mmap_default.c @@ -6,30 +6,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); -#endif + TEST_MMAPS; } TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/riscv/mm/mmap_test.h b/tools/testing/selftests/riscv/mm/mmap_test.h index 9b8434f62f57..36e78d991d5e 100644 --- a/tools/testing/selftests/riscv/mm/mmap_test.h +++ b/tools/testing/selftests/riscv/mm/mmap_test.h @@ -4,60 +4,83 @@ #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; +#if __riscv_xlen == 64 +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, }; +#else +uint32_t random_addresses[] = { + 0x8dc302e0, 0x929ab1e0, 0xb47683ba, 0xea519c73, 0xa19f1c90, 0xc49ba213, + 0x8f57c625, 0xadfe5137, 0x874d4d95, 0xaa20f09d, 0xcf21ebfc, 0xda7737f1, + 0xcedf392a, 0x83026c14, 0xccedca52, 0xc6ccf826, 0xe0cd9415, 0x997472ca, + 0xa21a44c1, 0xe82196f5, 0xa23fd66b, 0xc28d5590, 0xd009cdce, 0xcf0be646, + 0x8fc8c7ff, 0xe2a85984, 0xa3d3236b, 0x89a0619d, 0xc03db924, 0xb5d4cc1b, + 0xb96ee04c, 0xd191da48, 0xb432a000, 0xaa2bebbc, 0xa2fcb289, 0xb0cca89b, + 0xb0c18d6a, 0x88f58deb, 0xa4d42d1c, 0xe4d74e86, 0x99902b09, 0x8f786d31, + 0xbec5e381, 0x9a727e65, 0xa9a65040, 0xa880d789, 0x8f1b335e, 0xfc821c1e, + 0x97e34be4, 0xbbef84ed, 0xf447d197, 0xfd7ceee2, 0xe632348d, 0xee4590f4, + 0x958992a5, 0xd57e05d6, 0xfd240970, 0xc5b0dcff, 0xd96da2c2, 0xa7ae041d, +}; +#endif -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); +#define PROT (PROT_READ | PROT_WRITE) +#define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS) - int prot = PROT_READ | PROT_WRITE; - int 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 << (((sizeof(unsigned long) * 8) - 1 - + __builtin_clzl(input)))); - 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 Wed Jan 31 01:07:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charlie Jenkins X-Patchwork-Id: 194422 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1600488dyb; Tue, 30 Jan 2024 17:08:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IENAYtrSDFBbX7isNqNNiu7OxZyS4jKuDdcnZ2gApfHbWD690vYLUfRs7vYYdeJeC4yPSpk X-Received: by 2002:a05:6830:3113:b0:6dd:efd1:763a with SMTP id b19-20020a056830311300b006ddefd1763amr73326ots.31.1706663323893; Tue, 30 Jan 2024 17:08:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706663323; cv=pass; d=google.com; s=arc-20160816; b=JFMmhoyQEHoYDx0ir3L7HPX2PJFAX7iXGnQ+ezgsokz+8snsZBMW+/jKRujT+YvWwZ gWL+UhA5i0eAEsVQWus9yTr10Xg7l+Wn77C+/PreF+dokrn54xb20ge0/G1QC/cXi/GI NdfIPSrk+OW+QDKVB6DI+5aDSXYOCSz5FCFH0cXA060pAsQLJIU9i8OgmiNhWd3MHg07 6SjNHpbo+xUxjDxTpy62T6cE9cN1y7s7UmEF1Z8/Mc3Ze7nPUG4FIUm8OLcq+aTm22zF TfQDOpNdVGdYtvLb0TYmKdz5qFY+tbkrZjB0bjueN+Q6ytuHcOp1zm37wIjIwrVkO7TW hqrg== 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=O3hZTfgLTiU+PpJJSGgH0qe9xyFlcRrYYGwCFWooQQM=; b=lzN+JfcO1VSlKHm/nb+sesTkmHCqhUqE383GCvd90YWVRYzFxAhjRsnJu4jL0Y0oBT xPu8Vr098/Dl8Z4mESteNX5wS4CJe/FxJtAZwMmK7KScAq5PwgcfnSK4+g47Oi4ZZ0zl YdcPc3QUWT/Rq6q+HB7ga2j7KM7vDv1ebVD8pClBRlP0hE2GfhaZBoDFLzt6Rp0nJxdD 5XnzDET1zMOUrAgvwQXVzkNobQT97njrRf669h1A8GUPY5CLTSoRhYvjkTCS0BR3qFQC 7XAdPFbScoiVoH7ABWv6TGw2et4VIURwUnS8KbmxVqX+Hw8krGzxWFS7xZ1x5P5fYgaq eo2Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=Yu4dJrGi; 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-45570-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45570-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWW6SgXCB1FmRzjvZf6MUJHHttMEgFeNyvR1g5FrjAQ2M9wj8s4KAsVyPX+VsL1P4CE6SoJbFYmi3t5Dj4GtemCgeUwAg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id k9-20020a63ba09000000b005cee179d5c4si8271485pgf.230.2024.01.30.17.08.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 17:08:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45570-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=Yu4dJrGi; 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-45570-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45570-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 001CAB24961 for ; Wed, 31 Jan 2024 01:08:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 643D6746B; Wed, 31 Jan 2024 01:07:13 +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="Yu4dJrGi" Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 E09F0185E for ; Wed, 31 Jan 2024 01:07:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706663230; cv=none; b=tDyne3nrH4u2iKIEohmK8+JPF88FfdJelL7HTa2eNcuSs3SUTg1bWtLPra2TPMC5Es2skjFiU6E/sCrxVJH0klPW+xG51jo1jJEXhNqCpa5cnNMMbu6GxlKcJ5PR/zCu6WpSwP8jP6XVfgdmY5TLI+QaTkRWhLlzC5X+xL92sS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706663230; c=relaxed/simple; bh=2lxtSNzBMdkYqwC90W41TvLPqjzE8CkjIf8iMq/P7L4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=U2224qoxsb8OVoG5dk9xFQTg783CsxhAjZJqB8MS82MToJAvoHbLyQ87ypaAzU1JrPYnxgik0uvL8myPbse2DUAmwsu1rD62tnQ9dd/BGVEDp9U03PQWe9PmgFsy56MIlj2wPk6bqrAKb9XQics7KaIf1pRzI/eXWp/YIYnqT0E= 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=Yu4dJrGi; arc=none smtp.client-ip=209.85.214.173 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-pl1-f173.google.com with SMTP id d9443c01a7336-1d746ce7d13so38370105ad.0 for ; Tue, 30 Jan 2024 17:07:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1706663228; x=1707268028; 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=Yu4dJrGi0IiDCFrpiqOLpDobeO92AFXkezCwPWsw/oaztxOemXJY57rq0+tk6HeDWn SMvK/q+uW8H416VONvYwknTIiUxb0L5Qo9OiGr8lO9mbrg6SjjZI11XDWqgoqLBPZOJk Y0j/tlIPvwlzRjCUi7biS6r2pECwzg3YEeYZelC1RW6rG0p87fpYpfd8qKKcccHKl/7P CvBiJ2CdsTudiTl3Z4M+QRRtB+EIXCAzmX8shU8OEka5yt3oTfpBC6KZj5ZWUyfshFlu ppMexHdpGFXYccRrCFTH5kfjt9sE2sX7hgORhXC8DyRjnI2tc3dfAaf/OH1wx6q6kRxG NvQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706663228; x=1707268028; 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=bX1q1FHnKuL/PDWWT/KHya4ovuFNaOqlXvwpx3aSmRrU0yk8tjX/jUCoFK7w9AeUdR i36EOpDymS/T/BQp85sfWow7diuVA55o8zICenUQaKBHrYbEoQO0XP6gUW/joLphCtwR qR0QfPbZ2uuEkViytSoNb8tafMN/YsPs1Kb82J6ail1D3O9JwhmQzLxvWIfBzXNo0iCx 1o6aeOEsksxPKp2c5LbXfpsRfdgyFTqmsd+QtfZcnev4aNwENufOC+raX3eySrghd5mf /GghnmCapKaZcquIsvBtUNKv0xbmPBSTPdIHql/kKUZVXtKLzyH5Pkeplv00UWUFOfIK PnSQ== X-Gm-Message-State: AOJu0YxOucO1JehRDN5BPeNBB0YaCL0HVj4DWekW1NZRDhTDPrHih/Gg 5zx8nOKHIjtqrHEAlVEoiWBCMScO8Ox26oJxjbRfrtNNrafafzT/q5cial+YFco= X-Received: by 2002:a17:902:ed94:b0:1d7:310e:1e0d with SMTP id e20-20020a170902ed9400b001d7310e1e0dmr263865plj.32.1706663228198; Tue, 30 Jan 2024 17:07:08 -0800 (PST) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id r12-20020a170903410c00b001d8d3c276c4sm4970822pld.35.2024.01.30.17.07.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 17:07:07 -0800 (PST) From: Charlie Jenkins Date: Tue, 30 Jan 2024 17:07:02 -0800 Subject: [PATCH v3 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-v3-3-8a655cfa8bcb@rivosinc.com> References: <20240130-use_mmap_hint_address-v3-0-8a655cfa8bcb@rivosinc.com> In-Reply-To: <20240130-use_mmap_hint_address-v3-0-8a655cfa8bcb@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=1706663222; l=1848; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=2lxtSNzBMdkYqwC90W41TvLPqjzE8CkjIf8iMq/P7L4=; b=VULcNJMPaGSSibunnHmdY8O6pSGdUfVoHdHqVkSZ/6IDh4hPdQyOg/2Va726eHw2pMLSxc0cG 87Fixe/YDGPCXhl08WlTq3vxGBa82+KW2s0J79eiJ6OVp8GW8Fgr/ii X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789566201516857277 X-GMAIL-MSGID: 1789566201516857277 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`.