Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2852124rwr; Fri, 28 Apr 2023 17:50:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5TtNAcajKo467z9SC0UqGNHD7xs44+vBcVLx3jlAFv0XXfp4p2Q5EpPCFuW0+Evqn2YwEu X-Received: by 2002:a05:6a00:1a0f:b0:63d:3a18:49fd with SMTP id g15-20020a056a001a0f00b0063d3a1849fdmr8709965pfv.2.1682729406386; Fri, 28 Apr 2023 17:50:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682729406; cv=none; d=google.com; s=arc-20160816; b=w1+nQRrEYGV1PutqVlAi4bQ8qu2ynTMf6Vps6CJWNLYhhLpnqNh+iCD3K56XcTzDA0 tErvHOsicqvYDJYB/6u/4i1TquKKQD5fkB79HMVsAg6Wvr/+tzRTnqwxKzj4rHDB+475 TRXUqjBgdKVui9IEOn3100AXMWsl3SuZuMoumFmlWO2zw++RR8k8lzuZMeGUkX0aXm7F Y6gh6iht19qr1pfLSD53tNKhY62CDvjk4mNvhVQBqlCIrCLnkdXk1g4FSzP8axtXTXG5 P0jURwUJhbzrhRQS/4OjGcIS/G0qyGELX9/jwpRwXsl/V7b4rhRqUuhAnQ8I9+DNGJuH Svrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:feedback-id:dkim-signature:dkim-signature; bh=MxLCpu5U79qjWhiQ3WAhq0F12mE7kqiiiVKbZ6XzXP4=; b=VN+zZynsCA7ywcjfGKXchHRPliucVaCE6noW//hVCHvPOL0zLhbrHU+IqZOkLuy5LM nxiS8HntavGW+JUw15J46UieIqyCmP3TPJ4cLFtaVHfTZaV9WtHFG0TcBlcsu3ZpQzER pidMGZGOjw2hcZXtEnmI7ymdkHIGkbZBM5yz7HA08ojztTbRVVSnpywgUSju0F6BQUXs MBGAmMeBN8NjqKrxpHXcUiRtiTc2KNmPu9ZJnyog1CQsbbb5N4GicMZKfctItXfjdiT5 0ADAtdJoZ3JgF6ej9zY/u2nvLBQoSIOegZCaZJ3IIm6BRDaPkp06NgddG0McuPpJT2Vj 6oOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov.name header.s=fm1 header.b=b3m3xs1G; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b="e4/dDau+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e11-20020aa7980b000000b0063b68fa0803si23277735pfl.268.2023.04.28.17.49.54; Fri, 28 Apr 2023 17:50:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@shutemov.name header.s=fm1 header.b=b3m3xs1G; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b="e4/dDau+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347163AbjD2Ai3 (ORCPT + 99 others); Fri, 28 Apr 2023 20:38:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230104AbjD2Ai1 (ORCPT ); Fri, 28 Apr 2023 20:38:27 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85F8A40C8 for ; Fri, 28 Apr 2023 17:38:26 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 946D95C00A5; Fri, 28 Apr 2023 20:38:25 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Fri, 28 Apr 2023 20:38:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov.name; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to; s=fm1; t=1682728705; x=1682815105; bh=MxLCpu5U79qjWhiQ3WAhq0F12 mE7kqiiiVKbZ6XzXP4=; b=b3m3xs1GsrzbB08awngro455npFaWrUXuKNT76qnX j0N1vVqw6eRL+9syf8ugb0/C3uZUWT9bhh/UF6ysY1uKvJHB+s1gZtTfUFCevrwt uFevjoouoBKfTrshXQFsiI+YglucZDVdiBE4uz+jHKOqb4Ne+Vd1vbhIRdSq0rDc xwgrRYdtdbl4gnApFwM04WR8eEyOhzxFRuYTxrLtWQthziDYIPYOraQs5HVriV+p G2WXpCiOkXP0PEyNt9XdrI403j//zFg0SR7MTu5uIhe05HDfQBYwsFBdOVsPW3nt cV+eKNge9Q/9MkAatLaID0mHtDqDw+EdLKWCBy7Q5jwDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1682728705; x=1682815105; bh=MxLCpu5U79qjWhiQ3WAhq0F12mE7kqiiiVK bZ6XzXP4=; b=e4/dDau+8HBuq9FUrZnVgprjDStrPDbKgqDfFzyx6KC21Nv2SMq vcS4Gd+j57fUKYCrkPd6TwLy/vgejpKzd6gL1Ga42E/49ro6tC2DHD8BhWpv9UmB 4UbkBZRzPm9nMcyVABd1rmdBhGdIK8/TiToyKk0IpdAj99LO+uoOFJ+iUdsmJNDf ZRBOhzfSykIKljksQQMc6a1TbjqyplOsqnL1AjmdfP1nQnjkYKz/K9DZ6KBCmAi5 QNF0CfW/KO6OOAWR7kajygd75OmZQ4JpDEvSKxm5GcI0CvPXrgEPm3TBParwOFMs QBkqF5O/nCXi5GRFxW/2QR/b7Y+FdPokNRQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeduledgfeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggugfgjsehtkedttddttdejnecuhfhrohhmpedfmfhi rhhilhhlucetrdcuufhhuhhtvghmohhvfdcuoehkihhrihhllhesshhhuhhtvghmohhvrd hnrghmvgeqnecuggftrfgrthhtvghrnhepgfejieekffeffeevudfgtdekvdfhtddtieef vedtheeggfejffellefggffgvdeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrg hmpehmrghilhhfrhhomhepkhhirhhilhhlsehshhhuthgvmhhovhdrnhgrmhgv X-ME-Proxy: Feedback-ID: ie3994620:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 28 Apr 2023 20:38:24 -0400 (EDT) Received: by box.shutemov.name (Postfix, from userid 1000) id E07F51041AE; Sat, 29 Apr 2023 03:38:22 +0300 (+03) Date: Sat, 29 Apr 2023 03:38:22 +0300 From: "Kirill A. Shutemov" To: Linus Torvalds Cc: Dave Hansen , x86@kernel.org, linux-kernel@vger.kernel.org, kirill.shutemov@linux.intel.com, Peter Zijlstra Subject: Re: [GIT PULL] x86/mm for 6.4 Message-ID: <20230429003822.n3mglslg666j3npp@box.shutemov.name> References: <20230427225647.1101172-1-dave.hansen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 28, 2023 at 01:15:33PM -0700, Linus Torvalds wrote: > On Fri, Apr 28, 2023 at 1:07 PM Linus Torvalds > wrote: > > > > So here's my suggested change on top of the current tree. Comments? > > Oh, and I wanted to particularly mention that > > We could probably just do that "check only starting address" for any > arbitrary range size: realistically all kernel accesses to user space > will be done starting at the low address. But let's leave that kind of > optimization for later. As it is, this already allows us to generate > simpler code and not worry about any tag bits in the address. > > part of the commit log. > > Right now that patch only simplifies the range check for when the > compiler statically knows that the range is small (which does happen, > but not very often, because 'copy_to/from_user()' isn't inlined on > x86-64, so the compiler doesn't actually see the constant size case > that is very common there). BTW, I think the static check can be relaxed. Checking size against PAGE_SIZE is rather conservative: there's 8 TB (or 4 PB for 5-level paging) guard hole at the begging of kernel address space. > However, that "check the end of the range" is sometimes actually > fairly complicated code, and it would be nice to drop that entirely. > > See for example the fs/readdir.c case, where the length of the access > is kind of annoying: > > if (!user_write_access_begin(dirent, > (unsigned long)(dirent->d_name + namlen + 1) - > (unsigned long)dirent)) > goto efault; > > and there really isn't any actual reason to check the end of the > access on x86: if the beginning address has the low bit clear, it > doesn't really matter what the end is, because we'll either have a > good area, or we'll fault in the non-canonical area even if the sign > changes. > > So being careful about the range is kind of annoying, when we don't > really need it. Hm. Is there anybody who access high to low after the check (glibc memcpy() bug flashbacks)? Or not in any particular order? -- Kiryl Shutsemau / Kirill A. Shutemov