From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8EF0C54EAA for ; Fri, 27 Jan 2023 02:04:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 26F286B0072; Thu, 26 Jan 2023 21:04:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 21F7D6B0074; Thu, 26 Jan 2023 21:04:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E7388E0001; Thu, 26 Jan 2023 21:04:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id F0F9B6B0072 for ; Thu, 26 Jan 2023 21:04:37 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C256DAB5FC for ; Fri, 27 Jan 2023 02:04:37 +0000 (UTC) X-FDA: 80398934994.12.21D61F1 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf15.hostedemail.com (Postfix) with ESMTP id 34E90A000E for ; Fri, 27 Jan 2023 02:04:34 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=ZubqXbAX; spf=none (imf15.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674785076; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CCo6CcOIMdKlo3WLVq6nzoGfLepaU37Js9DWTNsO9Fw=; b=3Avziztyqhj91RBvlvd8cHZKNnWP6g68HfdIlshJkzD27azDqeDPlEopM0j4OlJ2Vv/fmf +4n0DgUf76nO/Jcu1Iqoand6RYfvU0e/eQf33XWwaSqnzzT3sBDaoA+NYxECi4+11F0E38 PVvItxLeTzJnsB8wYqgOA5u/VxoL+jo= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=ZubqXbAX; spf=none (imf15.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674785076; a=rsa-sha256; cv=none; b=FxpSINlzYCHQLP3vpTJ/Sp/4mK0aVwC+tZZH/IN2vGlH9gkFnnBUJN41D9ag6c60Hcfazh TA616RRYIN7P7831C0qtFE0OVULNlSOAwp8XNe9Yd1Tt/feA7Ji+qKx6EDNQthLcwRhUZA bf1/91KaqanQQJ+HYTODyRvYB2/iWz0= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=CCo6CcOIMdKlo3WLVq6nzoGfLepaU37Js9DWTNsO9Fw=; b=ZubqXbAX/iWh0ihOuMt9SDBHj2 Pv4qOw9MHHh4xzYaqfKBBNsurvccE3kkKwwOPI4z/MmIuuhmfA9dL6LOSn2+VelWUoLq2PtvTPOI8 I3v2bV6rP0Iqcb87QiPCDj4v1qfF6PrAfsTtV3qjDF9hpgOuF46hafn6pPSY2OzHhePBfUeRPeh38 s0G09tEnelzytxV/uFfpJLq8isoxMbA4aJdJXXYipw9pN1JiJ/EU0GSkQUlU7/5r+FlOYMJ2rNSY7 1v1O52xCcVoUIagGOnBs4q6+18YPV3aGran5zy2UdX/mabd062q1qfStpID6GgRAGwBCRkcNBBYgJ CyORKCgg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLE6L-007H43-Fl; Fri, 27 Jan 2023 02:04:25 +0000 Date: Fri, 27 Jan 2023 02:04:25 +0000 From: Matthew Wilcox To: Andrew Morton Cc: "Fabio M. De Francesco" , Ira Weiny , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH] mm: Add memcpy_from_file_folio() Message-ID: References: <20230126201552.1681588-1-willy@infradead.org> <20230126154152.898a1bdfd7d729627e2a6bf4@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230126154152.898a1bdfd7d729627e2a6bf4@linux-foundation.org> X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 7uu5n465mxusryhpnts4kxbpw3a3bruq X-Rspamd-Queue-Id: 34E90A000E X-HE-Tag: 1674785074-447983 X-HE-Meta: U2FsdGVkX1+bkY+PGKeNjwyxnF4d1LdgW2HQfYqX+5shQwm4LWCIJT5K9gaj0EKmDVM1IBzfKDoFRdrdW0LCq8sS2w1D72lQEBPBd6cCxvPEvVXJIZ0bwsE7ItNmzpoBkNwJEMTgatr75m4gPE4xMTOaUEGh2s4DBDc9VXr3NKkcnvy3Dre/AdoxlNwWj+IkStCScPhG0rGbo1QB/bwkyGBBcP2dTBfT0YJN7XOoJhi4nuTac3rvE951mjt9xlHtRzLC5lcIh6LV5tVbvwJi6xOUJYdGB7HkX2Jhbj2BY1ltmDz1FgeKuUcB+MiR+DGykKEe6OfVHwA3TrFSldQWE208u3AgA460OwIzFKQALECgFKmgmHc1a7K2T1YlevkiaWVxavL55dQz2hH0GpICyq/BE9/tg8wQXnVEzDcojHkpwoxXnpWQdH6W53EgldgoirmupHe5cIN6Wxs8EZ1kKghAAmpFIdrl9nIxiuRyxQ/gWPlh7qEbBTx1uaHCvdTYBg/PN4z/IKzUIBls+ZnwUFWSrVrp1lNywfvfiwtQEIA1uaVsmxvsA+YhVEy3UCy7r5nzIdQaofei2/EgeXMXNf7NV/L1JcDr/M/BROhx5lzr4QAIMGMdHTCeujuoMntpiW8/EivwhPQzUtLCdJAxZVgmQGDhRKP6jzObqUCwgP/Fd5ORPMR2+RKTVr07q7xdo4sbTiJEbiiKkm3drpXvR6wjd0Cl7bXYhfQYn4qpSBTWx4QL68ZxUVfItqu2Qbh4xJGibqH2Uv36+HrBGDsZDiwRIboHFyJghynL/FSPIMlBWtK7unIIsB5kXBFUuHsNBWIjIaPAXONdSzWP/9GtlurP3/FUlx+sdb6JCjMNWZZ9z1JUpzDcVT6/zA+OeUFTb9JU5oteW5X7NVOuUXingoUzKffNGy6UPA+PIOWON8TwC2UOEKf3MbrEdpsyK+Rw4zbSUpOfC84YPoCxYOW 6YjGKj9m eICpOgBCL9cMC/ZEskxXTkdQ7xyaqrSdVuKdjzg5Bqj4JkHUnBoTbSZ2TK+aOABR6YHLgirKRzctjEXzqHrT/+cbcj7O/gY5m3Es7RthHaap2flf/HQ4b/g63+Eh4tlJYiZllfH7fXfZZewA5p0bJULujOXVHBH/c3TqyQnSguu325Z8F1u8KhozyOKFHBf/aF0O49NW3o9saIsc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Jan 26, 2023 at 03:41:52PM -0800, Andrew Morton wrote: > > + * Return: The number of bytes copied from the folio. > > +static inline size_t memcpy_from_file_folio(char *to, struct folio *folio, > > + loff_t pos, size_t len) > > +{ > > + size_t offset = offset_in_folio(folio, pos); > > + char *from = kmap_local_folio(folio, offset); > > + > > + if (folio_test_highmem(folio)) > > + len = min(len, PAGE_SIZE - offset); > > + else > > + len = min(len, folio_size(folio) - offset); > > min() blows up on arm allnoconfig. > > ./include/linux/highmem.h: In function 'memcpy_from_file_folio': > ./include/linux/minmax.h:20:35: warning: comparison of distinct pointer types lacks a cast > 20 | (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1))) > | ^~ > ./include/linux/minmax.h:26:18: note: in expansion of macro '__typecheck' > 26 | (__typecheck(x, y) && __no_side_effects(x, y)) > | ^~~~~~~~~~~ > ./include/linux/minmax.h:36:31: note: in expansion of macro '__safe_cmp' > 36 | __builtin_choose_expr(__safe_cmp(x, y), \ > | ^~~~~~~~~~ > ./include/linux/minmax.h:67:25: note: in expansion of macro '__careful_cmp' > 67 | #define min(x, y) __careful_cmp(x, y, <) > | ^~~~~~~~~~~~~ > ./include/linux/highmem.h:435:23: note: in expansion of macro 'min' > 435 | len = min(len, PAGE_SIZE - offset); > | ^~~ Oh, right, PAGE_SIZE is size_t everywhere except on ARM. > We could use min_t(), but perhaps and explanatorialy named variable is > nicer? But buggy because we return the number of bytes copied. > --- a/include/linux/highmem.h~mm-add-memcpy_from_file_folio-fix > +++ a/include/linux/highmem.h > @@ -430,13 +430,14 @@ static inline size_t memcpy_from_file_fo > { > size_t offset = offset_in_folio(folio, pos); > char *from = kmap_local_folio(folio, offset); > + size_t remaining; > > if (folio_test_highmem(folio)) > - len = min(len, PAGE_SIZE - offset); > + remaining = PAGE_SIZE - offset; > else > - len = min(len, folio_size(folio) - offset); > + remaining = folio_size(folio) - offset; I don't think remaining is a great name for this. The key thing is that for any platform we care about folio_test_highmem() is constant false, so this just optimises away the min() call. You could salvage this approach by doing len = min(remaining, len); memcpy(to, from, len); return len; but I think it's probably better to just do min_t on the PAGE_SIZE line. Stupid ARM. > - memcpy(to, from, len); > + memcpy(to, from, min(len, remaining)); > kunmap_local(from); > > return len; > _ >