From patchwork Wed Jan 3 16:00:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras X-Patchwork-Id: 13510223 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC9C7C3DA6E for ; Wed, 3 Jan 2024 16:01:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3940D6B02CE; Wed, 3 Jan 2024 11:01:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 344A36B02CF; Wed, 3 Jan 2024 11:01:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20D8F6B02D0; Wed, 3 Jan 2024 11:01:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 10D956B02CE for ; Wed, 3 Jan 2024 11:01:04 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D10E4A0917 for ; Wed, 3 Jan 2024 16:01:03 +0000 (UTC) X-FDA: 81638463606.04.F0A2960 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 65C6CC001A for ; Wed, 3 Jan 2024 16:01:00 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="OAve/LgS"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of leobras@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=leobras@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704297660; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=eW7Hp92xFvn0uEDHFJ5uhGV0bhy55HqDGviT7ReovF8=; b=RRDDLF11yHJp0dMjVEHRsG9G+TwlwtcuM+QdmfBEOEPOdLuXSrlNiV2aZgB9zAo5jJsG3f Mn3+jhzYjLxpxCSm0TTQuuFbDg4MoCLacWpGuDaS2o2CrQxGm16kGj+1fKVeiKw8E9EbVh rC2FGTL6fgZ7S48WLHgWGg2iRspvzCE= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="OAve/LgS"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of leobras@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=leobras@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704297660; a=rsa-sha256; cv=none; b=qk3nkjkNvNgMq5hsavRvC1Hy1lyiIsvRl6gmQROK5Tvy4d3UkUUcEW19Ii9elc8F0NXq1+ 9unrxvu46drbdx78IbIX7flvIXHRHP8oOobzcQLyM9Uao1ARGQNBrV+YtkfG5N3ungXIKf AHKNv3kh0+orI0XCa85MbQYXSS4Ptcc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704297659; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eW7Hp92xFvn0uEDHFJ5uhGV0bhy55HqDGviT7ReovF8=; b=OAve/LgSkYP+KgY5bCM2w1jaHbzsxPaIh/eyH0MkiNjvNec07RtVpLItmLODy5bOUOA3m6 ZOsAH6hrdL0JZWn6N2DAMEG57NQqPUwWGIASfSGzqymNBJEnrEvWtRSEMk6yPLqnEd840h tJfZ3JWaJvhJ0IGzd3gdvXRbbeaKRpQ= Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-633-9by2_ElXOkGNysRYoqE_pw-1; Wed, 03 Jan 2024 11:00:58 -0500 X-MC-Unique: 9by2_ElXOkGNysRYoqE_pw-1 Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-28ccb055d6eso477405a91.1 for ; Wed, 03 Jan 2024 08:00:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704297656; x=1704902456; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eW7Hp92xFvn0uEDHFJ5uhGV0bhy55HqDGviT7ReovF8=; b=UFFOHrsnJePR2nNqrEH44kGIebNDJqBmxpO/aVIFS9NKuXeNlR7RQBJOc5fOKqcWHF Hjv1qOY40CWiq4Y/Vp1d3kim8sAbf8D6yt73q/EG2pb4vIuCRy3DPmwejKBr9pxlC93D QviLH2ArvnOvxMUJLCfi2sbfcv3VEak4grPR+EGXEHhEL9tQ97wadWhabiEj+otoQKfy wrvjktM34VzP2NLPxy0eqdI5mJIUXWrMnKhho6n7PfvYlRBXzhJnzU62eK+Vyx1gChsS 3iAdfTKYGrJvzH8qODYE5BnxMnzIJC6GbGDEVhdE2kGOGHdgfcIi6dukSlPoVSHsJlg3 Wd5g== X-Gm-Message-State: AOJu0Yyy9TD/0eW5zXPzOh6V/PQwmic8XzHNl7u0Nu0xk5e1E3g8yxLy Wi4C9FZ7+thNQZDthLIhIGTzwStXvxlCj9Tw/QLd1l7TO02DXWjjo1ow6HanNMcyOAuj9Ehb/BL 7fmWcFn6L/viv3fUhgnc= X-Received: by 2002:a17:90a:c245:b0:28c:eeef:aaca with SMTP id d5-20020a17090ac24500b0028ceeefaacamr705438pjx.4.1704297656082; Wed, 03 Jan 2024 08:00:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IH1Qw9aIClua9ds5Nw8/POsd9KwpDhXoK1ctp78/8BijwUvH1rwsQL+Vt2C/sTQWWAMNvcTuQ== X-Received: by 2002:a17:90a:c245:b0:28c:eeef:aaca with SMTP id d5-20020a17090ac24500b0028ceeefaacamr705420pjx.4.1704297655711; Wed, 03 Jan 2024 08:00:55 -0800 (PST) Received: from localhost.localdomain ([2804:431:c7ec:911:6911:ca60:846:eb46]) by smtp.gmail.com with ESMTPSA id qc8-20020a17090b288800b0028b1fce7c01sm1922253pjb.37.2024.01.03.08.00.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 08:00:55 -0800 (PST) From: Leonardo Bras To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Eric Biederman , Kees Cook , Oleg Nesterov , Leonardo Bras , Guo Ren , Andy Chiu , Conor Dooley , Xiao Wang , Vincent Chen , Charlie Jenkins , Greg Ungerer , Andrew Morton , Kemeng Shi , Alexandre Ghiti , David Hildenbrand , "Matthew Wilcox (Oracle)" , Qinglin Pan , Greentime Hu , Baoquan He , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v1 1/5] riscv: Improve arch_get_mmap_end() macro Date: Wed, 3 Jan 2024 13:00:19 -0300 Message-ID: <20240103160024.70305-3-leobras@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240103160024.70305-2-leobras@redhat.com> References: <20240103160024.70305-2-leobras@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 65C6CC001A X-St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aGyA0g64Xhofr7p3LVDcGdeG2pqEiDJrPms2UuXDcb4b8lgUI08rkHwQyPzWmP2d5Ndrr2Dqjps2JglbJqTVNNEuncxdLsidbS6KCjED4HaMdVlsI4Rmm2ALUDRnYM2h89j+oet9+8L5k2UOffAvBNLtEPFVWIvToyNeU5z912DPK/gjHDCDGa1Wp2HHucpHaLdNmQsdyuNUtg0fBFkT4CLEofUhJ0vf9zzMs/J792DG3Ytwp8qcEnfHr6/h8iOTFsGC5z7BfwSdGGmFMkI5cTMbOKqiDZcKVqWe5ESTi8fqrO8xvFliD7q3Ne7vsoVJQtHfPFyezA/1CDmMAJzj7eIRH/6jR1d6qpfLY7lZMc4C+FNLAbw+28L0hCHdIKQvFKSc36h06G0NALtVxqXYprq+7ozXUiwQpylO84vPYk3ETg6UEuvc9d3FMcDPalDh/BYMFOfWUTa7Vk5AUBV2aDqamPswHQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This macro caused me some confusion, which took some reviewer's time to make it clear, so I propose adding a short comment in code to avoid confusion in the future. Also, added some improvements to the macro, such as removing the assumption of VA_USER_SV57 being the largest address space. Signed-off-by: Leonardo Bras Reviewed-by: Guo Ren --- arch/riscv/include/asm/processor.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/riscv/include/asm/processor.h b/arch/riscv/include/asm/processor.h index f19f861cda549..2278e2a8362af 100644 --- a/arch/riscv/include/asm/processor.h +++ b/arch/riscv/include/asm/processor.h @@ -18,15 +18,21 @@ #define DEFAULT_MAP_WINDOW (UL(1) << (MMAP_VA_BITS - 1)) #define STACK_TOP_MAX TASK_SIZE_64 +/* + * addr is a hint to the maximum userspace address that mmap should provide, so + * this macro needs to return the largest address space available so that + * mmap_end < addr, being mmap_end the top of that address space. + * See Documentation/arch/riscv/vm-layout.rst for more details. + */ #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())) \ 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)) \ + else if (((_addr) >= VA_USER_SV57) && (VA_BITS >= VA_BITS_SV57)) \ + mmap_end = VA_USER_SV57; \ + else if (((_addr) >= VA_USER_SV48) && (VA_BITS >= VA_BITS_SV48)) \ mmap_end = VA_USER_SV48; \ else \ mmap_end = VA_USER_SV39; \