Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp1359349rdb; Fri, 19 Jan 2024 17:34:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IGWFOp8noxggxHTQPd2oIuu6vJI1KBXfbiNQYUxze3bv4+LI3FfeFzMJXtLKhUXpNfXkTY/ X-Received: by 2002:a25:bfc5:0:b0:dbd:bd00:809c with SMTP id q5-20020a25bfc5000000b00dbdbd00809cmr690025ybm.6.1705714485403; Fri, 19 Jan 2024 17:34:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705714485; cv=pass; d=google.com; s=arc-20160816; b=PqbJPM6gACr5+BN9oF3QvV00LidkthqDX5H6y3sdGesdwyIlfE2qDhonQlE26EhDQ3 ZJMJRt+tg/C0t1+jqAOJ/wLhduyQBqi/514SBKtcgqCKbHdlBL4hwwMHytJqYjxicUc2 tof4GavS3PSebiF+cyppFk1HcCHwkNl40ot0GZU64dwpFaUKzuXK20isUflJ0azYqgYS 524hHoOaob7HKrkAd1aqwaAHg2Vi/qMPQYieJnaZIVuoM8nomKokK4j91vyd/EUtShsE 1b6YamhROezA0t+BgVHMaG6FanlCMaZjtW1/ehF/zxirJzfUZR7/RNbzu98wPg5g1FmF 4hnA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=1ESr1s1LQuOTutaWHm69OFuVr1y+EY8ccPvGNNNRU7c=; fh=VqbsqI1lyr9AgqvMkTVmc2FLG1WO7lkQBQ6f/qmLHqU=; b=qLYQPE78aMDxZR+X2/3pLAWM+QaQsxGap3PQhk8bvFp/WzvvzgjiNebAHxTbj5AsGZ 4ZOxuTh8k1fHaZ32QCAygl+ONe6kvoRxWsnQ/R9KBOzH2KXQNTnVD1inKgvg0Z2LN75U tG8KVH1mQGgp6pDrkcDcLeWa5WFMUZ9IGG8H4v4l/Ua+SNdoAUjYiZkl4jEs2WO2uT/m Y0Tjq17R9mkh2jg4UPL1n5mQbuAPzLYUsD0jEB+xmOs0g0N/zy+6jIORvpnsyzR6f41N fZ+p1zlpFjTA5nITTfc4nx2L1cMmbqNJRxhi+c6xc5su+icG2C4uZ9etaFgiqcR1kRYv oyNw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=UCp7uzu2; 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-31668-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31668-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id il4-20020a17090b164400b0028e82dd05c8si4460540pjb.94.2024.01.19.17.34.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 17:34:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31668-linux.lists.archive=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=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=UCp7uzu2; 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-31668-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31668-linux.lists.archive=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 063BA2820B0 for ; Sat, 20 Jan 2024 01:34:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B9C58A52; Sat, 20 Jan 2024 01:34:37 +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="UCp7uzu2" Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 6A34F10EC for ; Sat, 20 Jan 2024 01:34:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705714476; cv=none; b=B0alLvirk060tjOjB7HZu25lZFq+SMAo5nKlZfuPd1nIHX+efuCc2SqPW1xKO7UIT3ZvZ3jSUKuDNsy5PlqjlHwQIuo+cy8H5V0s27LHzm8RWF3/sKf1cuGAIto2n7VpXXhyQuSbgcFqs/O2TvDYV5X1QIPyNu4nh+kdFUGqHH4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705714476; c=relaxed/simple; bh=26huEc5Mwf9rHtDTIB9WAm8Uc/lRlNkBs+RET7bxIJ0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FIoPp5oi/LZ4FykqKc27DseWqL7DTajR5ZD+L34Ym4F82xFt8zXhMEUr9VKZ+qJ3opWYoO2rszs2zygC9AFKKpgPKauoC5tx8PH1jo1G3j3gzRtTJVkKfdyk6Nr0+4KOTb7VNOkjzO21J0UrQL4OX7GyDUDH1hGY7FUR2je97Og= 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=UCp7uzu2; arc=none smtp.client-ip=209.85.210.170 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-pf1-f170.google.com with SMTP id d2e1a72fcca58-6dac225bf42so980546b3a.0 for ; Fri, 19 Jan 2024 17:34:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1705714474; x=1706319274; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=1ESr1s1LQuOTutaWHm69OFuVr1y+EY8ccPvGNNNRU7c=; b=UCp7uzu2SrCb+R9eaVctu2pPOqoDuEKPKwXpHR7XkhnHNkbRA3W+8E6RQb/J23CxWC RAL5FkWrxUT1EU6Djq4IiFvT/uWQg2s15zio4t8pyN7OSoPkW/oO5oSh0158ilgdUh6N dMd+oRMs9CqL8nlJGoi9JzSJCCTTaB7K9TztSsFvt0IkQVObSLRTkXrcLIB+YEbLuJ+t JZoKjWH1T3vPRP30Tt+he4KvTS4SnuoqpZoqH+8IuwN5izgYWB89ubnxoGXAw6NkdDiE mlVnBFYjOfqws2vOOy3XIE7c3faHIV7OIxavzWvRuROh9EPdL7BZO2vr1VM0d0XDYhyF ++jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705714474; x=1706319274; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=1ESr1s1LQuOTutaWHm69OFuVr1y+EY8ccPvGNNNRU7c=; b=wD1O5ap53ee6VRRMay2IeGuWVk5kAjH2aOehYwu4KcXqeKehP+IKOIy0okgucFwYg0 9aUWe4Jv0DIqg3QPL6GwupQ3E1sL/fra0s+Cu1n/yGhvPqDHj+2VUSXAqqnnYRjdCN7o uzbkhxMeufW47YYGdER1XgED47MHvnC9ITOp3H6zpKn1goRfPDV4D3LhvYGRF+3o+JDz GQauuYjva/sniybTP/cwD/S1CaxdzqmlM2AGWH3GnPCd9cgLb9rNnp9GedBXZJmjpO6t DG6jBHFS/8nimSSA8qsGZ0A+FO9jn9yJCU+TOvJ1SnbZFmwXF/YjVoCortbgopK3Gi35 cULQ== X-Gm-Message-State: AOJu0YxSNhdAOkori66K3PAA0VhV0L6FofFsrUkth6bcraVcHAtDAkIg CJ6V8XW7U/JuHcXOFNypGD4impsuzLJEyYzMmkONEiuZpj14j905Jbqv85/hcO0= X-Received: by 2002:a05:6a21:185:b0:19a:6830:2334 with SMTP id le5-20020a056a21018500b0019a68302334mr757399pzb.46.1705714474654; Fri, 19 Jan 2024 17:34:34 -0800 (PST) Received: from ghost ([12.44.203.122]) by smtp.gmail.com with ESMTPSA id r9-20020a170903410900b001d71c89fb32sm1961666pld.269.2024.01.19.17.34.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 17:34:34 -0800 (PST) Date: Fri, 19 Jan 2024 17:34:31 -0800 From: Charlie Jenkins To: Yangyu Chen Cc: alexghiti@rivosinc.com, anup@brainfault.org, aou@eecs.berkeley.edu, conor@kernel.org, jrtc27@jrtc27.com, konstantin@linuxfoundation.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, mick@ics.forth.gr, palmer@rivosinc.com, paul.walmsley@sifive.com, rdunlap@infradead.org Subject: Re: [PATCH v10 0/4] RISC-V: mm: Make SV48 the default address space Message-ID: References: <20230809232218.849726-1-charlie@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Sun, Jan 14, 2024 at 01:26:57AM +0800, Yangyu Chen wrote: > Hi, Charlie > > Although this patchset has been merged I still have some questions about > this patchset. Because it breaks regular mmap if address >= 38 bits on > sv48 / sv57 capable systems like qemu. For example, If a userspace program > wants to mmap an anonymous page to addr=(1<<45) on an sv48 capable system, > it will fail and kernel will mmaped to another sv39 address since it does Thank you for raising this concern. To make sure I am understanding correctly, you are passing a hint address of (1<<45) and expecting mmap to return 1<<45 and if it returns a different address you are describing mmap as failing? If you want an address that is in the sv48 space you can pass in an address that is greater than 1<<47. > not meet the requirement to use sv48 as you wrote: > > > else if ((((_addr) >= VA_USER_SV48)) && (VA_BITS >= VA_BITS_SV48)) \ > > mmap_end = VA_USER_SV48; \ > > else \ > > mmap_end = VA_USER_SV39; \ > > Then, How can a userspace program create a mmap with a hint if the address > >= (1<<38) after your patch without MAP_FIXED? The only way to do this is > to pass a hint >= (1<<47) on mmap syscall then kernel will return a random > address in sv48 address space but the hint address gets lost. I think this In order to force mmap to return the address provided you must use MAP_FIXED. Otherwise, the address is a "hint" and has no guarantees. The hint address on riscv is used to mean "don't give me an address that uses more bits than this". This behavior is not unique to riscv, arm64 and powerpc use a similar scheme. In arch/arm64/include/asm/processor.h there is the following code: #define arch_get_mmap_base(addr, base) ((addr > DEFAULT_MAP_WINDOW) ? \ base + TASK_SIZE - DEFAULT_MAP_WINDOW :\ base) arm64/powerpc are only concerned with a single boundary so the code is simpler. > violate the principle of mmap syscall as kernel should take the hint and > attempt to create the mapping there. Although the man page for mmap does say "on Linux, the kernel will pick a nearby page boundary" it is still a hint address so there is no strict requirement (and the precedent has already been set by arm64/powerpc). > > I don't think patching in this way is right. However, if we only revert > this patch, some programs relying on mmap to return address with effective > bits <= 48 will still be an issue and it might expand to other ISAs if > they implement larger virtual address space like RISC-V sv57. A better way > to solve this might be adding a MAP_48BIT flag to mmap like MAP_32BIT has > been introduced for decades. > > Thanks, > Yangyu Chen > - Charlie