From patchwork Fri Oct 28 02:33:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 13022999 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 772C2FA373D for ; Fri, 28 Oct 2022 02:34:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236316AbiJ1CeW (ORCPT ); Thu, 27 Oct 2022 22:34:22 -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 Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-cifs@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; }