Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1663025rdb; Sat, 23 Dec 2023 17:24:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IFWgEU/acvFSyyEfLKMRKtPyqlcUo9gbG+aNPNNKeYdVyl+Tm6M4TGsjrXVY172y0HYeXdH X-Received: by 2002:a05:620a:8209:b0:781:2afb:9bdf with SMTP id ow9-20020a05620a820900b007812afb9bdfmr3789535qkn.50.1703381062561; Sat, 23 Dec 2023 17:24:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703381062; cv=none; d=google.com; s=arc-20160816; b=IXXUpmtmeCz/fx5K7VQwYMQrbgehc4fRLhDbtobQ+NxgE9sv8eA4j645KzSnZvJCFf SNWzQxxYvObb8NMFtP4g0a0UcDx8zP7SjJa0gBI7AnJhsOo4JxLwzfDNEulRwbo+VSIU yTV2zPdRiEWdcYyXML0D5gqlilNCuIHJ2iFANShgZs7F0Avi7qeYLkhPyoaJ6MkyGsvM 7kUTDRBVIDNNgT5Ic2cIWcUepcJJMKvq1B3CPyLnxy39vKLqM/x5duizuO5Po1294Cas rlQAKdgzm2QITTJoUzPQu04O3WYtRAtPCnr0w7ak6WQz2753IvXnfW+cEl/KuzGsXIon 4OcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=E9MD8EkLkJLf+M5TbfkUdCU5Yt3OasciUqzF37EWFXc=; fh=A78Ob4OkQhcrc9fF2kCzUxJhWq20+Me+Hfow3c50/jM=; b=BJFDa85CLNonH09PZvVW7A1yJHpuOHZL0EuPg9q1jld08g6JV8bLUonBEoauEO3Pzc pq0EtEUprZK6LZKSh3IviVdjXhHt4jMi64DYGLVNRE0cbtH/LgNS/HUWnQiLsLTyw3KD M27a8+O+isBWVER7NGnBXJnbPuYRl7kjAMTDtAhKYP54+y5T31HQVFb2FUwjgBRR6+MU N/KulJjELx+Q0pnK1eka6evPzXo082umghw+5Z0mgD3N/K1yq03dCI6xjV0JaOEJI7OP 3Dtw4dfIBT1Eq54zMrp842OjyEN/nb+ETx8bOHdqX1RftwdSXXVoZel6IUtKEhkTx+7r dPtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="T15Ae/+A"; spf=pass (google.com: domain of linux-kernel+bounces-10619-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10619-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f16-20020a05620a409000b00777e47ef0a4si8197017qko.166.2023.12.23.17.24.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Dec 2023 17:24:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10619-linux.lists.archive=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=@kernel.org header.s=k20201202 header.b="T15Ae/+A"; spf=pass (google.com: domain of linux-kernel+bounces-10619-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10619-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 3DE6A1C20D75 for ; Sun, 24 Dec 2023 01:24:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 648E1815; Sun, 24 Dec 2023 01:24:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="T15Ae/+A" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 92C377EA for ; Sun, 24 Dec 2023 01:24:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F120BC433CA for ; Sun, 24 Dec 2023 01:24:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1703381055; bh=/H0+iF+fDn9DTrAW4o9tox8uhqnr94eocMPWRFJRU0s=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=T15Ae/+AuOnYFc6GQj3tfN5c8UaAV7WLR512HkGl/SPDPgxKE73XQJoiFRNmkquuW YpUcorvbZh4FeJFfxveoQFJFj1WUaJaAA/Fxk0fNm6lVvaoJDq7pcHcCG2IK7nswf+ 2RS6/02jRB1AkQq9UBlwjd1iIMIrs3vb/6MaJzMVVCaC/aUmDohu0+8y99KtQdZzaU G6sTCb6MWYl6kPN3brqRrdObKMSxRZGW7CwKQxCH1zzP8C1AHSMj7ZUIQGhS0p9gxB AFJoiC6k79mkDLhR+M2YZPq0MziKmGoLk8uKhIQPTvZLJBkX2qH80/rmEjnx+iw5r2 f9i/yk960zRFg== Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-40d4d70eca6so14558835e9.3 for ; Sat, 23 Dec 2023 17:24:14 -0800 (PST) X-Gm-Message-State: AOJu0YwIuenJUbENB8NXK8lYvsaJkYXIEwHTMo66xeiL/vcTOllb51u7 gLsfCb2reFbRwYstzKNpDFyKsCbPwkAce2rwCqU= X-Received: by 2002:a05:600c:748:b0:40c:35fd:be08 with SMTP id j8-20020a05600c074800b0040c35fdbe08mr1371260wmn.122.1703381053321; Sat, 23 Dec 2023 17:24:13 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231221154702.2267684-1-guoren@kernel.org> <20231221154702.2267684-5-guoren@kernel.org> <9d4d15e8e3e944b8bd18e8bc1d54f59c@AcuMS.aculab.com> In-Reply-To: <9d4d15e8e3e944b8bd18e8bc1d54f59c@AcuMS.aculab.com> From: Guo Ren Date: Sun, 24 Dec 2023 09:24:00 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH V2 4/4] riscv: mm: Optimize TASK_SIZE definition To: David Laight Cc: Leonardo Bras , "linux-kernel@vger.kernel.org" , "paul.walmsley@sifive.com" , "palmer@dabbelt.com" , "alexghiti@rivosinc.com" , "charlie@rivosinc.com" , "xiao.w.wang@intel.com" , "david@redhat.com" , "panqinglin2020@iscas.ac.cn" , "rick.p.edgecombe@intel.com" , "willy@infradead.org" , "bjorn@rivosinc.com" , "conor.dooley@microchip.com" , "cleger@rivosinc.com" , "linux-riscv@lists.infradead.org" , Guo Ren Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Dec 23, 2023 at 6:31=E2=80=AFPM David Laight wrote: > > From: Guo Ren > > Sent: 23 December 2023 02:53 > > > > On Fri, Dec 22, 2023 at 7:52=E2=80=AFPM David Laight wrote: > > > > > > From: Guo Ren > > > > Sent: 22 December 2023 11:25 > > > ... > > > > > > +#define TASK_SIZE (is_compat_task() ? \ > > > > > > TASK_SIZE_32 : TASK_SIZE_64) > > > > I would remove is_compat_task() in the next version because your pa= tch > > > > contains that. > > > > > > Does TASK_SIZE get used in access_ok() ? > > > If so the repeated expansion of that 'mess' will slow things down. > > > > > > OTOH access_ok(ptr, len) can just check (ptr | (ptr + len)) < 0) > > > and rely on the page faults for everything else. > > Or do you want to discuss the bad side effect of is_compat_task()? > > > > Yes, test_thread_flag(TIF_32BIT) would slow down access_ok(). But if > > we use TASK_SIZE_MAX, VA_BITS still needs pgtable_l5_enabled, > > pgtable_l4_enabled detectation for riscv. > > > > It's not only for compat mode, but also Sv39, Sv48, Sv57. All treat > > TASK_SIZE_MAX as 0x8000000000000000, right? Then: > > access_ok(ptr, len) can just check (ptr | (ptr + len)) < 0) > > > > It's another feature and does not relate to compat mode. > > Compat mode just makes it worse... It's hard to observe. > > One possibility would be to save the task's max user address > in the task structure itself - that would save all the conditionals > at a cost of an extra value in the task structure. It would still cause memory load operation, although it is $tp->xxx. If we want to gain observability benefits, "just check (ptr | (ptr + len)) < 0)" is better. > > There is also the question of whether a normally 64-bit task > can actually make the compat mmap() system call? No. > On x86 that is certainly possible (IIRC wine does it), x86 > userspace can flip between 32bit and 63bit mode without a > system call. RISC-V can't do that because it needs sstatux.uxl=3D32/64, which can only be modified in S-mode. > > David > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1= 1PT, UK > Registration No: 1397386 (Wales) --=20 Best Regards Guo Ren