Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp790822rwe; Thu, 25 Aug 2022 09:08:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR5RmnoxxWyhrKiba8V0S4HGWBmobc+ZZgEwlPTReMJeIpNsDTobjzCF2Ez5WF+9ygL7IWWZ X-Received: by 2002:a05:6402:138b:b0:447:9f18:dbc5 with SMTP id b11-20020a056402138b00b004479f18dbc5mr3816312edv.113.1661443705948; Thu, 25 Aug 2022 09:08:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661443705; cv=none; d=google.com; s=arc-20160816; b=tzm1de6Io8TZW5So7CvM8Umg5+mlMvDTq5zRFsh5jIqAaNgB9Euuy+0IS1fDq+isXx Ux0dIUfPzTXWxbXfhTloFtz9MjS4F3Gw03mm722c3nnlpez5OYdR8rzA9tEvL+fSUzE+ lfWaJy15Kji51YHGj7NoxDvPpBwoMb1+fYI8PiJGUhJ24ns+RkodNpvBcijXXStTFlLw f515w7fNP0JbxzyUx7j2vcCpZMQIBt0CitWc++f4WhuzY4dkfEKXSCFzg9gMQzpSQkdG dMNHrpELxLVoHjmCaI480PPKOHiXDFzS3GrHGBu1chm/ij5Df77JS9XcIdkVAdN7xbej dRVA== 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=K5Jc8scvLUvhDTN44UnDRvk62eVtMjOsLaEb4UWxg7M=; b=sJaSijy9MAtEodURFMCBqxqxI6zVOH1BwgYAQLWOEyyVFKsHrOehhaMXw4hNVXzryG 6nGR2gSjxpVS8omMFkuBbsJO+3FKB6dRXXuFS9DD7YvOLHJuOI1uLHvz0MM/FQTHpBUE 2AOvb92R+05uSUln6sD3TAFOOeCcbJD0BZTfZ2yzfaqzuTr55hAP3zcxjX9Ji+g448tA YVxQeKl/NG/lk85a13np49nZp1yjiVN5Je1oS6GTKVfWn/bRjtQ7Dn/FK61t/n5XoCQa pRGzuSuq+ctoyWighlkdSV/T3K7slwgpYcBmDOwQhoLiBM1wHpdJwL3sSRV99W342Q/2 pxbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b="TAse/YlG"; 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 qf22-20020a1709077f1600b0072b53e673bbsi3675395ejc.913.2022.08.25.09.07.58; Thu, 25 Aug 2022 09:08:25 -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="TAse/YlG"; 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 S241961AbiHYPZd (ORCPT + 99 others); Thu, 25 Aug 2022 11:25:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241995AbiHYPYp (ORCPT ); Thu, 25 Aug 2022 11:24:45 -0400 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53F5DB99E1; Thu, 25 Aug 2022 08:24:42 -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=K5Jc8scvLUvhDTN44UnDRvk62eVtMjOsLaEb4UWxg7M=; b=TAse/YlGEzCihIsPGWyu6RMzTu yVK3Z1T9yYnlVtvmVzsxxqVjBgdqX7sn3+vugZG+YautHnMksjYjBxO4uRGs2yNGc5Zd70AHnj/8t OKgc66oyUrOurIsgqvHKdljgGD8qK7+t6en6l3GHHZ72iJvO63y0vSn64Yj1tDJxqglXS2TuNjpOC 5DDMrI6DkZCYkhfmF6vz1VZopGSU1I5Hl3KwpXsNddsfPYhPRCJsXyvh3WFofP9kODtJTQslzXHFP di3HWbMlwtbBe5NGrNBDOqE53/6YQC7Q13W2bgh1/aEpIKI05z9wd8VybMTyt/0ZG+4gsxawAYGoa 098afT0Q==; 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 1oREij-0086MB-QX; Thu, 25 Aug 2022 09:24:39 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1oREie-0001ec-8l; Thu, 25 Aug 2022 09:24:32 -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, 25 Aug 2022 09:24:20 -0600 Message-Id: <20220825152425.6296-4-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220825152425.6296-1-logang@deltatee.com> References: <20220825152425.6296-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, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH v9 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 --- 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