Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1112298rwb; Thu, 22 Sep 2022 10:13:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5bO75Dd6IMY8jnSHdxThXrrUkxgxK4Iwjk4JM2Tohywj9IbdrMPs9AjGnuf1dlTKOf/7v9 X-Received: by 2002:a17:902:e5c1:b0:176:c2b3:6a4c with SMTP id u1-20020a170902e5c100b00176c2b36a4cmr4359822plf.87.1663866809178; Thu, 22 Sep 2022 10:13:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663866809; cv=none; d=google.com; s=arc-20160816; b=yJEWeKEsYFlUHSNHN8sFotfLS+mDjm/wJ0+ccu8ubSsBK/ccv13quqa5QwYb1Hrpue LK1bbHNb5UPz9uKN8FnUq2AlRFfrczMwF1+iW9ENUrC3LiHtrbELUAbv6PrV3vnsUMJk kNhOSw9NNh6e+jPlCmt2fvGQc9QPQn/dF2c4sakzc10Jl8y69ULSI7ex9HJeGFnuZsNi aTLVM7KAbivgxNKFoLQCO9LSvQKTIUk4LdQPAkyfeIrvA01ZMgrXGtpmfvbtvFC5r3/e E/UV6DKHr3Y/XCZ4JWXsjPx+4WTKTUE8JqtNQD2W3khe44HbqS94nKh48hLtmX/2IPuF XAHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=55w4V1w11q9zjvxXiqXDCItXvw7MgUl3ug3CrLLmnIw=; b=jfy0FMkiWyMPJhynTs9NXA6ActJoDjJjosCwLUSXWq+qX58ZpPekQsvIJhCWQIJDRs L0nj1X5FMJZqGfjrtxBHsqIMthfLF88mI5AL/p2cHdpE4vmIhV2gGN9+gUE/r7c4L3E2 w4TmjQCk+0W2W2Mi7Gc4vTtHTruJCBALBja7bWfss0VSi3MOsJ75xW9jHMizDjv4tqJv QMJh8EIpPbYGo//nBSwJ1o8OvX1O3I/V46GonzUSIr4NfjpUuQFBn88R1T8/hMOyHuWA vIQKoWkogbcDYP70ey0cu7ldrNnGzVLQPGMU5TOkuI9DTiJEAT6l7jmqCRUC9CbwjlBT FYQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b="OZN/AZUO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deltatee.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u16-20020a170902e5d000b00176c0e055d8si382815plf.102.2022.09.22.10.13.17; Thu, 22 Sep 2022 10:13:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b="OZN/AZUO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deltatee.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232066AbiIVQju (ORCPT + 99 others); Thu, 22 Sep 2022 12:39:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231608AbiIVQjo (ORCPT ); Thu, 22 Sep 2022 12:39:44 -0400 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C243F491FF; Thu, 22 Sep 2022 09:39:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:MIME-Version:References:In-Reply-To: Message-Id:Date:Cc:To:From:content-disposition; bh=55w4V1w11q9zjvxXiqXDCItXvw7MgUl3ug3CrLLmnIw=; b=OZN/AZUOfIgfOjP6ooObX1mD/z 0C6aPsUozqfInf00hOtNduDUliCS3P28Y3+gALxitullhCJGm2V3yuSFm/F5CNVrTdv0i+SOzb80R AShkraGn1LBqr6dGuFHxp/2RsA3aKj+Rrm2OM05egSqxplGXEPbvgy06OBm93U2eXw2bn1yL7yjv7 9REh05flbq5LZLN0J2me10EK8R4FTm+m1wh4UX23047qMkC7DrAeGQcTiYNkHxoXfuCz1GBhNif5m JJwGas6Cur79OhPuKLfOLiLK6+Ll+tbqsZzcLGHqQ40dvAi4xLr1CpxSeX8u08w+zwfmQ3jBIT7X+ fXWDB7Cg==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1obPEf-00862d-HN; Thu, 22 Sep 2022 10:39:39 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1obPEb-0001rp-6K; Thu, 22 Sep 2022 10:39:33 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-block@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org Cc: Christoph Hellwig , Greg Kroah-Hartman , Dan Williams , Jason Gunthorpe , =?UTF-8?q?Christian=20K=C3=B6nig?= , John Hubbard , Don Dutile , Matthew Wilcox , Daniel Vetter , Minturn Dave B , Jason Ekstrand , Dave Hansen , Xiong Jianxin , Bjorn Helgaas , Ira Weiny , Robin Murphy , Martin Oliveira , Chaitanya Kulkarni , Ralph Campbell , Stephen Bates , Logan Gunthorpe Date: Thu, 22 Sep 2022 10:39:21 -0600 Message-Id: <20220922163926.7077-4-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220922163926.7077-1-logang@deltatee.com> References: <20220922163926.7077-1-logang@deltatee.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, hch@lst.de, gregkh@linuxfoundation.org, jgg@ziepe.ca, christian.koenig@amd.com, ddutile@redhat.com, willy@infradead.org, daniel.vetter@ffwll.ch, jason@jlekstrand.net, dave.hansen@linux.intel.com, helgaas@kernel.org, dan.j.williams@intel.com, dave.b.minturn@intel.com, jianxin.xiong@intel.com, ira.weiny@intel.com, robin.murphy@arm.com, martin.oliveira@eideticom.com, ckulkarnilinux@gmail.com, jhubbard@nvidia.com, rcampbell@nvidia.com, sbates@raithlin.com, logang@deltatee.com X-SA-Exim-Mail-From: gunthorp@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH v10 3/8] block: add check when merging zone device pages X-SA-Exim-Version: 4.2.1 (built Sat, 13 Feb 2021 17:57:42 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Consecutive zone device pages should not be merged into the same sgl or bvec segment with other types of pages or if they belong to different pgmaps. Otherwise getting the pgmap of a given segment is not possible without scanning the entire segment. This helper returns true either if both pages are not zone device pages or both pages are zone device pages with the same pgmap. Add a helper to determine if zone device pages are mergeable and use this helper in page_is_mergeable(). Signed-off-by: Logan Gunthorpe Reviewed-by: Christoph Hellwig Reviewed-by: John Hubbard --- block/bio.c | 2 ++ include/linux/mmzone.h | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/block/bio.c b/block/bio.c index 3d3a2678fea2..969607bc1f4d 100644 --- a/block/bio.c +++ b/block/bio.c @@ -865,6 +865,8 @@ static inline bool page_is_mergeable(const struct bio_vec *bv, return false; if (xen_domain() && !xen_biovec_phys_mergeable(bv, page)) return false; + if (!zone_device_pages_have_same_pgmap(bv->bv_page, page)) + return false; *same_page = ((vec_end_addr & PAGE_MASK) == page_addr); if (*same_page) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index e24b40c52468..2c31915b057e 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -794,6 +794,25 @@ static inline bool is_zone_device_page(const struct page *page) { return page_zonenum(page) == ZONE_DEVICE; } + +/* + * Consecutive zone device pages should not be merged into the same sgl + * or bvec segment with other types of pages or if they belong to different + * pgmaps. Otherwise getting the pgmap of a given segment is not possible + * without scanning the entire segment. This helper returns true either if + * both pages are not zone device pages or both pages are zone device pages + * with the same pgmap. + */ +static inline bool zone_device_pages_have_same_pgmap(const struct page *a, + const struct page *b) +{ + if (is_zone_device_page(a) != is_zone_device_page(b)) + return false; + if (!is_zone_device_page(a)) + return true; + return a->pgmap == b->pgmap; +} + extern void memmap_init_zone_device(struct zone *, unsigned long, unsigned long, struct dev_pagemap *); #else @@ -801,6 +820,11 @@ static inline bool is_zone_device_page(const struct page *page) { return false; } +static inline bool zone_device_pages_have_same_pgmap(const struct page *a, + const struct page *b) +{ + return true; +} #endif static inline bool folio_is_zone_device(const struct folio *folio) -- 2.30.2