Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3196235pxj; Mon, 7 Jun 2021 04:59:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhmjceUBgGw8CmmAZ3cqXISocxx4izDjBy4z11AlD+eKP+kQ7gDg1vml1IErBnT7kyrgL3 X-Received: by 2002:a17:906:4c5a:: with SMTP id d26mr17778102ejw.509.1623067164274; Mon, 07 Jun 2021 04:59:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623067164; cv=none; d=google.com; s=arc-20160816; b=ZPCRtUTu3sOGUIg+R+BdWSKA8JqCE+rlDkiive/C/Mamk2FlUawicY99MXnM4Y8qXM Ajz4Qmj48llM4u8PqmyGkanL61N9HeMvltMn0TioQ8lTGcUgvtiQYRIp2EfyHYXRGT8b iDBLh4UTvQGvr+pSEuQupXj2q1UztZiStHqulaSMM84ibFu1kuQPIKnjrUn1OCZfCySG L9wxtzKCGjZmWmCHSBvs8laSDobOO2seAoO7oheHwXMvDGgi4Ac+RP3BCNbk8V09uukq CTQ074BaPTei8Z42FfFpc9nZHL4GGUqmc2RADLKgVqAkipjzrD+ImXR3E4ywzNfigJkt F/cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature:dkim-signature:dkim-signature :dkim-signature; bh=BqFN536PDnP3Zynyosw+raEhWyH991Zb94ulbNCCUPI=; b=tOtpatkEg9Yk8DnOQyDMeLpaf6gWPwuq97Ixk8enJBShBA2ZdCKp+/1RkmrrF835j3 2j2IOB6Wd9m40PiqRT+6/3VQQbR1DkG3yjdwtkkZplhTQUw7JU90Rn0N7rwiilvDdA6k +NrgUSpHm3TacFMCYTnhxzTbayL/ZwmPVoUaiA9YKsmWKC5u362UPko7OO8JILHnHy6/ Z4isVdwPyNEbtkS11kDJYqtX71Q7P6sa5BavdsveOdZQEJ3AMRf1gUZlnWlb2wgTh0lS r89bVwajZ/jErOZE+VNis7H7HgBrjSNJbZqOPoP3ATGot5tghBgWfElOSe+Tl7lX33hb M1QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=TfZh0rTw; dkim=neutral (no key) header.i=@suse.de; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=TfZh0rTw; dkim=neutral (no key) header.i=@suse.de; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hc43si15224014ejc.513.2021.06.07.04.59.01; Mon, 07 Jun 2021 04:59:24 -0700 (PDT) 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=@suse.de header.s=susede2_rsa header.b=TfZh0rTw; dkim=neutral (no key) header.i=@suse.de; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=TfZh0rTw; dkim=neutral (no key) header.i=@suse.de; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230269AbhFGL5X (ORCPT + 99 others); Mon, 7 Jun 2021 07:57:23 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:56274 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230193AbhFGL5W (ORCPT ); Mon, 7 Jun 2021 07:57:22 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 79F211FDC5; Mon, 7 Jun 2021 11:55:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623066930; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BqFN536PDnP3Zynyosw+raEhWyH991Zb94ulbNCCUPI=; b=TfZh0rTwQFOmv60JXi81ZTOEXzkiIC1f08hfqAXbhh1wptG/d6HMQAUAD/Ryh4w+KpVOtG hyb6wjs/6d5YEPr+tMVAUkxW/quPnjDnt2acUPxKG6rE6C3mKgqqGIbffeukTGRxf6/CDO 5nfRX0xDEGrLF1VnvcCW5Il7ybSn7sk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623066930; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BqFN536PDnP3Zynyosw+raEhWyH991Zb94ulbNCCUPI=; b=hJe2nXU8SuQLJ2QccHgBR3B8xjhz/y+SDzvWX2OFp2igGZoqWQXShRhJ6YJzTIA7AnuqH4 d/LwCpFdA+dK72BA== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 1CD94118DD; Mon, 7 Jun 2021 11:55:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1623066930; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BqFN536PDnP3Zynyosw+raEhWyH991Zb94ulbNCCUPI=; b=TfZh0rTwQFOmv60JXi81ZTOEXzkiIC1f08hfqAXbhh1wptG/d6HMQAUAD/Ryh4w+KpVOtG hyb6wjs/6d5YEPr+tMVAUkxW/quPnjDnt2acUPxKG6rE6C3mKgqqGIbffeukTGRxf6/CDO 5nfRX0xDEGrLF1VnvcCW5Il7ybSn7sk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1623066930; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BqFN536PDnP3Zynyosw+raEhWyH991Zb94ulbNCCUPI=; b=hJe2nXU8SuQLJ2QccHgBR3B8xjhz/y+SDzvWX2OFp2igGZoqWQXShRhJ6YJzTIA7AnuqH4 d/LwCpFdA+dK72BA== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id hgKGNSwJvmCYaAAALh3uQQ (envelope-from ); Mon, 07 Jun 2021 11:55:24 +0000 Subject: Re: [PATCH v5 2/2] bcache: avoid oversized read request in cache missing code path To: Christoph Hellwig Cc: axboe@kernel.dk, linux-bcache@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Alexander Ullrich , Diego Ercolani , Jan Szubiak , Marco Rebhan , Matthias Ferdinand , Victor Westerhuis , Vojtech Pavlik , Rolf Fokkens , Thorsten Knabe , stable@vger.kernel.org, Kent Overstreet , Nix , Takashi Iwai References: <20210607103539.12823-1-colyli@suse.de> <20210607103539.12823-3-colyli@suse.de> <20210607110657.GB6729@lst.de> From: Coly Li Message-ID: <6d08d23b-b778-4e5f-a5f3-7106a42e26a1@suse.de> Date: Mon, 7 Jun 2021 19:55:22 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210607110657.GB6729@lst.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/7/21 7:06 PM, Christoph Hellwig wrote: > On Mon, Jun 07, 2021 at 06:35:39PM +0800, Coly Li wrote: >> + /* Limitation for valid replace key size and cache_bio bvecs number */ >> + size_limit = min_t(unsigned int, bio_max_segs(UINT_MAX) * PAGE_SECTORS, >> + (1 << KEY_SIZE_BITS) - 1); > bio_max_segs kaps the argument to BIO_MAX_VECS, so you might as well It was suggested to not directly access BIO_MAX_VECS by you, maybe I misunderstood you. > directly write BIO_MAX_VECS. Can you explain the PAGE_SECTORS here a bit > more? Does this code path use discontiguous per-sector allocations? > Preferably in a comment. It is just because bch_bio_map() assume the maximum bio size is 1MB. It was not true since the multiple pages bvecs was merged in mainline kernel.   The PAGE_SECTORS part is legacy for 1MB maximum size bio (256*4KB), it should be fixed/improved later to use multiple pages for bio size > 1MB and replace bch_bio_map(). >> + s->insert_bio_sectors = min3(size_limit, sectors, bio_sectors(bio)); > Also I don't really understand the units involved here. > s->insert_bio_sectors, sectors, and bio_sectors is in unit of 512 byte > sectors. Yes, they are in sectors, this is the maximum permitted bio size for 1MB bio size. Now we can have bio > 1MB, and you modify bio_alloc_bioset() parameter 'nr_iovecs from unsigned int to unsigned short, so bio-size/page-size can be > 256 and overflow, e.g. 258 overflows to 2, then the BUG in biovec_slab() is triggered. I feel this is a long time existing issue in bcache code, and should be fixed from bcache side, and your change helps to trigger the problem explicitly. >> - miss = bio_next_split(bio, sectors, GFP_NOIO, &s->d->bio_split); >> + miss = bio_next_split(bio, s->insert_bio_sectors, GFP_NOIO, &s->d->bio_split); > Overly long line. Not any more. Now the line limit is 100 characters. Though I still prefer 80 characters, place 86 characters in single line makes the change more obvious. Thanks. Coly Li