Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp243202pxf; Wed, 10 Mar 2021 05:30:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJyI5AXH68In5pdXBroLYZ3kc0NUf2JMKQ3gx73x4ou8WnPiP+CHc5MyT9QF86nJAPb1MnUx X-Received: by 2002:a17:906:82c5:: with SMTP id a5mr3802516ejy.232.1615383038337; Wed, 10 Mar 2021 05:30:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615383038; cv=none; d=google.com; s=arc-20160816; b=Zuodn9D/OYhchFKx9tedHZwT7JHsGMrHhuA8dYp3UAi6+xlrAU1kQrVG0UpWJuYI2e CPfuIAGUlywZWsnR6ygu8MhIsUuo420eQjZSOQzMqC8awbnp1JYFBI2PQoAfPVe2eXFT 8m9GQoK4v69Rl9bg/yxfcS369ZCZhkkAYodVYjukzJBlL6bvZ38Ni8fbrFv0zpdvjyXl ryJJN+nfCbKtgkZWz/q4BJ5/BBkFEb5ysqJDPoI6hq/RzTc+LVmOaS9HVdKwOomuIam9 tc5ZHVy0r0U9CsJYnZ9wjXWwa+j4uPnLpHlNZrvaalU+u8QwNqJmH9Cu8Bz9qBRmm4xF ubnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0rV7G1jD6xtbCSvVZH4i58ONvz7bS0QR7E+MhIBrRk4=; b=uSB6rej8bgvUY5y2WJlN6Mftjouu3xZ0R0hN94oPYz9WVu+wr3Km2auVALsmJNwXbd Ylrkwvq5pVt8kRM+xsDu/Eob5YhxgThy8mHNI9TVhrgFBzSco7oRng6jgW2owS0M8P94 HxcfWBKcY2x5rOmUPcyNNPzNkQk7hi7CI+p4RmOCRYBvPczg84dJCFpF/IXbf+XD4vPB RiTC3eE8d8Z/iw5mqKx1r+cAa1Sj+FP7jcdjuPmluzxg+sq1Rpk54fL9ZUrcvLTdndYF 5LfNNQemKrKZfyU+Iwxj7u8QqmJzYKXqtrcZdmIAGLuHNDmssrG4waL/KZRH5L2Khhha bcJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ac3m1iac; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q21si11398131edt.445.2021.03.10.05.30.14; Wed, 10 Mar 2021 05:30:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ac3m1iac; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233989AbhCJN3N (ORCPT + 99 others); Wed, 10 Mar 2021 08:29:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:46746 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233301AbhCJNZT (ORCPT ); Wed, 10 Mar 2021 08:25:19 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 34BB06500E; Wed, 10 Mar 2021 13:25:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615382719; bh=GTkDIsWZYLIlBE7QKAAma1929RS+G5varp3cUWHkM6g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ac3m1iacgKmZEeu5SCk+mD6Aw3JaKondljCvha+LH6hY0KNDVqFeNBarP/mqUJU9K nWnjbEb7vQr4h7Tsm8gx7KKZWLVhWUAdvhoo+AsBiiW9JgOUJof5NCmJZEQA6//UC/ x5Wb58rg+3WWAnUN3cVpokXa5iiAamf9H7oraRHI= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ira Weiny , David Sterba Subject: [PATCH 4.9 02/11] btrfs: fix raid6 qstripe kmap Date: Wed, 10 Mar 2021 14:25:01 +0100 Message-Id: <20210310132320.469905282@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210310132320.393957501@linuxfoundation.org> References: <20210310132320.393957501@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Ira Weiny commit d70cef0d46729808dc53f145372c02b145c92604 upstream. When a qstripe is required an extra page is allocated and mapped. There were 3 problems: 1) There is no corresponding call of kunmap() for the qstripe page. 2) There is no reason to map the qstripe page more than once if the number of bits set in rbio->dbitmap is greater than one. 3) There is no reason to map the parity page and unmap it each time through the loop. The page memory can continue to be reused with a single mapping on each iteration by raid6_call.gen_syndrome() without remapping. So map the page for the duration of the loop. Similarly, improve the algorithm by mapping the parity page just 1 time. Fixes: 5a6ac9eacb49 ("Btrfs, raid56: support parity scrub on raid56") CC: stable@vger.kernel.org # 4.4.x: c17af96554a8: btrfs: raid56: simplify tracking of Q stripe presence CC: stable@vger.kernel.org # 4.4.x Signed-off-by: Ira Weiny Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/raid56.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) --- a/fs/btrfs/raid56.c +++ b/fs/btrfs/raid56.c @@ -2341,16 +2341,21 @@ static noinline void finish_parity_scrub SetPageUptodate(p_page); if (has_qstripe) { + /* RAID6, allocate and map temp space for the Q stripe */ q_page = alloc_page(GFP_NOFS | __GFP_HIGHMEM); if (!q_page) { __free_page(p_page); goto cleanup; } SetPageUptodate(q_page); + pointers[rbio->real_stripes - 1] = kmap(q_page); } atomic_set(&rbio->error, 0); + /* Map the parity stripe just once */ + pointers[nr_data] = kmap(p_page); + for_each_set_bit(pagenr, rbio->dbitmap, rbio->stripe_npages) { struct page *p; void *parity; @@ -2360,16 +2365,8 @@ static noinline void finish_parity_scrub pointers[stripe] = kmap(p); } - /* then add the parity stripe */ - pointers[stripe++] = kmap(p_page); - if (has_qstripe) { - /* - * raid6, add the qstripe and call the - * library function to fill in our p/q - */ - pointers[stripe++] = kmap(q_page); - + /* RAID6, call the library function to fill in our P/Q */ raid6_call.gen_syndrome(rbio->real_stripes, PAGE_SIZE, pointers); } else { @@ -2390,12 +2387,14 @@ static noinline void finish_parity_scrub for (stripe = 0; stripe < nr_data; stripe++) kunmap(page_in_rbio(rbio, stripe, pagenr, 0)); - kunmap(p_page); } + kunmap(p_page); __free_page(p_page); - if (q_page) + if (q_page) { + kunmap(q_page); __free_page(q_page); + } writeback: /*