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=ham 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 44430C433E6 for ; Fri, 28 Aug 2020 19:27:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EF3E52073A for ; Fri, 28 Aug 2020 19:27:04 +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" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EF3E52073A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 864E36B0003; Fri, 28 Aug 2020 15:27:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8154C8D0001; Fri, 28 Aug 2020 15:27:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6DA946B0006; Fri, 28 Aug 2020 15:27:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0053.hostedemail.com [216.40.44.53]) by kanga.kvack.org (Postfix) with ESMTP id 55EFC6B0003 for ; Fri, 28 Aug 2020 15:27:04 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 08D9B1E0E for ; Fri, 28 Aug 2020 19:27:04 +0000 (UTC) X-FDA: 77200960368.20.cloud48_3c134c527078 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id D5A75180C07AB for ; Fri, 28 Aug 2020 19:27:03 +0000 (UTC) X-HE-Tag: cloud48_3c134c527078 X-Filterd-Recvd-Size: 8316 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Fri, 28 Aug 2020 19:27:03 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id t11so136643plr.5 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=YnzMAcv9qLyA4ri7jWrNhF/AUDpwV/gADhoMr7/tbj2mnbSp3eCdg4pk8/Nk+cIi9R 4AA9Y0r8xgYL7QR6iP4FIFdQMEh8DSyypnljlvODkI5y3lnyF+uAovOO7bR4tJjW00PJ u2FEeqIw5/1zE+NX0ssK/Y/v6y1x6l8QBm5N1iKGqVE1mc69zJn8dwG346DcE9WkeHr4 fskDzXFD5sL3JiVdN4WHcM9sNHiyW/Faq2dtSSXOOfoUIoBPi1ZcLw/YFg3u88ONwINs kMoXyQG+nr4y4zlTZt6ZS+U7TnZ+6O1cSDpBuAoicdVpWSAB5yR818nNBfAJNQO4p/Nk ndKg== X-Gm-Message-State: AOAM530/Uk0tZrDRojPJwaPVvNJwQcjwKWArQJC94xIoYEjil9TbUzAr a2iRMzmBw/9Hw7gkvdbjR9d8Bw== 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 X-Rspamd-Queue-Id: D5A75180C07AB X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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 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