Received: by 10.192.165.148 with SMTP id m20csp1671imm; Fri, 20 Apr 2018 01:51:08 -0700 (PDT) X-Google-Smtp-Source: AIpwx485v9jW16Xi4T9QCnANLSvoLPEyDEFWgDWWaptb0PB827EjU9HsJI2h+EbDhvtooYR30D2B X-Received: by 10.101.97.1 with SMTP id z1mr8029307pgu.134.1524214268220; Fri, 20 Apr 2018 01:51:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524214268; cv=none; d=google.com; s=arc-20160816; b=V3XLUQfuVsB5E4WQhkTRo3Rs0d/YrdfwPOyJXFt0c1251DO05d+FBxtyQkXlDQNTLr ytxYrLXEQRjU+wEpyHV7pHh3AdHBkdQ4C5N5a0sqW2J2aTJcTF2IBMLc4cbQtGqvWVF3 fMNn9QIO7nLuBe38M+jGZ+mxtXmFNaric2VaTvKK3HkD/KuRud4m7p7kRnD5fEq5OqmM AI921pIbpi8Ups9/L5iQI4ZBNzNPs/BKbHdU8PziNnmPcuW+4KbeJuqBuK1s9728HH6a gpziq88JkmsC8eBb6f0wHvvCA94mH+h7rlXH1Lks4o74honiEPVeXg7SquINScoi5ucl pBeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=OKrD6wc5JxlZdqda6X59wyVoJE+kKITY7/n2AVZqRNM=; b=XAg9IlGbkOn7ihMeZDrEOmNr4fwzX5l4WiXfP5dFhua4Q/u3Wc/B6j8gZ5BN/Ie25+ FOgi8v+ViDFS6IbajwK/02Q+rIYaDGkSPqM7DFEIc9xKeCoRQDoimIN58OtoO6Al2s9a 3lL9EYrXB8memM9e0QMYXwtCFnpXy8imbGRvldWZFtfBpVja37NxlpX/Mo99LTK0XNsL mR6UmR1FS62N71EegqG6yGGZGPvn0f9oHNneZg+XbjPZrLwmBy5B443LnEGvj6bw2IYM YTSkQZwDAe0OFPtSiUUE/8CKY6JWFSesBekY3Eb/zAjNqPQlTQUs3oj5JvBSzfOFwmPf ZcMA== ARC-Authentication-Results: i=1; mx.google.com; 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 r1-v6si5331973plb.430.2018.04.20.01.50.54; Fri, 20 Apr 2018 01:51:08 -0700 (PDT) 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; 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 S1754196AbeDTItn (ORCPT + 99 others); Fri, 20 Apr 2018 04:49:43 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:44341 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753918AbeDTItm (ORCPT ); Fri, 20 Apr 2018 04:49:42 -0400 Received: from static-242-42-24-46.ipcom.comunitel.net ([46.24.42.242] helo=nanos) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1f9Rjc-0000mM-7S; Fri, 20 Apr 2018 10:49:36 +0200 Date: Fri, 20 Apr 2018 10:49:05 +0200 (CEST) From: Thomas Gleixner To: NeilBrown cc: Mike Snitzer , LKML , Kees Cook , Segher Boessenkool , Kernel Hardening , Andrew Morton , Boris Brezillon , Richard Weinberger , David Woodhouse , Alasdair Kergon , Anton Vorontsov , Colin Cross , Tony Luck Subject: Re: [patch V2 7/8] dm verity fec: Check result of init_rs() In-Reply-To: <87o9ieq1ud.fsf@notabene.neil.brown.name> Message-ID: References: <20180419100441.548834519@linutronix.de> <20180419100935.340306831@linutronix.de> <20180419134647.GA9817@redhat.com> <87o9ieq1ud.fsf@notabene.neil.brown.name> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 20 Apr 2018, NeilBrown wrote: > On Thu, Apr 19 2018, Thomas Gleixner wrote: > > The analysis above forgot to look at the mempool->alloc() callback. So yes, > > while the NOIO is good at the mempool level, but init_rs() uses GPF_KERNEL > > so there might be a different can of wurms lurking. > > The ->alloc call back is not relevant to the question of when > mempool_alloc() can return NULL. > If the ->alloc() callback returns a non-NULL value, it will be returned > by mempool_alloc(). > If it returns NULL, that will not be returned. Yes, as I said before, I missed the NOIO flag. > > mempool_alloc() *only* returns NULL in one place: > > if (!(gfp_mask & __GFP_DIRECT_RECLAIM)) { > spin_unlock_irqrestore(&pool->lock, flags); > return NULL; > } > > so a NULL return is purely dependent on the GFP flags passed. > GFP_NOIO contains __GFP_DIRECT_RECLAIM, so NULL cannot be returned. > > It seems quite broken that init_rs() uses GFP_KERNEL. It should take a > gfp_t arg for the allocation. Well, init_rs() was that way before somebody used it in a mempool_alloc() callback. And all other users are fine with GFP_KERNEL AFAICT. > If the mempool_alloc() above really needs GFP_NOIO, then it could > theoretically deadlock as it performs a GFP_KERNEL allocation inside > rs_init(). So in that sense, the code is not correct as-is. > It could possibly be fixed by calling memalloc_noio_save() / > memalloc_noio_restore() around the call to init_rs() in fec_rs_alloc(). No, we surely can add a gfp aware version of init_rs(). It's trivial enough to do. Thanks, tglx