From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63E42C77B7F for ; Thu, 11 May 2023 06:31:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D8B866B0075; Thu, 11 May 2023 02:31:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D3C0E6B0078; Thu, 11 May 2023 02:31:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB5216B007B; Thu, 11 May 2023 02:31:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A96586B0075 for ; Thu, 11 May 2023 02:31:39 -0400 (EDT) Received: by unirelay03.hostedemail.com (Postfix, from userid 8) id F23B9A0D5F; Thu, 11 May 2023 06:28:46 +0000 (UTC) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 185D1A0B11 for ; Thu, 11 May 2023 03:16:47 +0000 (UTC) X-FDA: 80776512054.30.9588781 Received: from mail-yb1-f180.google.com (mail-yb1-f180.google.com [209.85.219.180]) by imf06.hostedemail.com (Postfix) with ESMTP id 366AE180015 for ; Thu, 11 May 2023 03:16:39 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=JDYjlZO6; dmarc=temperror reason="server fail" header.from=google.com (policy=temperror); spf=pass (imf06.hostedemail.com: domain of hughd@google.com designates 209.85.219.180 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1683775000; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hRBzifhysJxaavDAsJ+Sa+/VyNhQzLXJPjsoUGcNRd4=; b=3wKzQgjHwSzKFSWaOS1l5TzQS5/8b8QxL5UCZoFCAJhiwmNd7toqVf3SLBKU+iKP2OjQgW PSirqz4cMKCwdVPtbdkI6/Xrc0jfN9D/WeDFjDdWGbI5RiP5ZjpO1DSZhwxNa64mKwiS0K 9UMKOlOoeIzCSEpDK9F8VD0JV+4BhII= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=JDYjlZO6; dmarc=temperror reason="server fail" header.from=google.com (policy=temperror); spf=pass (imf06.hostedemail.com: domain of hughd@google.com designates 209.85.219.180 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1683775000; a=rsa-sha256; cv=none; b=MAsW1yMHJUJw9k6JT0fWzzb67jeyyBvrAdDd5kljGArl1PT08eAmAtns1Ys7cTToIfpQHF 9K3KD+SuguIO0RLryaRgaKG43Jcst/WWpUqsWOPF0j0Cljj63zY4nEuJN4Si34yusTBG5j nTPT0GxM4tvKgnttOvq4RFA1KXYtk3U= Received: by mail-yb1-f180.google.com with SMTP id 3f1490d57ef6-b9e66ce80acso10447435276.3 for ; Wed, 10 May 2023 20:16:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683774999; x=1686366999; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=hRBzifhysJxaavDAsJ+Sa+/VyNhQzLXJPjsoUGcNRd4=; b=JDYjlZO6u5Rd6QYeBUTXCp/kgqPCJk7kIYj5131tW+Oftjr3CeY+3TrtF265PwQLsY CzyhzuHdTlVexa4Irr81wJWJONYV4WJYb+Qmn3xCOOTrZII3mN3FIl3WlUa9ZzRwMyft TbG+lOOAm/FlIwiaNhNLr42JUk/Xp0bH2c5++eORJ8zXY8TzfBVIgW201ldf27i4oXvO WYco0w5tL3fNC1aMrOMXgic+X453i3JN5jojWOgIXdVajjoFoae+wDli+04h87K4PSDU PrZHQkqAQy9rNdfpBcTkPkLhTcEgcEAEnkRKNVLkHXWaXGdspdGha99g/0X8mBFfM1nS C7lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683774999; x=1686366999; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hRBzifhysJxaavDAsJ+Sa+/VyNhQzLXJPjsoUGcNRd4=; b=RbSso9fr0Ch44e+9D34EOWKwY60lz3iCw7wSs0DOO0tb2PTpfdIJqyM0QlM8JEbPcQ We5iX403B/hHR1piakwg3dBr/7qqueIlHg1J9N1aV40LrXY6tGyQv+lTKTEDZX9e3rqf bN7HE7uqwZXA7m22XpoCdypki5ZsLTVD5gwSe8VBTsRIRKDIzsz26POL0zEGovnhV93z Bz55l9ctReLWFol4Yu7LDO0lrmWWA3wF2NCmB1kDA8R4YwTDAI+9YUESPhX2ckxznI/A ntnbQ+llKg5B0/yDmXcsOu/1eoRG3wsOciAlR1SeWZLRds2GMuY5K5q6Ze+B0hf5o0B/ 1TTA== X-Gm-Message-State: AC+VfDwsTCIvQaho0tjHSsPeYqjB/16lJPpML/U4R0pmU+6UwuBjP3zp UbKEC97qKMk6z5Bw4CEqaO4fsg== X-Google-Smtp-Source: ACHHUZ7/wlg4bppDf9uBVNG9J9Qk7aL+NA0hCKaxoiuDXlSicnUNf7o6tqD4YBoUi/tdOZkorZkwaA== X-Received: by 2002:a25:4087:0:b0:b9e:5006:42af with SMTP id n129-20020a254087000000b00b9e500642afmr19049386yba.58.1683774998976; Wed, 10 May 2023 20:16:38 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id j128-20020a255586000000b00b923b2935d9sm4144529ybb.20.2023.05.10.20.16.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 20:16:38 -0700 (PDT) Date: Wed, 10 May 2023 20:16:34 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Peter Zijlstra cc: Hugh Dickins , Andrew Morton , Mike Kravetz , Mike Rapoport , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Suren Baghdasaryan , Qi Zheng , Russell King , Catalin Marinas , Will Deacon , Geert Uytterhoeven , Greg Ungerer , Michal Simek , Thomas Bogendoerfer , Helge Deller , John David Anglin , "Aneesh Kumar K.V" , Michael Ellerman , Alexandre Ghiti , Palmer Dabbelt , Heiko Carstens , Christian Borntraeger , Claudio Imbrenda , John Paul Adrian Glaubitz , "David S. Miller" , Chris Zankel , Max Filippov , x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 21/23] x86: Allow get_locked_pte() to fail In-Reply-To: <20230510081848.GD83892@hirez.programming.kicks-ass.net> Message-ID: References: <77a5d8c-406b-7068-4f17-23b7ac53bc83@google.com> <20230510081848.GD83892@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Stat-Signature: t5t9qyweqzi6gh7ob8jhwzuzsdds99au X-Rspam-User: X-Rspamd-Queue-Id: 366AE180015 X-Rspamd-Server: rspam07 X-HE-Tag: 1683774999-530430 X-HE-Meta: U2FsdGVkX18yxu41+b3Lr7AX5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aD/ijTSh9nbMryU91HQ6j5MBeAng4coyEgMomYvjwFQplIkvhF6+eVm00ioKLaBBqo7pQBXjiauFio6o4ufMZe87ax5Iu33WEhYo4iCzs9e00wKfyrU8q07a86PGWexIPZkep22B3vg3WK8L3jLol5Fi45qMLyYF6LIXSqoKAjO1CGoXKXcHCIdHQNiOZPoe5+0J+N1BWR5JrQHp1411hWoF9vVLgetxFy5EnsHVmRxcihZOQxYLJdYkCke9wqoW3GcGlRsPQ24cQsqbPUonKwQOrK+XxdcP1QBh/61ukRhR7u1qpMOJS1XP8WA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, 10 May 2023, Peter Zijlstra wrote: > On Tue, May 09, 2023 at 10:08:37PM -0700, Hugh Dickins wrote: > > In rare transient cases, not yet made possible, pte_offset_map() and > > pte_offset_map_lock() may not find a page table: handle appropriately. > > > > Signed-off-by: Hugh Dickins > > --- > > arch/x86/kernel/ldt.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c > > index 525876e7b9f4..eb844549cd83 100644 > > --- a/arch/x86/kernel/ldt.c > > +++ b/arch/x86/kernel/ldt.c > > @@ -367,8 +367,10 @@ static void unmap_ldt_struct(struct mm_struct *mm, struct ldt_struct *ldt) > > > > va = (unsigned long)ldt_slot_va(ldt->slot) + offset; > > ptep = get_locked_pte(mm, va, &ptl); > > - pte_clear(mm, va, ptep); > > - pte_unmap_unlock(ptep, ptl); > > + if (ptep) { > > + pte_clear(mm, va, ptep); > > + pte_unmap_unlock(ptep, ptl); > > + } > > } > > Ow geez, now I have to go remember how the whole PTI/LDT crud worked :/ I apologize for sending you back there! > > At first glance this seems wrong; we can't just not unmap the LDT if we > can't find it in a hurry. Also, IIRC this isn't in fact a regular user > mapping, so it should not be subject to THP induced seizures. > > ... memory bubbles back ... for PTI kernels we need to map this in the > user and kernel page-tables because obviously userspace needs to be able > to have access to the LDT. But it is not directly acessible by > userspace. It lives in the cpu_entry_area as a virtual map of the real > kernel allocation, and this virtual address is used for LLDT. > Modification is done through sys_modify_ldt(). And there must be a user-style page table backing that cpu_entry_area, because the use of get_locked_pte() and pte_unmap_unlock() implies that there's a user page table (struct page containing spinlock if config says so) rather than just a kernel page table mapping it. > > I think I would feel much better if this were something like: > > if (!WARN_ON_ONCE(!ptep)) > > This really shouldn't fail and if it does, simply skipping it isn't the > right thing either. Sure, I'll gladly make that change when I respin - not immediately, let's get more feedback on this arch series first, but maybe in a week's time. Thanks for looking so quickly, Peter: I didn't Cc you on this particular series, but shall certainly be doing so on the ones that follow, because a few of those patches go into interesting pmdp_get_lockless() territory. Hugh