Received: by 10.192.165.148 with SMTP id m20csp22400imm; Wed, 9 May 2018 08:11:56 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrhV9CSLWoviryYrrLqzoodtU5us/FuB7cmX9qHCXIcez4vfv/xKIfH84PvrlNidyz44sj7 X-Received: by 2002:a63:8f5b:: with SMTP id r27-v6mr26401999pgn.439.1525878716254; Wed, 09 May 2018 08:11:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525878716; cv=none; d=google.com; s=arc-20160816; b=A2oZUhfkZSwN8VoCiJzgxj7L/HcffycnM9IhAwpbn7lP24VS4iZLTqz8nVnpeS/7yi GJ/9co6N+2V0RNfU/V5S4NZFYsT78ZQ3xeRQOloc/dpveB5/XH1mFpO/NuCRO5DTdpyq sZ0bBzvHIXTXFFxCVZNem8mwmBicrYS1v7zC7sdDC19+FuM8oQi5Ih2hEAG4bMzHXh8z B85aOKjjGyH92F4cu4F7n1Wjj6Q1t/hNtg51S0dNjBx/SNoo8OOCh8N4OvHKSZ0/Ut06 GnwNMp1A2XjY9oCrPRwSdc5D5RxeeeS91LTAGM10yebP64NxOEs/kggHI/EQXlRgLB3U b2wQ== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=/r6DzH54CiTW8qJhCA7+hVY4eqzj+12ETn1Xe7dGscA=; b=neNeiKUsMHl65AGWXiQYG4NdYOLY4mXPSOoXRutFdrXrrJHZnd8fkW7u0fcEG6LO1w tUMeXHmD7aIiBQ9ODYAU7253kV4j+3b3sQgKHh95FM6tQKFFWvbkM82/75uCnNWP1o66 rU1lgEOFsoemW17R/5docDJWt4Y1JTeY2G8C4X3qfe3Qd9Q90tcpvIwe3/e7RxJOHvcx dH6D79PYb3VfqwSHjzFr+Ba16Yb3Wio309tKjllqcy5aZqZkUVWjhrLnHVcWabNgr8Jk zetq2lq/b3QYtJ34WZq56S7Y0Jns31I2Ul2+cRCik0BrkJTBft376vKH2FIVlx75Dm+R GCkA== 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 m198-v6si21082886pga.107.2018.05.09.08.11.40; Wed, 09 May 2018 08:11:56 -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 S964816AbeEIPJr (ORCPT + 99 others); Wed, 9 May 2018 11:09:47 -0400 Received: from mga11.intel.com ([192.55.52.93]:14855 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935065AbeEIPJn (ORCPT ); Wed, 9 May 2018 11:09:43 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 May 2018 08:09:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,381,1520924400"; d="scan'208";a="54492399" Received: from theros.lm.intel.com (HELO linux.intel.com) ([10.232.112.164]) by orsmga001.jf.intel.com with ESMTP; 09 May 2018 08:09:38 -0700 Date: Wed, 9 May 2018 09:09:38 -0600 From: Ross Zwisler To: Jan Kara Cc: Ross Zwisler , Andrew Morton , linux-kernel@vger.kernel.org, Matthew Wilcox , Christoph Hellwig , Dan Williams , Dave Chinner , linux-nvdimm@lists.01.org, stable@vger.kernel.org Subject: Re: [PATCH 5/5] radix tree: fix multi-order iteration race Message-ID: <20180509150938.GA3814@linux.intel.com> References: <20180503192430.7582-1-ross.zwisler@linux.intel.com> <20180503192430.7582-6-ross.zwisler@linux.intel.com> <20180509124611.6hoa743z4qrx6bgc@quack2.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180509124611.6hoa743z4qrx6bgc@quack2.suse.cz> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 09, 2018 at 02:46:11PM +0200, Jan Kara wrote: > On Thu 03-05-18 13:24:30, Ross Zwisler wrote: > > Fix a race in the multi-order iteration code which causes the kernel to hit > > a GP fault. This was first seen with a production v4.15 based kernel > > (4.15.6-300.fc27.x86_64) utilizing a DAX workload which used order 9 PMD > > DAX entries. > > > > The race has to do with how we tear down multi-order sibling entries when > > we are removing an item from the tree. Remember for example that an order > > 2 entry looks like this: > > > > struct radix_tree_node.slots[] = [entry][sibling][sibling][sibling] > > > > where 'entry' is in some slot in the struct radix_tree_node, and the three > > slots following 'entry' contain sibling pointers which point back to > > 'entry.' > > > > When we delete 'entry' from the tree, we call : > > radix_tree_delete() > > radix_tree_delete_item() > > __radix_tree_delete() > > replace_slot() > > > > replace_slot() first removes the siblings in order from the first to the > > last, then at then replaces 'entry' with NULL. This means that for a brief > > period of time we end up with one or more of the siblings removed, so: > > > > struct radix_tree_node.slots[] = [entry][NULL][sibling][sibling] > > > > This causes an issue if you have a reader iterating over the slots in the > > tree via radix_tree_for_each_slot() while only under > > rcu_read_lock()/rcu_read_unlock() protection. This is a common case in > > mm/filemap.c. > > > > The issue is that when __radix_tree_next_slot() => skip_siblings() tries to > > skip over the sibling entries in the slots, it currently does so with an > > exact match on the slot directly preceding our current slot. Normally this > > works: > > V preceding slot > > struct radix_tree_node.slots[] = [entry][sibling][sibling][sibling] > > ^ current slot > > > > This lets you find the first sibling, and you skip them all in order. > > > > But in the case where one of the siblings is NULL, that slot is skipped and > > then our sibling detection is interrupted: > > > > V preceding slot > > struct radix_tree_node.slots[] = [entry][NULL][sibling][sibling] > > ^ current slot > > > > This means that the sibling pointers aren't recognized since they point all > > the way back to 'entry', so we think that they are normal internal radix > > tree pointers. This causes us to think we need to walk down to a struct > > radix_tree_node starting at the address of 'entry'. > > > > In a real running kernel this will crash the thread with a GP fault when > > you try and dereference the slots in your broken node starting at 'entry'. > > > > We fix this race by fixing the way that skip_siblings() detects sibling > > nodes. Instead of testing against the preceding slot we instead look for > > siblings via is_sibling_entry() which compares against the position of the > > struct radix_tree_node.slots[] array. This ensures that sibling entries > > are properly identified, even if they are no longer contiguous with the > > 'entry' they point to. > > > > Signed-off-by: Ross Zwisler > > Reported-by: CR, Sapthagirish > > Fixes: commit 148deab223b2 ("radix-tree: improve multiorder iterators") > > Cc: > > Looks good to me. You can add: > > Reviewed-by: Jan Kara Thank you for the review, Jan.