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 X-Spam-Level: X-Spam-Status: No, score=-2.1 required=3.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, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9D50C433E0 for ; Sat, 13 Jun 2020 13:29:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9355420739 for ; Sat, 13 Jun 2020 13:29:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YAz0iEo0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9355420739 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1DD3F6B0002; Sat, 13 Jun 2020 09:29:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 18DF86B0003; Sat, 13 Jun 2020 09:29:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07C1A6B0005; Sat, 13 Jun 2020 09:29:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0105.hostedemail.com [216.40.44.105]) by kanga.kvack.org (Postfix) with ESMTP id E44A86B0002 for ; Sat, 13 Jun 2020 09:29:34 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id A1073824556B for ; Sat, 13 Jun 2020 13:29:34 +0000 (UTC) X-FDA: 76924270668.19.cloud73_5502df826de5 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 692E41AD1B0 for ; Sat, 13 Jun 2020 13:29:34 +0000 (UTC) X-HE-Tag: cloud73_5502df826de5 X-Filterd-Recvd-Size: 8096 Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Sat, 13 Jun 2020 13:29:34 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id j6so1532632pgh.4 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=mUcYm0TUQoUBy3WHKIte6K7hTllcJvOmULjO6qQilYxNf+o3DFIkWG7287indfIu7a O9FedxUk+e54KFpob7TN+VZkfRcKwtZ15+Pan/ODq1ioZbOBa2QFZOzoutq60qp5Nxyc 3ALynRwJIMZBgt6c2Rptehei+ZddsFd0U3nLcxeJRFrDLmxslkaofJhT6rO5W4te0/2O 06KIOcissN0s9AuvnEppbIsFxP3m0ENbAL/urnS8fgoIvgv3Y4ZSa0FJ8GSLq/ioUxBa yXgyA8cVJLTKJmk/Oz4RLSioe/rIUFXnhWWDHtCFVTUHd+fyHuTyVzGQUGNkCa6Pz3Li LVUw== X-Gm-Message-State: AOAM5304dabySobjz18CY/szl0bncD/ylrk3MbL/9JvV4rwQ8Z72aZFR DM9ENIVB3GDoFrg+R9qTmY0= X-Google-Smtp-Source: ABdhPJzRhgcSz+npSCAV/H07NPbuJdcfBHWW62k9iaNoNkiA7BP5w79gXw1gi9vcc51wgZllbwjPcA== 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) X-Rspamd-Queue-Id: 692E41AD1B0 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: 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