Message ID | 20230913201248.452081-5-zi.yan@sent.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp89238vqi; Wed, 13 Sep 2023 20:44:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4z2v/pQYU5V3jIlnWLSnop9xx/abmflvhcg7fmcYwyLR1j5HcCS1IrVLLV/fzslng8sf5 X-Received: by 2002:a05:6358:8829:b0:13a:d269:bd23 with SMTP id hv41-20020a056358882900b0013ad269bd23mr5196045rwb.16.1694663061008; Wed, 13 Sep 2023 20:44:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694663060; cv=none; d=google.com; s=arc-20160816; b=p0ZAO7ChE7q2zcb28kB9x2I7+AOK3Obn2cLrgngxf4y8qVbaIOYbfg2XPPCeebKBsu khZEQr5SjVx+GPBiwxoSDHKXzWjQVqzwloD41SNOfHjEQCbfD5sCE3DSR8kxNGlNzVW6 whYqe+u0dT1Bdj28dkdrv+eUWxB/MM9eV5OF1DTVVqqqLCC6oxyccvhHIV5oezuvGJtr rTsHgt9zz/plYYzbSdIQHiMhT2TAxoxE5VywZdjYnO74WKx3QoccZk3hKLn6ZmJ13XTl 4/cgBZnCLOWzd0DVNesjoUUJFG9UqTUrQhmKjteLOeFEXMN+ibpTrTP6Fuly8dFmsY/e fE5Q== 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:reply-to :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=l4bevEHulLiJ5YHyw6Y9teMcyGqHbAaeFHUaV/6ZIds=; fh=uXOOnG6dSiAFwWm6vSsvJiwW7q8GOjY1G0eNovT28gQ=; b=i6ELG/YzF9C+2Rz+nXtiWelJm5yiGkIhqu9l6plxBMRnU9R/HmEdQx0gw6VfuzZm81 JBV0gRgB+MBMqIIS6QTu0wN80LiDUm4bjTN63UwAcG65cytt3wWtK81x0HrBDYZy15hf TvKjRdMMIu08Jfifk9HCgUC6eJKo5F1Zsw2ltm4rcrNJBO5nLCpVvAK0+0aPozIEBWPP j3sVoFOpyhfhHmDKQZd9gGldmsNC6IehfuT4du6G2CX5rara6ON2RnGJpGR2M7Xs/pzp LHeIz1LewwjluT2DWmTDypEL0HmJm+1aJ65GkAvS3qOA3ul2g/HnNJ8nxApBO4KUBohM njRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sent.com header.s=fm2 header.b=H+ayEHKc; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=YgxV1M8o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id l69-20020a638848000000b00565f37c5472si572754pgd.781.2023.09.13.20.44.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 20:44:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@sent.com header.s=fm2 header.b=H+ayEHKc; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=YgxV1M8o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 4C46B821579F; Wed, 13 Sep 2023 13:13:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232679AbjIMUNe (ORCPT <rfc822;pwkd43@gmail.com> + 34 others); Wed, 13 Sep 2023 16:13:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232203AbjIMUNa (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 13 Sep 2023 16:13:30 -0400 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 364A71BEF; Wed, 13 Sep 2023 13:13:23 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id A1BC43200495; Wed, 13 Sep 2023 16:13:21 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Wed, 13 Sep 2023 16:13:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:reply-to:sender:subject:subject:to:to; s=fm2; t= 1694636001; x=1694722401; bh=l4bevEHulLiJ5YHyw6Y9teMcyGqHbAaeFHU aV/6ZIds=; b=H+ayEHKc5Yx5k+Dpc1wOOB1Y3ycugVwzEwwHd91K9eeo6tz2GMZ o33ft/YdfjMmTvM8YBdqDgvvVlPdq3S4OIgTsrSpnDohjyqct1/YmeU4yDSoy02A tPkjTNDVL6a3mQ19/TUut7cl2giLJq98zopfOqmR9d5eBAsXnIRLasFx428VGFiu RQ4oK4Cyz/3A0XTw/dvzJhkEmWaycHldo+LMf0LcfpAkV/vIuvL8lxrND9KvTeS6 WYC70OuysEGIDRBToO65ln/Cyo7B5Agdp1LtNShS4+BJS+TtX2pkZvvLBq0eAXLl WJdnEZZWQDha8YWY4EJ+ifRxu/i1o6HoQ/Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1694636001; x=1694722401; bh=l4bevEHulLiJ5YHyw6Y9teMcyGqHbAaeFHU aV/6ZIds=; b=YgxV1M8oM33Puqg8fj6ipfY4rlBIRJuVZuMSIN9kxRevCGOpP+W aoW2pFq0J91Gro+JxjekWxs09v8kElVXgHstaNMEONK6uRSBBPu212JouOcLr3N4 7BuiAMO58woKwmVen+hAOQPd7KNStogYTQUHa5rXDK87CGePkfSRCmGi4XBOPOGh Pl3oMdD2LGDUWDzIkx6b+ke06EPe5+IIWzBnIkvY/jUhaCJHSpNF9RDq9nJBrl8D gmyNu+EwD1DbYD3/m92dw3hbK52VLvp09SkNBa1GJD7x/ESvHPZzgFGjEqUIdNTu fY3/9QQCffj6h8vIDhr2sSZOyjVGtF5ddgQ== X-ME-Sender: <xms:4RcCZcphjoqBBov82s36srRr93mxMlEdks-Rg-Vwhzi4zQIegLjHNQ> <xme:4RcCZSo7qYRMKKrWV_YSzcAb4aiaG7L_UVBr0E-gHmpECTNioY9We3Cb9eblQ-tzG TuL29zVs3CyfIjb8Q> X-ME-Received: <xmr:4RcCZRNFTnV80jEs9Fi4EAN_9XVHaw-g37aEGnQarQDDRT_6MhwN2AOp5vmF1BUiX-NlNVwZw-UTFdABxcevjHdLAWjiPVGDM8G9cR1gmCEMBdGiP2s_xloy> X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudeikedgudegiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enogfuohhrthgvugftvggtihhpvdculdegtddmnecujfgurhephffvvefufffkofgjfhhr ggfgsedtqhertdertddtnecuhfhrohhmpegkihcujggrnhcuoeiiihdrhigrnhesshgvnh htrdgtohhmqeenucggtffrrghtthgvrhhnpeeggeehudfgudduvdelheehteegledtteei veeuhfffveekhfevueefieeijeegvdenucevlhhushhtvghrufhiiigvpedunecurfgrrh grmhepmhgrihhlfhhrohhmpeiiihdrhigrnhesshgvnhhtrdgtohhm X-ME-Proxy: <xmx:4RcCZT7nybB_IOhWkP7Dtm99zPXUwCAjiPydEHo7bV03IUmpdmvzJw> <xmx:4RcCZb7tJNmuN71SdxBonujl-2IaWrdG_D41pDnUdiw99N95mbC1Cg> <xmx:4RcCZTiKYBKtqmeTp7LHPg_GLFVn2UtgGQrYed2feLme2CkA20eEhQ> <xmx:4RcCZfiajUv-lJnY_64MCRZHZ0pclmjCH_0J5yahjePmMIslSox1qw> Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 13 Sep 2023 16:13:20 -0400 (EDT) From: Zi Yan <zi.yan@sent.com> To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org Cc: Zi Yan <ziy@nvidia.com>, Andrew Morton <akpm@linux-foundation.org>, Thomas Bogendoerfer <tsbogend@alpha.franken.de>, "Matthew Wilcox (Oracle)" <willy@infradead.org>, David Hildenbrand <david@redhat.com>, Mike Kravetz <mike.kravetz@oracle.com>, Muchun Song <muchun.song@linux.dev>, "Mike Rapoport (IBM)" <rppt@kernel.org>, stable@vger.kernel.org, Muchun Song <songmuchun@bytedance.com> Subject: [PATCH v3 4/5] fs: use nth_page() in place of direct struct page manipulation. Date: Wed, 13 Sep 2023 16:12:47 -0400 Message-Id: <20230913201248.452081-5-zi.yan@sent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230913201248.452081-1-zi.yan@sent.com> References: <20230913201248.452081-1-zi.yan@sent.com> Reply-To: Zi Yan <ziy@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 13 Sep 2023 13:13:49 -0700 (PDT) X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776983013418768971 X-GMAIL-MSGID: 1776983013418768971 |
Series |
Use nth_page() in place of direct struct page manipulation
|
|
Commit Message
Zi Yan
Sept. 13, 2023, 8:12 p.m. UTC
From: Zi Yan <ziy@nvidia.com> When dealing with hugetlb pages, struct page is not guaranteed to be contiguous on SPARSEMEM without VMEMMAP. Use nth_page() to handle it properly. Fixes: 38c1ddbde6c6 ("hugetlbfs: improve read HWPOISON hugepage") Cc: <stable@vger.kernel.org> Signed-off-by: Zi Yan <ziy@nvidia.com> Reviewed-by: Muchun Song <songmuchun@bytedance.com> --- fs/hugetlbfs/inode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Comments
On 13 Sep 2023, at 16:12, Zi Yan wrote: > From: Zi Yan <ziy@nvidia.com> > > When dealing with hugetlb pages, struct page is not guaranteed to be > contiguous on SPARSEMEM without VMEMMAP. Use nth_page() to handle it > properly. > > Fixes: 38c1ddbde6c6 ("hugetlbfs: improve read HWPOISON hugepage") > Cc: <stable@vger.kernel.org> > Signed-off-by: Zi Yan <ziy@nvidia.com> > Reviewed-by: Muchun Song <songmuchun@bytedance.com> > --- > fs/hugetlbfs/inode.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c > index 7083fa0caaab..14d3d28e41b0 100644 > --- a/fs/hugetlbfs/inode.c > +++ b/fs/hugetlbfs/inode.c > @@ -295,7 +295,7 @@ static size_t adjust_range_hwpoison(struct page *page, size_t offset, size_t byt > size_t res = 0; > > /* First subpage to start the loop. */ > - page += offset / PAGE_SIZE; > + page = nth_page(page, offset / PAGE_SIZE); > offset %= PAGE_SIZE; > while (1) { > if (is_raw_hwpoison_page_in_hugepage(page)) > @@ -309,7 +309,7 @@ static size_t adjust_range_hwpoison(struct page *page, size_t offset, size_t byt > break; > offset += n; > if (offset == PAGE_SIZE) { > - page++; > + page = nth_page(page, 1); > offset = 0; > } > } > -- > 2.40.1 Without the fix, a wrong subpage might be checked for HWPoison, causing wrong number of bytes of a page copied to user space. No bug is reported. The fix comes from code inspection. -- Best Regards, Yan, Zi
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 7083fa0caaab..14d3d28e41b0 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -295,7 +295,7 @@ static size_t adjust_range_hwpoison(struct page *page, size_t offset, size_t byt size_t res = 0; /* First subpage to start the loop. */ - page += offset / PAGE_SIZE; + page = nth_page(page, offset / PAGE_SIZE); offset %= PAGE_SIZE; while (1) { if (is_raw_hwpoison_page_in_hugepage(page)) @@ -309,7 +309,7 @@ static size_t adjust_range_hwpoison(struct page *page, size_t offset, size_t byt break; offset += n; if (offset == PAGE_SIZE) { - page++; + page = nth_page(page, 1); offset = 0; } }