From patchwork Sun Jan 14 19:55:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangyu Chen X-Patchwork-Id: 19015 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp1348075dyc; Sun, 14 Jan 2024 11:57:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IHzNmNyoTf8deC9XWYNvDybKivibdMWbgQlS692tj8Tl8GGlSPuPRaue2ue42fiW67rnk1o X-Received: by 2002:a05:6870:7ec4:b0:205:e4db:b5e2 with SMTP id wz4-20020a0568707ec400b00205e4dbb5e2mr6752459oab.68.1705262225107; Sun, 14 Jan 2024 11:57:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705262225; cv=none; d=google.com; s=arc-20160816; b=z/PO+HyjzcIF5Kne2E8xl1Cpknbi8iWoe0CZF1Y5xKuoe2YC1k658IEsRWHD2g6+WG HheANSONR6ciHDimk1C/MRxmjxCxntW2W22nk873ETWf/58gtObcaWuNRxEjbA5Rp9A+ OWh/Lzth+EC85PDxcn52bl19SLCmL3IMc0svMpJeM6cFhyQZCMNodFxKoZuykm5siB+s BE0rPlur1/RTeCTpVZFiwHMzBM6fXUdPVfIucsReDXqwXED2w57GZ70tDcPvfBLfiRg/ ZO0U9kiiDbMFtcypYzGYxqThPw/pakSahjiZyV5PDlm8rKy7lZy/HFsERqN7/voDG+we nTWg== 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:date:subject:cc:to:from :message-id:dkim-signature; bh=p9Bu5tHe0FzPhQq4mnG4EqMw8nkniS9fHhWhaNF5cVw=; fh=kODHYoeYq4h2jujSH/fCKtLduBcYOJagZ8PpgB8jnfY=; b=sRXVlM5yevoZl2PFzeoRuSSGMWzTUceS2akZP8vl19f+zmNe7ejrMRZjr+iZhU6I5T +inPXhVosjWOhoQGy7b94Y2gpSdFbYGrvWGY+tLVuhdNlYrHdWtc16b9VidP4kCEF9nh QxUe5V0Of7kAhEo7x8bdupm1jzu2NgaKJJSwk5ZeoxN3FfPM72PXjB9PpbOO6Dg95o4H lQcGvLxbqPyRyRrQG/8fXZAVr9TvDh+Bpi/WoxV4ZIIdUzO8LSbs9Pf7WU7+Fuyr1IIE ySzOGPJ7YaleN+qnHEhh/JwCLlAn/rxwG8wHg2aH1H5xuB1ex+27I74jCRvzZ6DVKKbw OP7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@qq.com header.s=s201512 header.b=rF+dbXRI; spf=pass (google.com: domain of linux-kernel+bounces-25533-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25533-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id gp14-20020a17090adf0e00b0028d158b5885si7703245pjb.33.2024.01.14.11.57.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jan 2024 11:57:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25533-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@qq.com header.s=s201512 header.b=rF+dbXRI; spf=pass (google.com: domain of linux-kernel+bounces-25533-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25533-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 D014DB21228 for ; Sun, 14 Jan 2024 19:56:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0284A154BA; Sun, 14 Jan 2024 19:56:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=qq.com header.i=@qq.com header.b="rF+dbXRI" Received: from out203-205-221-233.mail.qq.com (out203-205-221-233.mail.qq.com [203.205.221.233]) (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 68A5210A32 for ; Sun, 14 Jan 2024 19:56:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=cyyself.name Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=cyyself.name DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1705262185; bh=p9Bu5tHe0FzPhQq4mnG4EqMw8nkniS9fHhWhaNF5cVw=; h=From:To:Cc:Subject:Date; b=rF+dbXRILjAuVUJfUfbLlOWfhKqA1O79/iKLGW1QA9Rl1d6p4k4dsNd6OvhgcSGLl gSr6tC+MJzKRQqJ0WbLGANm4vh1piFJE57mDZQMEv01BACleBK9MRI5C6RgFQjZ8nP Uel8mEsVxYf0txP3iCHg+r6ap/mbVXfVFAp6r95Q= Received: from cyy-pc.lan ([218.70.255.58]) by newxmesmtplogicsvrszb9-0.qq.com (NewEsmtp) with SMTP id E112FC12; Mon, 15 Jan 2024 03:56:17 +0800 X-QQ-mid: xmsmtpt1705262177tqrr4biqc Message-ID: X-QQ-XMAILINFO: NQR8mRxMnur9qJqW6WlkeAfDDZIHIUWFf62lHXj5+7j9b/4lnmECzz+d7Pbxhp 75Wr185z4svs6HRiLa3p3mJVWnQzxP160GOB0oaXzlRXNc9TzstTyZ2G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chiu , Conor Dooley , linux-kernel@vger.kernel.org, Yangyu Chen Subject: [PATCH 0/3] RISC-V: mm: correct mmap behavior in sv48 address space Date: Mon, 15 Jan 2024 03:55:41 +0800 X-OQ-MSGID: <20240114195541.275148-1-cyy@cyyself.name> 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: 1788097043122196781 X-GMAIL-MSGID: 1788097043122196781 Previous patch series [1] violates the principle of mmap syscall as it uses hint address as the largest address space to use rather than where to create the mapping, thus broke the possibility to mmap in sv48, sv57 address space without a MAP_FIXED flag. This patchset corrects the behavior of mmap syscall and use the behavior of x86 5-stage-paging as a reference. I first noticed this issue when I was trying to run box64 on a sv48 system with commit previous than [2]. Then I reported this through private communication, then a box64 contributor did some investigation and found that trying to mmap in sv48 address space without MAP_FIXED flag will always return a random address in sv39. I review the changelog with some tests on qemu and found this issue was introduced from [1]. After reviewing the code, tests and docs, I think the original author might misunderstand the meaning of hint address in mmap syscall. Then I did some investigation on other ISAs like x86 which has 5-stage-paging and found that it has addressed the same issue if some userspace software assumes the pointer size should smaller than 47 bits and also solved in kernel by limiting the mmap in maximum 47 bits address space by default. Finally I correct the behavior of mmap syscall as x86 5-stage-paging does, and migreate the documentation from x86-64 kernel to riscv kernel. [1]. https://lore.kernel.org/linux-riscv/20230809232218.849726-1-charlie@rivosinc.com/ [2]. https://github.com/ptitSeb/box64/commit/5b700cb6e6f397d2074c49659f7f9915f4a33c5f Yangyu Chen (3): RISC-V: mm: fix mmap behavior in sv48 address space RISC-V: mm: only test mmap without hint Documentation: riscv: correct sv57 kernel behavior Documentation/arch/riscv/vm-layout.rst | 48 +++++++++++-------- arch/riscv/include/asm/processor.h | 39 ++++----------- .../selftests/riscv/mm/mmap_bottomup.c | 12 ----- .../testing/selftests/riscv/mm/mmap_default.c | 12 ----- tools/testing/selftests/riscv/mm/mmap_test.h | 30 ------------ 5 files changed, 36 insertions(+), 105 deletions(-)