Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3502888imu; Sun, 11 Nov 2018 16:35:02 -0800 (PST) X-Google-Smtp-Source: AJdET5fv3e/dJOXBxZPtNjWMIJ51vTHhBI2fkmUy85CMglZik4KkJ5KtoTqyL2qC+jh+Yaj8HV7b X-Received: by 2002:a62:75d1:: with SMTP id q200mr411388pfc.254.1541982902129; Sun, 11 Nov 2018 16:35:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541982902; cv=none; d=google.com; s=arc-20160816; b=KMSqbECcSHcJKchg1KJjqJ6Q2mAAjjNboy+RYSLvM3AxGaTswMkJuEAoPyvsrbL/ad c2ZIc3Shi9UJttugOW2xwb6tzWH01DhE1WRUzMgj9xITMqD6hnbu/edw8BU7gf9SE3I9 K/TlW25XozbNRD5enlpNom6tueqBpRHKa7OJAzI/O+F+WX2LUEo9+jhA4zWzZmWfzkQJ ImMjvccb8GBl33mlAGJtVs5Ms7fOnvmMwYmMnuHvQonBN8/blvz3y7R6H7mAOSebdhIQ A/CcfKM9Mf7rsavn/b4TMLbSsMky4W9csrFI9PF3y9ImUv4ZJ1X9wBqaWcIQBf2mc+w/ xq1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=/CsDxASX/xWQbwdXl5IiplVTXHdEVTx3byb4PI8F+9U=; b=n4pgKVLbOy2dlIir8DtKt36YIHVV5eBhC13bLu5R9wbKBwFASGNrzQd0m8V7Ojl7q7 oIL9UFQGiZSZMzySut8RU24MzVOHa6zGpnjs/VCBRKpCmFSCFVFmo0hf8RGEnNLkbCu9 RqeYdivCYOCcnE9WipQTvehbuFU3L5IhQOGYIaqZsnL3yPVG5/94uTwMx7ijGDtrQrSo w2mTsq8avOaBTHnTmZlcuYKN6lu22gWCPTU2/M7AolsX8LmBjaekLeUs1USOZvx69c7r MF5oSLHMMu9uZ75DkMRIrqx+wDcn84q4EcHh6CE6IvT8BELMWZ9Q/FXq4s6YYXh3EfRF XGmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=aPg4A5il; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c13-v6si12260830pfn.184.2018.11.11.16.34.44; Sun, 11 Nov 2018 16:35:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=aPg4A5il; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729653AbeKLKYy (ORCPT + 99 others); Mon, 12 Nov 2018 05:24:54 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:48784 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726816AbeKLKYy (ORCPT ); Mon, 12 Nov 2018 05:24:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=/CsDxASX/xWQbwdXl5IiplVTXHdEVTx3byb4PI8F+9U=; b=aPg4A5ilBc3EH2O+/m73a6KLWc ++5IdH3cEo+Jzut/oMukYFOnv/0PKAzWHDMkoplFHjo4ZzD8+lh3/vksv9MNzfORm/X791Eoc9I+/ JiKpBF43tksuI7d4p1Lk6IGVYdoHuNmuIYFIzA8FeNzszSvQhAYGQb7jqz/d1XtebQ/adv12qEB0m KCski0wR3ynlPcbcmxCXLO8ygVhkzG6K5MpQoU1NdbagrB3NrUeEZ7rjZKEYui28qSuf4dyOt0plh L196zbMy8YIQ2bswMspYxaVK5T24Os0QTXJEdJ2eChMCnR21Ja4wmRL/N8yb8Xklsq88BbWYW9gRR i8ytl5mQ==; Received: from [64.114.255.97] (helo=worktop) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gM0BC-0004ho-9o; Mon, 12 Nov 2018 00:34:14 +0000 Received: by worktop (Postfix, from userid 1000) id E28636E061A; Mon, 12 Nov 2018 01:34:13 +0100 (CET) Date: Mon, 12 Nov 2018 01:34:13 +0100 From: Peter Zijlstra To: Nadav Amit Cc: Ingo Molnar , "linux-kernel@vger.kernel.org" , "x86@kernel.org" , "H. Peter Anvin" , Thomas Gleixner , Borislav Petkov , Dave Hansen , Kees Cook , Dave Hansen Subject: Re: [PATCH v4 05/10] x86/alternative: initializing temporary mm for patching Message-ID: <20181112003413.GE3056@worktop> References: <20181110231732.15060-1-namit@vmware.com> <20181110231732.15060-6-namit@vmware.com> <20181111144327.GG12766@worktop.psav.com> <0A01B5B5-C771-45AC-81B3-92EE9611D8B2@vmware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <0A01B5B5-C771-45AC-81B3-92EE9611D8B2@vmware.com> User-Agent: Mutt/1.5.22.1 (2013-10-16) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Nov 11, 2018 at 08:38:53PM +0000, Nadav Amit wrote: > From: Peter Zijlstra > > On Sat, Nov 10, 2018 at 03:17:27PM -0800, Nadav Amit wrote: > >> +void __init poking_init(void) > >> +{ > >> + spinlock_t *ptl; > >> + pte_t *ptep; > >> + > >> + poking_mm = copy_init_mm(); > >> + if (!poking_mm) { > >> + pr_err("x86/mm: error setting a separate poking address space"); > >> + return; > >> + } > >> + > >> + /* > >> + * Randomize the poking address, but make sure that the following page > >> + * will be mapped at the same PMD. We need 2 pages, so find space for 3, > >> + * and adjust the address if the PMD ends after the first one. > >> + */ > >> + poking_addr = TASK_UNMAPPED_BASE + > >> + (kaslr_get_random_long("Poking") & PAGE_MASK) % > >> + (TASK_SIZE - TASK_UNMAPPED_BASE - 3 * PAGE_SIZE); > >> + > >> + if (((poking_addr + PAGE_SIZE) & ~PMD_MASK) == 0) > >> + poking_addr += PAGE_SIZE; > >> + > >> + /* > >> + * We need to trigger the allocation of the page-tables that will be > >> + * needed for poking now. Later, poking may be performed in an atomic > >> + * section, which might cause allocation to fail. > >> + */ > >> + ptep = get_locked_pte(poking_mm, poking_addr, &ptl); > >> + if (!WARN_ON(!ptep)) > >> + pte_unmap_unlock(ptep, ptl); > >> +} > > > > The difference in how we deal with -ENOMEM here is weird. I think we > > have a _lot_ of code that simply hard assumes we don't fail memory alloc > > on init. > > > > I for instance would not mind to simply remove both branches and let the > > kernel crash and burn if we ever fail here. > > Actually, now that we removed the fallback of patching without poking_mm, a > failure to allocate poking_mm should have had a BUG_ON(). > > For the second case, I think we still need either WARN_ON() or BUG_ON(), at > least as some sort of an in-code comment. I’ll change it to BUG_ON() if you > prefer. Sure, two BUG_ON()s works for me.