From patchwork Fri Dec 22 08:27:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras Soares Passos X-Patchwork-Id: 182593 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp919460dyi; Fri, 22 Dec 2023 00:28:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFPLlbYQ+F9BUD/8Gft7pfs16LiQJqMq/ddLdNDSY/bbAm2IkhPi9D7voLQjmOTssLJHcIN X-Received: by 2002:a05:6a00:1d2a:b0:6ce:6407:2264 with SMTP id a42-20020a056a001d2a00b006ce64072264mr697940pfx.56.1703233713730; Fri, 22 Dec 2023 00:28:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703233713; cv=none; d=google.com; s=arc-20160816; b=sZj6/6OxB3WqJ0KHdUOgxoKV02Q6/vUKhZi4doaWAlKe4c2BT5VNN3xQhQBDz0LoyS nrXEcvljv/uCNR5VHX0akyILK30hsI3wDkmxRKpiCEsPaO+YTZ3QZdU87z1cKyAOuTBn qPmBXI9zFb9mIeAYTAvOpmLpiYSdUAgIBFYxpdUy1Lcg086UVxW5IqAI8FNvBMstKWoD Fu3D3Y8i7LhYCf34n8gyPv+aNXqUxbAjd3T3gCVbW89mNju6d+2KRK+qP10c9ryAWCfR JiH8CXAhMu4w7StfRCWIHafWw8c44v7j/9ReVFQ/rQdlitzLrF67U7KJLsJpPU3VnSV6 rHlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=aLqkaq/CNNYt4l8d0bCD03noyF1tDxxEcTb0gpcUAAQ=; fh=tnBykuOQKFbb50zBp6ndQbf4eFJlPku6JDJdHaJ3JrM=; b=AbVP7OqJVMgtIL5WUjwkvqJL8PbYwJIt40dqque0OmN386gGZ4XyyPIOSn8D0Tpnoj ZEnyn5RPuDbFgy00UOYSWrHHA5azhYNd5dr+1aF4xjP8UU/LcD88JgFoy873LTZ3KSrI w2vKaV01mmnIV/2cnnMJkKHo11dqJzoo1oGqgGlQ17aTgKJC0t4gAe+Ag2KziWx2IATE QsoS1thh/1bfJIUMRZebUydMchsRY8KRzwW0N4AbWrNZgU/koN17uyspMg91xyLdxO34 KG2AwWEluJ42Eh3PUD8da1nqbGmDulCOu+dzZf45sVvkjvrwmmk5ykTFoCam7fjgaO2f hTFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RiywPMpZ; spf=pass (google.com: domain of linux-kernel+bounces-9500-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9500-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id jo15-20020a056a00908f00b006d97bb4b213si1859119pfb.134.2023.12.22.00.28.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 00:28:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9500-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RiywPMpZ; spf=pass (google.com: domain of linux-kernel+bounces-9500-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9500-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 8314128537A for ; Fri, 22 Dec 2023 08:28:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 283291D698; Fri, 22 Dec 2023 08:27:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RiywPMpZ" X-Original-To: linux-kernel@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B590D1A5A3 for ; Fri, 22 Dec 2023 08:27:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703233657; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=aLqkaq/CNNYt4l8d0bCD03noyF1tDxxEcTb0gpcUAAQ=; b=RiywPMpZQARBrLVYkN3o8tCgIYE6U7xjOnY8McOr0cy17svyPRfzvy4+76OumWfOaXtLmS ajtPyWHMtnsapIuqWKn6LetMZBKSEGY31be9cCpx31q4tYqxaza2Hz57Nh8Hq+v+l/kiRg 1QRa92VLYSW9t7l8gvhpE7DA6vuza6E= Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-588-whQPAGq3N42jUlvY3BYlvA-1; Fri, 22 Dec 2023 03:27:35 -0500 X-MC-Unique: whQPAGq3N42jUlvY3BYlvA-1 Received: by mail-oi1-f197.google.com with SMTP id 5614622812f47-3bb87fc010fso743337b6e.0 for ; Fri, 22 Dec 2023 00:27:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703233655; x=1703838455; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=aLqkaq/CNNYt4l8d0bCD03noyF1tDxxEcTb0gpcUAAQ=; b=WpFMW2qr72O279wHxrr2v2OciFCjM0B0sD27WzNr6H1CjufYiA4+6icYvaCb35mxeZ qzNbusBX3QU5LXGM67hc8PWO9oSGBzv0nJVeepEiO4fFpbYsel0uGJmfcdnMDLW0yP5Z aRrQnatobKxOaUBXApu8PyyZJYBWqv41mqrgvo81BmaBdhKvcVr0oCVadR83JTiK6IEC 82hsueIOp65bYlYVTkYO5ToX47rNttHGGzj0uENJPGzqRWouJ+5Y/hcI99xDAFOSjPMU LxHOwzbdwfxxQmu40f78CmOLipVVgJB2w++HAz/GRTAzlnwCr0MLm9dXu4nFBJPRkRgE Ai8w== X-Gm-Message-State: AOJu0Yw9nRnXlz53TStanK7A7wlbLXR0sYtsaxqXBcohg6ohv904iW2n Lz24ZuGufRrlxykdH/0hZ0fzrjz0FMusOXuLZXzNStD9VaYrB1Yjd5DPJ7kIv8WDSdxyAkmbYQz zpXB5+JV+geeX1hUEpp7OVH0x3H5dv+cU X-Received: by 2002:a05:6808:d4f:b0:3b8:9025:57d7 with SMTP id w15-20020a0568080d4f00b003b8902557d7mr974247oik.3.1703233654973; Fri, 22 Dec 2023 00:27:34 -0800 (PST) X-Received: by 2002:a05:6808:d4f:b0:3b8:9025:57d7 with SMTP id w15-20020a0568080d4f00b003b8902557d7mr974235oik.3.1703233654771; Fri, 22 Dec 2023 00:27:34 -0800 (PST) Received: from localhost.localdomain ([2804:1b3:a802:7496:88a7:1b1a:a837:bebf]) by smtp.gmail.com with ESMTPSA id i10-20020a056a00004a00b006ce273562fasm2871150pfk.40.2023.12.22.00.27.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 00:27:34 -0800 (PST) From: Leonardo Bras To: Paul Walmsley , Palmer Dabbelt , Albert Ou , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Conor Dooley , Vincent Chen , Andy Chiu , Leonardo Bras , Charlie Jenkins , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , Guo Ren Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/1] riscv: Improve arch_get_mmap_end() macro Date: Fri, 22 Dec 2023 05:27:10 -0300 Message-ID: <20231222082711.454374-1-leobras@redhat.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785969994654594440 X-GMAIL-MSGID: 1785969994654594440 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; \