Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp350446ybt; Sat, 13 Jun 2020 06:31:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpCFX7yww6UmU2yyVWdVbTdfhsn+KhqFOLYKj7A7kS9GRiWKlD3ws8yYKXnH9UcHzLGZbF X-Received: by 2002:a17:906:851:: with SMTP id f17mr16928117ejd.396.1592055104864; Sat, 13 Jun 2020 06:31:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592055104; cv=none; d=google.com; s=arc-20160816; b=P9/p3huHFCoy8QqSn5xTMd486kIybJFNt8FrzyHOP9OL9dNvlZOWMzfNkkUWSMpaHg P8OR8YYnbViPsqKtLKH57zLivdkQpatQnZ0Kk0pK/Jb7fmix6nLVQWqL2hIIOFO19nVr 8HsC1Jp1GLeUDpuHJH8dydJrc5+UKbZwBMCkfIp4kjgkSCA0e0UAQ7ds1oXyGkqhGE/I +N4hCzswXofKbdAEY2f6MLy3YvXmsJK7Z3lyZJU+4fVnSkL4s96iWd6wDYOK6I33VoqY r+tb0nb/HbNqUTWCo69l6v3Jdrymk09bVtLjrlVz8HiqD3TYHeVU6LkzcWIJjHJPYmKf 1M7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=FgD7trK9UXai91vKASUg9drm0IS6CWPS1x1rvWXbOqI=; b=MCtEKB+FoEskWg1XfptQfwif3FKp4q4SCWFMbTTYrlB0LCB6S3PQTavC5SnmGf9sjH kuudy5u2WbDVKEXBcw7iEG5K+1NKMgouiuNjUB+yZ1witHOtEL/cpYkZKyKr81xPvDLc bqVslfVdMrRoXQfYEn4Ryf0UcSgqIbxfFWcrnT69iGONhT9F/3pvNIzo6iE3mshE4jmm uDBSI4u1LUen8H+ZqOQ5WF8NU8UuMq069ews/ZgW26mNAnhB0FtqnQaoIB+oaqiEfVPh RtVESJsKpviuYPckL4ivFdpsrAB9yJySCvIHcPDaKGlJIjMJgu+s1HxNo1OlGOPFGnG8 2Iog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YAz0iEo0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bz17si5810624ejc.605.2020.06.13.06.31.21; Sat, 13 Jun 2020 06:31:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YAz0iEo0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726272AbgFMN3e (ORCPT + 99 others); Sat, 13 Jun 2020 09:29:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726021AbgFMN3e (ORCPT ); Sat, 13 Jun 2020 09:29:34 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B17D1C03E96F for ; Sat, 13 Jun 2020 06:29:33 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id l63so3210055pge.12 for ; Sat, 13 Jun 2020 06:29:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=FgD7trK9UXai91vKASUg9drm0IS6CWPS1x1rvWXbOqI=; b=YAz0iEo0hPYKJp7OqcrKcUh3QZ6NVMIfb8JNmJQexYFLcsQkcfe4oxjTldEqzp1vko o/MMzJRE9NB1XlzFvR6IHPhztJaGV/ZhEZsqJgnRPvX/HupGJlunL51IFW5HotEA3YuB qH2io2BRmD/6UGpmHm6GvXQaTLExnDvJtSkRYRsRAyNvY3ti8b1eAl0EnwgKxvU1qBY8 Jimb0i7fRhLucW3TTviZB0t+bhCGvrMheIWKAmsTYW6DAvHvBKa0DEtBhyKHJTP0EWzj bijLfnxKVWKqQ+CsboOhnIEVkNwJMkpCYpm6zQ6mxTI9OtHC92qxpeRP9nNal0Y+VMeI JFGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=FgD7trK9UXai91vKASUg9drm0IS6CWPS1x1rvWXbOqI=; b=kXAhjv7FUtDRFT/CJAM5YXlk7uVN1/PY0huJNnT9VpzuYJurqubfUh8CyjtQDI/YcJ 2p82htTwnLNEOdhCFztJYu5XXryUo1n6yLoVJnXd81xE6W9afTrHP+QgIMxMMBTr/UCJ pPgh4jTdGnZwq/jNNlbOIA7Y8AFaXRR4bPPV47sO7WuVJKjfzPDHyfZk3GvQ6uFopwMX PKtI4Sh4T1HMbMTHjTR0ljIjtPpoczXnWN7sZLBaxAT1sXHzfhV3f1oF4QkP8pomB8ry obi4wSf0WEy4pGpPJ19UIapIN15dXM5UMti6csy1LCPnNkIzYsmBo63CSgS3NYg3grie IUbA== X-Gm-Message-State: AOAM530vhq/dXVtKJEtNqgUpQUJjczFhfzB+oqXzsB4Qy3y+lwlSEkew wu4DM8ZECotI3cEIC+FUo20= X-Received: by 2002:a62:3582:: with SMTP id c124mr11627890pfa.298.1592054973085; Sat, 13 Jun 2020 06:29:33 -0700 (PDT) Received: from localhost ([49.207.210.132]) by smtp.gmail.com with ESMTPSA id p19sm8996514pff.116.2020.06.13.06.29.32 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 13 Jun 2020 06:29:32 -0700 (PDT) Date: Sat, 13 Jun 2020 18:59:30 +0530 From: afzal mohammed To: Andy Shevchenko Cc: Russell King - ARM Linux admin , Arnd Bergmann , Linus Walleij , Linux Kernel Mailing List , linux-mm , linux-arm Mailing List , Nicolas Pitre , Catalin Marinas , Will Deacon Subject: Re: [RFC 1/3] lib: copy_{from,to}_user using gup & kmap_atomic() Message-ID: <20200613132930.GA4005@afzalpc> References: <9e1de19f35e2d5e1d115c9ec3b7c3284b4a4e077.1591885760.git.afzal.mohd.ma@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.3 (2018-01-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Sat, Jun 13, 2020 at 02:08:11PM +0300, Andy Shevchenko wrote: > On Fri, Jun 12, 2020 at 1:20 PM afzal mohammed wrote: > > +// Started from arch/um/kernel/skas/uaccess.c > > Does it mean you will deduplicate it there? What i meant was, that file was taken as a template & nothing more, at same time i wanted to give credit to that file, i will explicitly mention it next time. It is not meant to deduplicate it. Functionality here is completely different. In the case here, there would be different virtual address mapping that CPU will be see once in Kernel as compared to user mode. Here a facility is provided to access the user page, when the current virtual address mapping of the CPU excludes it. This is for providing full 4G virtual address to both user & kernel on 32bit ARM to avoid using highmem or reduce the impact of highmem, i.e. so that Kernel can address till 4GiB (almost) as lowmem. Here assumption is that user mapping is not a subset of virtual address mapped by CPU, but a separate one. Upon Kernel entry ttbr0 is changed to Kernel lowmem, while upon Kernel exit is changed back to user pages (ttbrx in ARM, iiuc, equivalent to cr3 in x86) Now realize that i am unable to put coherently the problem being attempted to solve here to a person not familiar w/ the issue w/o taking considerable time. If above explanation is not enough, i will try to explain later in a better way. > > +#include > > +#include > > +#include > > +#include > > Perhaps ordered? will take care > > +static int do_op_one_page(unsigned long addr, int len, > > + int (*op)(unsigned long addr, int len, void *arg), void *arg, > > + struct page *page) > > Maybe typedef for the func() ? will take care > > +{ > > + int n; > > + > > + addr = (unsigned long) kmap_atomic(page) + (addr & ~PAGE_MASK); > > I don't remember about this one... i am not following you here, for my case !CONFIG_64BIT case in that file was required, hence only it was picked (or rather not deleted) > > + size = min(PAGE_ALIGN(addr) - addr, (unsigned long) len); > > ...but here seems to me you can use helpers (offset_in_page() or how > it's called). i was not aware of it, will use it as required. > > Also consider to use macros like PFN_DOWN(), PFN_UP(), etc in your code. Okay > > > + remain = len; > > + if (size == 0) > > + goto page_boundary; > > + > > + n = do_op_one_page(addr, size, op, arg, *pages); > > + if (n != 0) { > > > + remain = (n < 0 ? remain : 0); > > Why duplicate three times (!) this line, if you can move it to under 'out'? yes better to move there > > > + goto out; > > + } > > + > > + pages++; > > + addr += size; > > + remain -= size; > > + > > +page_boundary: > > + if (remain == 0) > > + goto out; > > + while (addr < ((addr + remain) & PAGE_MASK)) { > > + n = do_op_one_page(addr, PAGE_SIZE, op, arg, *pages); > > + if (n != 0) { > > + remain = (n < 0 ? remain : 0); > > + goto out; > > + } > > + > > + pages++; > > + addr += PAGE_SIZE; > > + remain -= PAGE_SIZE; > > + } > > Sounds like this can be refactored to iterate over pages rather than addresses. Okay, i will check > > +static int copy_chunk_from_user(unsigned long from, int len, void *arg) > > +{ > > + unsigned long *to_ptr = arg, to = *to_ptr; > > + > > + memcpy((void *) to, (void *) from, len); > > What is the point in the casting to void *? The reason it was there was because of copy-paste :), passing unsigned long as 'void *' or 'const void *' requires casting right ?, or you meant something else ? now i checked removing the cast, compiler is abusing me :), says 'makes pointer from integer without a cast' > > + num_pages = DIV_ROUND_UP((unsigned long)from + n, PAGE_SIZE) - > > + (unsigned long)from / PAGE_SIZE; > > PFN_UP() ? Okay > I think you can clean up the code a bit after you will get the main > functionality working. Yes, surely, intention was to post proof-of-concept ASAP, perhaps contents will change drastically in next version so that any resemblence of arch/um/kernel/skas/uaccess.c might not be there. Regards afzal