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=-9.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 80754C433E2 for ; Fri, 28 Aug 2020 19:27:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 612CC20848 for ; Fri, 28 Aug 2020 19:27:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="GlJS/QRq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726146AbgH1T1G (ORCPT ); Fri, 28 Aug 2020 15:27:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725979AbgH1T1D (ORCPT ); Fri, 28 Aug 2020 15:27:03 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53BC6C061232 for ; Fri, 28 Aug 2020 12:27:03 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id c15so138647plq.4 for ; Fri, 28 Aug 2020 12:27:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=8vIVYyejCvH3/8OP761KZEsC4sBaI8JTbXZbD1JlWpo=; b=GlJS/QRqiByLAShtMbzuUct2M9gay1V0uz4R9A09slQFWVVYwSZJ6zlabHI0KWVx9e nqbcfnP6qUg4jvkfHc/xC3YATRYUsG50g4OWlP1cBvyoSMNaaIIBnGuCv+GBVdlnobxI Y87KhbGz6ZrcKMnsdCSJfVaFb5jGkoIDfg1KSFPkiY9lUx9sEkDmlT8Mc/Eekov+TVdj TWE+tjcipWNf+82AgW23Wzbm40QgmK5R3iuqWXnLz3sHzSJQAPvN92Xf0nPodwiP6OPO /MMw8od2kyGk3FeiWkxNioZ+IsA3bb+1h/1cA2tBt6wM0UYsT8fYrPomV4/bu90h2fFt pxbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=8vIVYyejCvH3/8OP761KZEsC4sBaI8JTbXZbD1JlWpo=; b=SohxYAfaHrz/RLxhlMLZNb3JlSSjJMd98df1rGdPWNkEUduLpG6GEj/KEX5dvq8OvD k/Qr9uWqOpbBL6tA/2yUI/nrJQycn47Y48Bs2e+kd5ryM0O54swAPwoYzIPPoAP4clkO hQZiL/rXeDLHKdSmqW9EsSnuF0gbuN4ZImXTZFkef8ZWDajYZcoLHDI8cpYqq0tHMsus wQD2g89xCidOIom3kTEx9salXgn74L0Aqc1k2RDMg2MLx4V8QyYjTQiR26Dl6YpI4qiM 58/B3v6cx5d8PgVee0ommshwFeQVwXn7ve1h9Cd4/p/w5eJInNMHcxJPuvE4LoKi0odq fE7A== X-Gm-Message-State: AOAM533h/rX7zPcTqWf8fX22FUupLM4n+GArsKYeAlp44S/Pa56hqM76 K6LlG4DnMIcOpGnDrP24Bi9SEpj6qFoDpBk8 X-Google-Smtp-Source: ABdhPJw6mZFQTyi9pnaI+cDWyDa0+6Uj81NRhZZ9JJWrD1rA541KiRJbm6Xz/kzNaXTGrVZZd+4Grg== X-Received: by 2002:a17:90a:4f0e:: with SMTP id p14mr460692pjh.31.1598642822331; Fri, 28 Aug 2020 12:27:02 -0700 (PDT) Received: from [192.168.1.182] ([66.219.217.173]) by smtp.gmail.com with ESMTPSA id x5sm211319pfj.1.2020.08.28.12.26.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 28 Aug 2020 12:27:01 -0700 (PDT) Subject: Re: [PATCH v8 3/4] mm/madvise: introduce process_madvise() syscall: an external memory hinting API From: Jens Axboe To: Arnd Bergmann , Minchan Kim Cc: Andrew Morton , LKML , Christian Brauner , linux-mm , Linux API , Oleksandr Natalenko , Suren Baghdasaryan , Tim Murray , Sandeep Patil , Sonny Rao , Brian Geffon , Michal Hocko , Johannes Weiner , Shakeel Butt , John Dias , Joel Fernandes , Jann Horn , alexander.h.duyck@linux.intel.com, SeongJae Park , David Rientjes , Arjun Roy , Vlastimil Babka , Christian Brauner , Daniel Colascione , Kirill Tkhai , SeongJae Park , linux-man References: <20200622192900.22757-1-minchan@kernel.org> <20200622192900.22757-4-minchan@kernel.org> <9c339413-68c7-344e-dd01-327cb988d385@kernel.dk> Message-ID: Date: Fri, 28 Aug 2020 13:26:58 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <9c339413-68c7-344e-dd01-327cb988d385@kernel.dk> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-man-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-man@vger.kernel.org On 8/28/20 12:24 PM, Jens Axboe wrote: > On 8/28/20 11:40 AM, Arnd Bergmann wrote: >> On Mon, Jun 22, 2020 at 9:29 PM Minchan Kim wrote: >>> So finally, the API is as follows, >>> >>> ssize_t process_madvise(int pidfd, const struct iovec *iovec, >>> unsigned long vlen, int advice, unsigned int flags); >> >> I had not followed the discussion earlier and only now came across >> the syscall in linux-next, sorry for stirring things up this late. >> >>> diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl >>> index 94bf4958d114..8f959d90338a 100644 >>> --- a/arch/x86/entry/syscalls/syscall_64.tbl >>> +++ b/arch/x86/entry/syscalls/syscall_64.tbl >>> @@ -364,6 +364,7 @@ >>> 440 common watch_mount sys_watch_mount >>> 441 common watch_sb sys_watch_sb >>> 442 common fsinfo sys_fsinfo >>> +443 64 process_madvise sys_process_madvise >>> >>> # >>> # x32-specific system call numbers start at 512 to avoid cache impact >>> @@ -407,3 +408,4 @@ >>> 545 x32 execveat compat_sys_execveat >>> 546 x32 preadv2 compat_sys_preadv64v2 >>> 547 x32 pwritev2 compat_sys_pwritev64v2 >>> +548 x32 process_madvise compat_sys_process_madvise >> >> I think we should not add any new x32-specific syscalls. Instead I think >> the compat_sys_process_madvise/sys_process_madvise can be >> merged into one. >> >>> + mm = mm_access(task, PTRACE_MODE_ATTACH_FSCREDS); >>> + if (IS_ERR_OR_NULL(mm)) { >>> + ret = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH; >>> + goto release_task; >>> + } >> >> Minor point: Having to use IS_ERR_OR_NULL() tends to be fragile, >> and I would try to avoid that. Can mm_access() be changed to >> itself return PTR_ERR(-ESRCH) instead of NULL to improve its >> calling conventions? I see there are only three other callers. >> >> >>> + ret = import_iovec(READ, vec, vlen, ARRAY_SIZE(iovstack), &iov, &iter); >>> + if (ret >= 0) { >>> + ret = do_process_madvise(pidfd, &iter, behavior, flags); >>> + kfree(iov); >>> + } >>> + return ret; >>> +} >>> + >>> +#ifdef CONFIG_COMPAT >> ... >>> + >>> + ret = compat_import_iovec(READ, vec, vlen, ARRAY_SIZE(iovstack), >>> + &iov, &iter); >>> + if (ret >= 0) { >>> + ret = do_process_madvise(pidfd, &iter, behavior, flags); >>> + kfree(iov); >>> + } >> >> Every syscall that passes an iovec seems to do this. If we make import_iovec() >> handle both cases directly, this syscall and a number of others can >> be simplified, and you avoid the x32 entry point I mentioned above >> >> Something like (untested) >> >> index dad8d0cfaaf7..0de4ddff24c1 100644 >> --- a/lib/iov_iter.c >> +++ b/lib/iov_iter.c >> @@ -1683,8 +1683,13 @@ ssize_t import_iovec(int type, const struct >> iovec __user * uvector, >> { >> ssize_t n; >> struct iovec *p; >> - n = rw_copy_check_uvector(type, uvector, nr_segs, fast_segs, >> - *iov, &p); >> + >> + if (in_compat_syscall()) >> + n = compat_rw_copy_check_uvector(type, uvector, nr_segs, >> + fast_segs, *iov, &p); >> + else >> + n = rw_copy_check_uvector(type, uvector, nr_segs, >> + fast_segs, *iov, &p); >> if (n < 0) { >> if (p != *iov) >> kfree(p); > > Doesn't work for the async case, where you want to be holding on to the > allocated iovec. But in general I think it's a good helper for the sync > case, which is by far the majority. Nevermind, I'm an idiot for reading this totally wrong. -- Jens Axboe