Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1673320rwi; Thu, 27 Oct 2022 19:58:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4kzz9qFok8xUdeqx9atdCApp26k5B80b0lBn6HWJDw1S8cYy1PuKvIbvNAQvtty9ODas79 X-Received: by 2002:a63:ed0e:0:b0:457:4a30:cb8c with SMTP id d14-20020a63ed0e000000b004574a30cb8cmr43878623pgi.161.1666925888999; Thu, 27 Oct 2022 19:58:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666925888; cv=none; d=google.com; s=arc-20160816; b=Pzpre8eCQI5P3l5oXP5stVeZ002oYdhEhZlPiY1RfpQ08/wrPgD6AKvTIJGraZ8MNH dY86aGhbX7jS5A2TY41Kjlduzs7ipgGMCPutmSEMridUylP2q0pkOTF0Hf5iEtf4ceuD hC0g6ojRhJaTd3gf17tG25tv/SX7EejHckMU7uQLJGDZwQD8TYjozoPaEdLegcsbpkes 2Hl2LPZBOopVAtMRmPaQIXb4EbHyr/k2SJZmhfqL5/nZCdAg/SkZZA0ULaiXdXpQjXcQ 4SY3XTO6n3sJ1+PP595yQXB+bBlzJz/mSzgGdnbokzwbuZWDAiWeYIDVXzcqw+wmMJ2h wMCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fVteMAVIVg+91bTuLaocFDEKI259Dr9+CPyGCGwShcc=; b=fPT48fuAlItIXUopS6QIabiOfpZLPPGsVmIAseTggXR3wfsIP2HrAd8VlPENgMRE2d sU0VKxQPJAhDx1btjqklDF4tVfL3pTc0WUIAb9DPX+1uhBU7wvuCvNRO/Rfpq9FAlhpi bhbFSxYLBu7KFJftx14qC8SEGIcy8daOuJ9Y2x0QYajRh1B+p/rIE/wHGUA0BYPAJNHQ QIaUTma5SFyslhpISw2lHLWka2Hj1U7pgPHm0giTCO/eQ5zj0CMM1LcSfbjveqpu4QNg 2uk0Jid9GyEbxay73s7qTToXdh7fAyZJ6Rqq+bb63/2W3KhsAzm8uCh7GSMmNYjMqu28 sWmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b="ijcu/m4X"; 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=zeniv.linux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g1-20020a170902c38100b001729cfb3cb5si3295117plg.610.2022.10.27.19.57.54; Thu, 27 Oct 2022 19:58:08 -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=@linux.org.uk header.s=zeniv-20220401 header.b="ijcu/m4X"; 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=zeniv.linux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236292AbiJ1Ce5 (ORCPT + 99 others); Thu, 27 Oct 2022 22:34:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236198AbiJ1CeP (ORCPT ); Thu, 27 Oct 2022 22:34:15 -0400 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5687BE2F5; Thu, 27 Oct 2022 19:34:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=fVteMAVIVg+91bTuLaocFDEKI259Dr9+CPyGCGwShcc=; b=ijcu/m4XkLYK3DKlJDahWgJHiW mu7ewOaipKjhqe8VSwqNcZrMyfILUJsa2yaMpnmbZVxHA5i3JWu6p/V0JfsAfj48zCsFoHd3YLmOt W01JhZsZst4iSFEpppNf0MEqyWOTaXTYlGSc3NLkewsdvMRN00foyNDwR016b8PpHvZo/LKktG6ty MXuZ13R+s+K9VtWA2tvb7xaYR/SlUqxnGEQKVOT6YaVhxbYNRWPcd1wpEdp+lzWrFjBgwtVu+3LUS fP6w3UjjniYWMPy29/vK7NAp1gDNZyW3VKJITWWsNvR+1mP8W70AvsKCFX+mWhOMS3BghRETljTH7 Dq1sletg==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1ooFBw-00Eor9-0O; Fri, 28 Oct 2022 02:33:52 +0000 From: Al Viro To: Christoph Hellwig Cc: David Howells , willy@infradead.org, dchinner@redhat.com, Steve French , Shyam Prasad N , Rohith Surabattula , Jeff Layton , Ira Weiny , torvalds@linux-foundation.org, linux-cifs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 01/12] get rid of unlikely() on page_copy_sane() calls Date: Fri, 28 Oct 2022 03:33:41 +0100 Message-Id: <20221028023352.3532080-1-viro@zeniv.linux.org.uk> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Al Viro X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Al Viro --- lib/iov_iter.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index c3ca28ca68a6..e9a8fc9ee8ee 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -703,17 +703,16 @@ static inline bool page_copy_sane(struct page *page, size_t offset, size_t n) head = compound_head(page); v += (page - head) << PAGE_SHIFT; - if (likely(n <= v && v <= (page_size(head)))) - return true; - WARN_ON(1); - return false; + if (WARN_ON(n > v || v > page_size(head))) + return false; + return true; } size_t copy_page_to_iter(struct page *page, size_t offset, size_t bytes, struct iov_iter *i) { size_t res = 0; - if (unlikely(!page_copy_sane(page, offset, bytes))) + if (!page_copy_sane(page, offset, bytes)) return 0; if (unlikely(iov_iter_is_pipe(i))) return copy_page_to_iter_pipe(page, offset, bytes, i); @@ -808,7 +807,7 @@ size_t copy_page_from_iter_atomic(struct page *page, unsigned offset, size_t byt struct iov_iter *i) { char *kaddr = kmap_atomic(page), *p = kaddr + offset; - if (unlikely(!page_copy_sane(page, offset, bytes))) { + if (!page_copy_sane(page, offset, bytes)) { kunmap_atomic(kaddr); return 0; } -- 2.30.2